From 5ed596ded03526c630fe4e94197f6e6b5af6b63d Mon Sep 17 00:00:00 2001 From: aah13002 Date: Tue, 29 Mar 2016 01:01:30 -0400 Subject: [PATCH] Added comments and improved readability --- src/model/Board.java | 24 ++++++++++++++++++------ src/test/BoardTest.java | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/model/Board.java b/src/model/Board.java index d48e607..d0a0b0d 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -18,7 +18,7 @@ public enum Direction {UP, DOWN, LEFT, RIGHT}; public Board() { representation = new Piece[BOARD_SIZE][BOARD_SIZE]; movesSinceCapture = 0; - initBoard(); + init(); } public boolean isValidSquare(int i, int j) { @@ -27,6 +27,7 @@ public boolean isValidSquare(int i, int j) { /** * Checks if a piece can attack another in a given direction. + * * @param p The piece. * @param X The direction along the x-coordinate (LEFT or RIGHT). * @param Y The direction along the y-coordinate (UP or DOWN). @@ -56,6 +57,7 @@ public boolean checkAttackDirection(Piece p, Direction X, Direction Y) { * that move is invalid because the player can keep on attacking. * We go by the convention that black starts out at the "bottom", and * red starts out at the "top". Smoke moves before fire. + * * @param p * @return */ @@ -71,8 +73,11 @@ public boolean hasAttackVector(Piece p) { } return can_attack; } - - private void initBoard() + + /** + * Initialize the board putting checker pieces in their starting locations + */ + private void init() { for(int row = 0; row < 3; row++){ for (int col = 0; col < 4; col++) @@ -84,8 +89,11 @@ private void initBoard() } } } - - public void printBoard() + + /** + * Print the current board representation + */ + public void print() { for(int row = 0; row < BOARD_SIZE; row++) { @@ -112,7 +120,11 @@ else if (representation[row][col].getColor() == Color.RED) System.out.println("|"); } } - + + /** + * return true if square contains a piece + * return false otherwise + */ public boolean isOccupied(int row, int col) { return representation[row][col] != null; diff --git a/src/test/BoardTest.java b/src/test/BoardTest.java index 1e30c07..a30f653 100755 --- a/src/test/BoardTest.java +++ b/src/test/BoardTest.java @@ -6,7 +6,7 @@ public class BoardTest { public static void main(String[]args) { Board checkers = new Board(); - checkers.printBoard(); + checkers.print(); } }