Skip to content
Permalink
9b207cfdc8
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 83 lines (64 sloc) 1.81 KB
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;
}
}