diff --git a/src/controller/Game.java b/src/controller/Game.java index d6c98ba..51dd3ef 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 { @@ -23,7 +23,12 @@ public Game(Board board) { public void requestMove(Move move) { board.movePiece(move); gamePanel.movePiece(move); - + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } /* If this is the first jump of the jump sequence */ if (move.isJump() && !inJumpSequence) inJumpSequence = true; @@ -37,7 +42,7 @@ public void requestMove(Move move) { Move thunkMove = getThunkMove(); board.movePiece(thunkMove); gamePanel.movePiece(thunkMove); - + if (thunkMove.isJump()) inJumpSequence = true; while (inJumpSequence) { @@ -55,7 +60,7 @@ public void requestMove(Move move) { public Move getThunkMove() { ArrayList availableMoves; - + if (inJumpSequence) { availableMoves = board.generateJumpMovesForPiece(board.getLastPieceMoved()); diff --git a/src/view/GameEventListener.java b/src/view/GameEventListener.java index 02141eb..208dd1d 100644 --- a/src/view/GameEventListener.java +++ b/src/view/GameEventListener.java @@ -37,8 +37,8 @@ public void mousePressed(MouseEvent e) { Square square = (Square) e.getComponent(); if (square.hasPiece() && !gamePanel.isInJumpSequence() && square.getPieceColor() == GameConstants.USER_COLOR - && (!gamePanel.isForceJump() || square.hasPiece() - && square.isValid())) { + && (!gamePanel.isForceJump() || (square.hasPiece() + && square.isValid()))) { gamePanel.dehighlightValidDestinations(); gamePanel.setMoveSource(square); if (square.isSelected()) diff --git a/src/view/GamePanel.java b/src/view/GamePanel.java index 514f0dd..9cddf61 100644 --- a/src/view/GamePanel.java +++ b/src/view/GamePanel.java @@ -72,7 +72,7 @@ public void updateMoveMessage() { // if (moveSource == null && moveDestination == null) { // displayMessage("---"); // } else - if (moveSource == null) { + if (moveSource == null) { displayMessage("Select a piece to move."); } else if (moveDestination == null) { displayMessage("Select a destination."); @@ -144,35 +144,39 @@ public void moveSelectedPiece() { /* Create the move */ Move move = new Move(moveSource.getCellLocation(), moveDestination.getCellLocation()); - - /* Request the move */ - game.requestMove(move); - + /* Get rid of valid destination options */ dehighlightValidDestinations(); - - /* If the user just jumped and the game is still in a jump sequence */ - /* Select the same piece again */ - if (move.isJump() && game.isInJumpSequence()) { - moveDestination.setSelected(true); - highlightValidDestinations(moveDestination.getCellLocation()); - moveSource = moveDestination; - moveDestination = null; - } else { - /* Reset the move choices */ - resetMove(); - } - - /* See if any jump moves are available */ - ArrayList jumpMoves = - game.getAllAvailableJumpMoves(GameConstants.USER_COLOR); - - if (!jumpMoves.isEmpty()) { - for (Move jump : jumpMoves) { - canvas.highlightAndValidateSquare(jump.source); + + new Thread(new Runnable() { + @Override + public void run() { + /* Request the move */ + game.requestMove(move); + + /* If the user just jumped and the game is still in a jump sequence */ + /* Select the same piece again */ + if (move.isJump() && game.isInJumpSequence()) { + moveDestination.setSelected(true); + highlightValidDestinations(moveDestination.getCellLocation()); + moveSource = moveDestination; + moveDestination = null; + } else { + /* Reset the move choices */ + resetMove(); + } + + /* See if any jump moves are available */ + ArrayList jumpMoves = + game.getAllAvailableJumpMoves(GameConstants.USER_COLOR); + + if (!jumpMoves.isEmpty()) { + for (Move jump : jumpMoves) { + canvas.highlightAndValidateSquare(jump.source); + } + } } - } - + }).start(); } public void resetMove() { diff --git a/src/view/Square.java b/src/view/Square.java index d4d2e3e..af24957 100644 --- a/src/view/Square.java +++ b/src/view/Square.java @@ -117,7 +117,6 @@ public boolean hasPiece() { } public void promotePiece() { - System.out.println("Kinged"); this.king = true; } @@ -178,7 +177,6 @@ protected void paintComponent(Graphics g) { public void dehighlight() { this.setBorder(null); - } public Color getPieceColor() {