Skip to content

Commit

Permalink
Thunk now waits 0.5s before making move
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed Apr 29, 2016
1 parent 76ea71e commit cc671bf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
13 changes: 9 additions & 4 deletions src/controller/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand All @@ -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) {
Expand All @@ -55,7 +60,7 @@ public void requestMove(Move move) {

public Move getThunkMove() {
ArrayList<Move> availableMoves;

if (inJumpSequence) {
availableMoves =
board.generateJumpMovesForPiece(board.getLastPieceMoved());
Expand Down
4 changes: 2 additions & 2 deletions src/view/GameEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
58 changes: 31 additions & 27 deletions src/view/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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<Move> 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<Move> jumpMoves =
game.getAllAvailableJumpMoves(GameConstants.USER_COLOR);

if (!jumpMoves.isEmpty()) {
for (Move jump : jumpMoves) {
canvas.highlightAndValidateSquare(jump.source);
}
}
}
}

}).start();
}

public void resetMove() {
Expand Down
2 changes: 0 additions & 2 deletions src/view/Square.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public boolean hasPiece() {
}

public void promotePiece() {
System.out.println("Kinged");
this.king = true;
}

Expand Down Expand Up @@ -178,7 +177,6 @@ protected void paintComponent(Graphics g) {

public void dehighlight() {
this.setBorder(null);

}

public Color getPieceColor() {
Expand Down

0 comments on commit cc671bf

Please sign in to comment.