Skip to content

Commit

Permalink
Fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed Apr 29, 2016
2 parents ec3b247 + 430f2be commit 760ed8f
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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 Down
66 changes: 65 additions & 1 deletion src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Board {
private Piece[][] representation;

private Piece lastPieceMoved;
private Move lastMove;

// Move properties
private int movesSinceCapture;
Expand All @@ -26,7 +27,8 @@ public Board() {
representation = new Piece[BOARD_SIZE][BOARD_SIZE];
movesSinceCapture = 0;
init();
lastPieceMoved = null;
lastPieceMoved = null;
lastMove = null;
}

/**
Expand All @@ -43,6 +45,7 @@ public Board(Board other) {
}
movesSinceCapture = other.getMovesSinceCapture();
lastPieceMoved = other.getLastPieceMoved();
lastMove = other.getLastMove();
}

/**
Expand Down Expand Up @@ -211,6 +214,64 @@ public ArrayList<Move> generateRegularMovesForPiece(Piece p) {
}

/**
<<<<<<< HEAD
=======
* Generates the frontier for movement for all pieces.
* @param color
* @return
*/
public ArrayList<Board> generateMoveFrontier(Color color) {
ArrayList<Board> frontier = new ArrayList<Board>();
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<Move> 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
Expand Down Expand Up @@ -367,6 +428,9 @@ public int getMovesSinceCapture() {

public Piece getLastPieceMoved() {
return this.lastPieceMoved;
}
public Move getLastMove() {
return this.lastMove;
}
}

1 change: 1 addition & 0 deletions src/view/CheckersWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/view/GameEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 49 additions & 2 deletions src/view/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
import javax.swing.JLabel;
import javax.swing.JPanel;

<<<<<<< HEAD
import controller.Game;
import controller.GameConstants;
import model.Color;
import model.Location;
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
Expand Down Expand Up @@ -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.");
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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());

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/view/Square.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void dehighlight() {
public Color getPieceColor() {
return pieceColor;
}
<<<<<<< HEAD


public void placePiece(Color color) {
Expand All @@ -199,6 +200,11 @@ public Color removePiece() {
return color;
}

=======

public void dehighlight() {
this.setBorder(null);
>>>>>>> 430f2be346c625bc746ce1659838d93253901c11

public void setKing(boolean king) {
this.king = king;
Expand Down

0 comments on commit 760ed8f

Please sign in to comment.