From be4b1b41200f5383850db3b20fb9aabf38374010 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Mon, 16 May 2011 19:07:47 +0200 Subject: Implemented new hand wrapping git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@240 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/Hand.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src') 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 implements IHand { /** * The height of the hand */ + @Deprecated public final static int HEIGHT = 2; + private boolean rowIsFull(float row) { + int count = 0; + for (Pair entry : this) { + if (entry.getSecond().getY() == row) { + count++; + } + } + return count == WIDTH; + } + @Override protected Pair fixInvalidDrop(Stone stone, Position pos, Direction dir) { @@ -25,16 +36,12 @@ public class Hand extends StoneTray implements IHand { return null; } if (x < 0) { - if (y == 0) { - return new Pair(new Position(0, 0), RIGHT); - } else { - return new Pair(new Position(WIDTH - 1, 0), LEFT); - } + return new Pair(new Position(0, y), RIGHT); } else { - if (y == 0) { - return new Pair(new Position(0, 1), RIGHT); + if (rowIsFull(y)) { + return new Pair(new Position(0, y + 1), RIGHT); } else { - return new Pair(new Position(WIDTH - 1, 1), LEFT); + return new Pair(new Position(WIDTH - 1, y), LEFT); } } } -- cgit v1.2.3