diff --git a/src/controller/Game.java b/src/controller/Game.java index 88e67ad..d6c98ba 100755 --- a/src/controller/Game.java +++ b/src/controller/Game.java @@ -5,7 +5,7 @@ import model.Board; import model.Color; import model.Location; -import model.Move; +import model.Move; import view.GamePanel; public class Game { diff --git a/src/model/Board.java b/src/model/Board.java index 2dd4ab9..3325239 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -16,6 +16,7 @@ public class Board { private Piece[][] representation; private Piece lastPieceMoved; + private Move lastMove; // Move properties private int movesSinceCapture; @@ -26,7 +27,8 @@ public Board() { representation = new Piece[BOARD_SIZE][BOARD_SIZE]; movesSinceCapture = 0; init(); - lastPieceMoved = null; + lastPieceMoved = null; + lastMove = null; } /** @@ -43,6 +45,7 @@ public Board(Board other) { } movesSinceCapture = other.getMovesSinceCapture(); lastPieceMoved = other.getLastPieceMoved(); + lastMove = other.getLastMove(); } /** @@ -211,6 +214,64 @@ public ArrayList generateRegularMovesForPiece(Piece p) { } /** +<<<<<<< HEAD +======= + * Generates the frontier for movement for all pieces. + * @param color + * @return + */ + public ArrayList generateMoveFrontier(Color color) { + ArrayList frontier = new ArrayList(); + for (int i = 0; i < BOARD_SIZE; ++i) { + for (int j = 0; j < BOARD_SIZE; ++j) { + Piece p = this.representation[i][j]; + if(null != p && p.getColor() == color) { + ArrayList moves = generateMoves(this.representation[i][j]); + for (Move move : moves) { + Board board = new Board(this); + board.move(move); + frontier.add(board); + } + } + } + } + return frontier; + } + + public void move(Move move) { + representation[move.destination.row][move.destination.column] + = representation[move.source.row][move.source.column]; + representation[move.source.row][move.source.column] = null; + representation[move.destination.row][move.destination.column] + .setLocation(new Location(move.destination.row, move.destination.column)); + Piece moved = representation[move.destination.row][move.destination.column]; + this.lastPieceMoved = moved; + this.lastMove = move; + } + + /** + * Move the jumper and erase the jumpee. + * @param jump + */ + public void jump(Move jump) { + representation + [(jump.destination.row + jump.source.row)/2] + [(jump.destination.column + jump.source.column)/2] = null; // monkey + representation[jump.destination.row][jump.destination.column] = + representation[jump.source.row][jump.source.column]; + representation[jump.source.row][jump.source.column] = null; + representation[jump.destination.row][jump.destination.column] + .setLocation(new Location(jump.destination.row, jump.destination.column)); + + Piece moved = representation[jump.destination.row][jump.destination.column]; + this.lastPieceMoved = moved; + this.lastMove = jump; + this.resetMovesSinceCapture(); + + } + + /** +>>>>>>> 430f2be346c625bc746ce1659838d93253901c11 * Returns the possible jumps a piece can take. * @param color * @return @@ -367,6 +428,9 @@ public int getMovesSinceCapture() { public Piece getLastPieceMoved() { return this.lastPieceMoved; + } + public Move getLastMove() { + return this.lastMove; } } diff --git a/src/view/CheckersWindow.java b/src/view/CheckersWindow.java index ec64f69..d1b065c 100644 --- a/src/view/CheckersWindow.java +++ b/src/view/CheckersWindow.java @@ -90,6 +90,7 @@ private void createMenuBar() { file.add(quit); file.add(newGame); file.add(instructions); + menubar.add(file); menubar.setVisible(true); this.setJMenuBar(menubar); diff --git a/src/view/GameEventListener.java b/src/view/GameEventListener.java index 02141eb..6bd334f 100644 --- a/src/view/GameEventListener.java +++ b/src/view/GameEventListener.java @@ -60,7 +60,14 @@ public void keyPressed(KeyEvent arg0) {} @Override public void keyReleased(KeyEvent e) { +<<<<<<< HEAD +======= + if(e.getKeyCode() == KeyEvent.VK_ENTER && gamePanel.moveReady()) { + gamePanel.moveSelectedPiece(); + gamePanel.updateMoveMessage(); + } +>>>>>>> 430f2be346c625bc746ce1659838d93253901c11 } @Override diff --git a/src/view/GamePanel.java b/src/view/GamePanel.java index 8c0831b..fa012f1 100644 --- a/src/view/GamePanel.java +++ b/src/view/GamePanel.java @@ -7,6 +7,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; +<<<<<<< HEAD import controller.Game; import controller.GameConstants; import model.Color; @@ -14,6 +15,12 @@ import model.Move; import model.Piece; import model.Type; +======= +import model.Color; +import model.Location; +import model.Move; +import controller.Game; +>>>>>>> 430f2be346c625bc746ce1659838d93253901c11 /** * Represents the panel which will hold all of the graphical @@ -70,12 +77,15 @@ public void displayMessage(String message) { } public void updateMoveMessage() { - if (moveSource == null) { +// if (moveSource == null && moveDestination == null) { +// displayMessage("---"); +// } else + if (moveSource == null) { displayMessage("Select a piece to move."); } else if (moveDestination == null) { displayMessage("Select a destination."); } else { - displayMessage("Select \"Move\" to move the piece."); + displayMessage("Press enter to confirm move."); } } @@ -121,6 +131,7 @@ public void dehighlightValidDestinations() { canvas.invalidateAllSquares(); } +<<<<<<< HEAD public void movePiece(Move move) { if (move.isJump()) { int monkeyRow = (move.destination.row + move.source.row)/2; @@ -135,10 +146,19 @@ public void movePiece(Move move) { if (canPromote(canvas.getSquare(move.destination))) { canvas.getSquare(move.destination).promotePiece(); } +======= + public Location getMoveSource(){ + return moveSource.getCellLocation(); + } + + public Location getMoveDestination(){ + return moveDestination.getCellLocation(); +>>>>>>> 430f2be346c625bc746ce1659838d93253901c11 } public void moveSelectedPiece() { +<<<<<<< HEAD /* Create the move */ Move move = new Move(moveSource.getCellLocation(), moveDestination.getCellLocation()); @@ -177,6 +197,33 @@ public void resetMove() { moveDestination.setSelected(false); moveSource = null; moveDestination = null; +======= + Move move = new Move(getMoveSource(), getMoveDestination()); + game.movePiece(move); + + canvas.moveChecker(getMoveSource(), getMoveDestination()); + dehighlightAllSquares(); + + if(move.isJump()) { + Location monkeyLoc = new Location((move.destination.row + + move.source.row)/2, + (move.source.column + + move.destination.column) / 2); + System.out.println(monkeyLoc); + removePiece(monkeyLoc); + moveSource.setSelected(false); + //moveDestination.setSelected(false); + moveSource = null; + //moveDestination = null; + + } else { + moveSource.setSelected(false); + moveDestination.setSelected(false); + moveSource = null; + moveDestination = null; + game.switchTurn(); + } +>>>>>>> 430f2be346c625bc746ce1659838d93253901c11 } public boolean canPromote(Square square) { diff --git a/src/view/Square.java b/src/view/Square.java index b2eecd9..2c4b197 100644 --- a/src/view/Square.java +++ b/src/view/Square.java @@ -184,6 +184,7 @@ public void dehighlight() { public Color getPieceColor() { return pieceColor; } +<<<<<<< HEAD public void placePiece(Color color) { @@ -199,6 +200,11 @@ public Color removePiece() { return color; } +======= + + public void dehighlight() { + this.setBorder(null); +>>>>>>> 430f2be346c625bc746ce1659838d93253901c11 public void setKing(boolean king) { this.king = king;