Skip to content

Commit

Permalink
printBoard(), initBoard(), isOccupied()
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Mar 28, 2016
1 parent 565cb52 commit 62a40cd
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,51 @@ public class Board {
public Board() {
representation = new Piece[BOARD_SIZE][BOARD_SIZE];
}

public void initBoard()
{
for(int row = 0; row < 3; row++){
for (int col = 0; col < 4; col++)
{
representation[row][2*col+ (row % 2)] = new Piece(Color.RED, row, 2*col + (row % 2));
representation[BOARD_SIZE - 1 - row][2*col + (BOARD_SIZE - 1 - row) %2] = new Piece(Color.BLACK, BOARD_SIZE - 1 - row, 2*col + (BOARD_SIZE - 1 - row) %2);
}
}
}

public void printBoard()
{
for(int row = 0; row < BOARD_SIZE; row++)
{
for (int col = 0; col < BOARD_SIZE; col++)
{
if (!isOccupied(row, col))
System.out.print("| ");
else if (representation[row][col].getColor() == Color.RED)
{
if (representation[row][col].getType() == Type.NORMAL)
System.out.print("|r");
else
System.out.print("|R");
}
else
{
if(representation[row][col].getType() == Type.NORMAL)
System.out.print("|b");
else
System.out.print("|B");
}

}
System.out.println("|");
}
}

public boolean isOccupied(int row, int col)
{
return representation[row][col] != null;
}



}
4 changes: 4 additions & 0 deletions src/model/Piece.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public void promote() {
public Type getType() {
return this.type;
}

public Color getColor() {
return this.color;
}
}
12 changes: 12 additions & 0 deletions src/model/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package model;

public class Test {
public static void main(String[]args)
{
Board checkers = new Board();
checkers.initBoard();
checkers.printBoard();
}


}

0 comments on commit 62a40cd

Please sign in to comment.