From 62a40cd61cb137074a5589af255b5339015c6492 Mon Sep 17 00:00:00 2001 From: aah13002 Date: Mon, 28 Mar 2016 17:41:35 -0400 Subject: [PATCH] printBoard(), initBoard(), isOccupied() --- src/model/Board.java | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/model/Piece.java | 4 ++++ src/model/Test.java | 12 ++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/model/Test.java diff --git a/src/model/Board.java b/src/model/Board.java index 0ac97d6..3dc164a 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -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; + } + + } diff --git a/src/model/Piece.java b/src/model/Piece.java index b3765a1..332e29c 100755 --- a/src/model/Piece.java +++ b/src/model/Piece.java @@ -33,4 +33,8 @@ public void promote() { public Type getType() { return this.type; } + + public Color getColor() { + return this.color; + } } diff --git a/src/model/Test.java b/src/model/Test.java new file mode 100644 index 0000000..668ff38 --- /dev/null +++ b/src/model/Test.java @@ -0,0 +1,12 @@ +package model; + +public class Test { + public static void main(String[]args) + { + Board checkers = new Board(); + checkers.initBoard(); + checkers.printBoard(); + } + + +}