1.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Fence.java Sun May 24 15:27:02 2009 +0200
1.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Fence.java Sun May 24 15:27:19 2009 +0200
1.3 @@ -70,6 +70,24 @@
1.4 this.o = o;
1.5 }
1.6
1.7 + /** The column of the center of the fence. The same
1.8 + * as used in {@link Move#fence(char, int, cz.xelfi.quoridor.Fence.Orientation)}.
1.9 + *
1.10 + * @return a letter between 'A' and 'H'
1.11 + */
1.12 + public char getColumn() {
1.13 + return (char) ('A' + (x - 1) / 2);
1.14 + }
1.15 +
1.16 + /** The row of the center of the fence. The same
1.17 + * as specified in {@link Move#fence(char, int, cz.xelfi.quoridor.Fence.Orientation)}.
1.18 + *
1.19 + * @return a number between 1 and 8
1.20 + */
1.21 + public int getRow() {
1.22 + return (y + 1) / 2;
1.23 + }
1.24 +
1.25 /** Midle coordinate of the fence.
1.26 * @return 1-15
1.27 */
1.28 @@ -85,8 +103,10 @@
1.29 }
1.30
1.31 /** The orientation of the fence.
1.32 + *
1.33 + * @return HORIZONTAL or VERTICAL
1.34 */
1.35 - Orientation getOrientation() {
1.36 + public Orientation getOrientation() {
1.37 return o;
1.38 }
1.39
2.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Move.java Sun May 24 15:27:02 2009 +0200
2.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Move.java Sun May 24 15:27:19 2009 +0200
2.3 @@ -84,17 +84,17 @@
2.4 * </pre>
2.5 *
2.6 *
2.7 - * @param x x-coordinate of the middle of the fence from 'A' to 'B'
2.8 - * @param y y-coordinate of the middle of the fence
2.9 + * @param column x-coordinate of the middle of the fence from 'A' to 'B'
2.10 + * @param row y-coordinate of the middle of the fence
2.11 * @param orientation place the fence horizontally or vertically
2.12 * @return the new board
2.13 * @exception IllegalPositionException if the move is not possible
2.14 */
2.15 - public static Move fence(char x, int y, Fence.Orientation orientation) throws IllegalPositionException {
2.16 - if (x < 'A' || 'H' < x) {
2.17 + public static Move fence(char column, int row, Fence.Orientation orientation) throws IllegalPositionException {
2.18 + if (column < 'A' || 'H' < column) {
2.19 throw new IllegalPositionException ("x coordinate has to be from A to H"); // NOI18N
2.20 }
2.21 - return new Move(new Fence ((x - 'A') * 2 + 1, y * 2 - 1, orientation));
2.22 + return new Move(new Fence ((column - 'A') * 2 + 1, row * 2 - 1, orientation));
2.23 }
2.24
2.25 /** Moves the player in given directions. After applying
3.1 --- a/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java Sun May 24 15:27:02 2009 +0200
3.2 +++ b/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java Sun May 24 15:27:19 2009 +0200
3.3 @@ -25,6 +25,7 @@
3.4 */
3.5 package cz.xelfi.quoridor;
3.6
3.7 +import java.util.Iterator;
3.8 import java.util.List;
3.9 import junit.framework.TestCase;
3.10
3.11 @@ -130,6 +131,10 @@
3.12
3.13 public void testCannotJumpOverFence () throws Exception {
3.14 Board b = fence (board, 0, 'D', 8, Fence.Orientation.HORIZONTAL);
3.15 + assertEquals("One fence is present", 1, b.getFences().size());
3.16 + final Fence f = b.getFences().iterator().next();
3.17 + assertEquals("Row is 8", 8, f.getRow());
3.18 + assertEquals("Column is D", 'D', f.getColumn());
3.19 try {
3.20 move(b, 1, Player.Direction.SOUTH);
3.21 fail ("This shall not be allowed, as there is the fence");