diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-05-16 22:01:02 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-05-16 22:01:02 +0200 |
commit | 604ef91282ad234130b1d46569efd486ab6c5024 (patch) | |
tree | 53fab92b75551c8acc8979d77ffa8351f788ae90 /src/jrummikub/model | |
parent | 57227570fe6bf9eb5ecf17c32a1db1a7bbed85e3 (diff) | |
download | JRummikub-604ef91282ad234130b1d46569efd486ab6c5024.tar JRummikub-604ef91282ad234130b1d46569efd486ab6c5024.zip |
Fix dealing stones for more than 2 rows
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@244 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/model')
-rw-r--r-- | src/jrummikub/model/Hand.java | 27 | ||||
-rw-r--r-- | src/jrummikub/model/IHand.java | 15 |
2 files changed, 33 insertions, 9 deletions
diff --git a/src/jrummikub/model/Hand.java b/src/jrummikub/model/Hand.java index 1337829..ab5eb19 100644 --- a/src/jrummikub/model/Hand.java +++ b/src/jrummikub/model/Hand.java @@ -10,22 +10,31 @@ public class Hand extends StoneTray<Stone> implements IHand { * The width of the hand */ public final static int WIDTH = 14; - /** - * The height of the hand - */ - @Deprecated - public final static int HEIGHT = 2; - private boolean rowIsFull(float row) { + @Override + public int getFreeRowSpace(int row) { int count = 0; for (Pair<Stone, Position> entry : this) { if (entry.getSecond().getY() == row) { count++; } } - return count == WIDTH; + return WIDTH - count; + } + + @Override + public int getRowCount() { + int rows = 0; + + for (Pair<Stone, Position> entry : this) { + if (entry.getSecond().getY() > rows) { + rows = (int) entry.getSecond().getY(); + } + } + + return rows + 1; } - + @Override protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos, Direction dir) { @@ -38,7 +47,7 @@ public class Hand extends StoneTray<Stone> implements IHand { if (x < 0) { return new Pair<Position, Direction>(new Position(0, y), RIGHT); } else { - if (rowIsFull(y)) { + if (getFreeRowSpace((int) y) == 0) { return new Pair<Position, Direction>(new Position(0, y + 1), RIGHT); } else { return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT); diff --git a/src/jrummikub/model/IHand.java b/src/jrummikub/model/IHand.java index f5234d1..dafa9c7 100644 --- a/src/jrummikub/model/IHand.java +++ b/src/jrummikub/model/IHand.java @@ -5,4 +5,19 @@ package jrummikub.model; */
public interface IHand extends IStoneTray<Stone> {
+ /**
+ * The number of used rows
+ *
+ * @return the number of rows
+ */
+ int getRowCount();
+
+ /**
+ * Gets the amount of free space in a hand row
+ *
+ * @param row
+ * the row number
+ * @return the number of stones that can fit into the row
+ */
+ int getFreeRowSpace(int row);
}
|