diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/model/Hand.java | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/jrummikub/model/Hand.java b/src/jrummikub/model/Hand.java index 62531f4..1337829 100644 --- a/src/jrummikub/model/Hand.java +++ b/src/jrummikub/model/Hand.java @@ -13,8 +13,19 @@ public class Hand extends StoneTray<Stone> implements IHand { /** * The height of the hand */ + @Deprecated public final static int HEIGHT = 2; + private boolean rowIsFull(float row) { + int count = 0; + for (Pair<Stone, Position> entry : this) { + if (entry.getSecond().getY() == row) { + count++; + } + } + return count == WIDTH; + } + @Override protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos, Direction dir) { @@ -25,16 +36,12 @@ public class Hand extends StoneTray<Stone> implements IHand { return null; } if (x < 0) { - if (y == 0) { - return new Pair<Position, Direction>(new Position(0, 0), RIGHT); - } else { - return new Pair<Position, Direction>(new Position(WIDTH - 1, 0), LEFT); - } + return new Pair<Position, Direction>(new Position(0, y), RIGHT); } else { - if (y == 0) { - return new Pair<Position, Direction>(new Position(0, 1), RIGHT); + if (rowIsFull(y)) { + return new Pair<Position, Direction>(new Position(0, y + 1), RIGHT); } else { - return new Pair<Position, Direction>(new Position(WIDTH - 1, 1), LEFT); + return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT); } } } |