diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-16 19:07:47 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-16 19:07:47 +0200 |
commit | be4b1b41200f5383850db3b20fb9aabf38374010 (patch) | |
tree | e403f80ccc771faf1a3416c83f2bcd813d8471d3 /src | |
parent | edf4197c1644f22f29ec4135fc6cbee4eb37d056 (diff) | |
download | JRummikub-be4b1b41200f5383850db3b20fb9aabf38374010.tar JRummikub-be4b1b41200f5383850db3b20fb9aabf38374010.zip |
Implemented new hand wrapping
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@240 72836036-5685-4462-b002-a69064685172
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); } } } |