Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSE-4705-Checkers/src/controller/Game.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
83 lines (64 sloc)
1.81 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controller; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.concurrent.ThreadLocalRandom; | |
import model.Board; | |
import model.Color; | |
import model.Location; | |
import model.Move; | |
import model.Type; | |
import player.ComputerPlayer; | |
import player.HumanPlayer; | |
import player.Player; | |
import view.GamePanel; | |
public class Game { | |
private ComputerPlayer computer; | |
private Player opponent; | |
private Board board; | |
private GamePanel gamePanel; | |
public Game(Board board) { | |
this.board = board; | |
} | |
/* Either the server or the user will request a move */ | |
public void requestMove(Move move) { | |
board.movePiece(move); | |
gamePanel.movePiece(move); | |
checkEndGame(); | |
} | |
public Move makeComputerMove() { | |
/* If the game is not in the middle of a jump sequence, move the thunk */ | |
Move computerMove = null; | |
if (!opponent.isInJumpSequence()) { | |
computerMove = computer.getMove(); | |
if (computerMove == null) { | |
gamePanel.displayMessage("Game over. User has won!"); | |
gamePanel.disableInteraction(); | |
} else { | |
board.movePiece(computerMove); | |
gamePanel.movePiece(computerMove); | |
} | |
} | |
return computerMove; | |
} | |
public void checkEndGame() { | |
if (board.getMovesSinceCapture() > GameConstants.MAX_PASSIVE_MOVES) { | |
gamePanel.displayMessage("It's a tie! Be more aggressive next time."); | |
gamePanel.disableInteraction(); | |
} | |
} | |
public void notifyClientWin() { | |
gamePanel.displayMessage("Game over. Client has won!"); | |
} | |
public void setGamePanel(GamePanel panel) { | |
this.gamePanel = panel; | |
} | |
public void setComputer(ComputerPlayer computer) { | |
this.computer = computer; | |
} | |
public void setOpponent(Player opponent) { | |
this.opponent = opponent; | |
} | |
public Player getComputer() { | |
return computer; | |
} | |
} |