Rekursives Verschieben getestet und heile gemacht
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@70 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
78049911ca
commit
e964c53cb6
2 changed files with 26 additions and 2 deletions
|
@ -15,7 +15,7 @@ import jrummikub.util.Pair;
|
|||
*/
|
||||
public class StoneTray<E extends Sizeable> implements
|
||||
Iterable<Pair<E, Position>> {
|
||||
protected List<Pair<E, Position>> objects = new ArrayList<Pair<E, Position>>();
|
||||
protected ArrayList<Pair<E, Position>> objects = new ArrayList<Pair<E, Position>>();
|
||||
|
||||
/** Possible move directions in case of overlapping Stones/Sets */
|
||||
|
||||
|
@ -68,8 +68,9 @@ public class StoneTray<E extends Sizeable> implements
|
|||
drop(object, position, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void drop(E object, Position position, Direction direction) {
|
||||
for (Pair<E, Position> i : objects) {
|
||||
for (Pair<E, Position> i : (List<Pair<E, Position>>)objects.clone()) {
|
||||
Position currentPosition = i.getSecond();
|
||||
E currentObject = i.getFirst();
|
||||
if (!objectsOverlap(object, position, currentObject,
|
||||
|
@ -100,6 +101,7 @@ public class StoneTray<E extends Sizeable> implements
|
|||
currentPosition.getY());
|
||||
break;
|
||||
}
|
||||
|
||||
objects.remove(i);
|
||||
drop(currentObject, newPosition, direction);
|
||||
}
|
||||
|
|
|
@ -109,6 +109,27 @@ public class StoneTrayTest {
|
|||
assertEquals(1, secondPosition.getX(), 0.00001);
|
||||
assertEquals(-2, secondPosition.getY(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleShift() {
|
||||
Thing firstThing = new Thing(5, 5);
|
||||
testTray.drop(firstThing, new Position(0, 0));
|
||||
|
||||
Thing secondThing = new Thing(5, 0.1f);
|
||||
testTray.drop(secondThing, new Position(5, 0));
|
||||
|
||||
Thing thirdThing = new Thing(3, 3);
|
||||
testTray.drop(thirdThing, new Position(-2, 1));
|
||||
Position firstPosition = testTray.getPosition(firstThing);
|
||||
Position secondPosition = testTray.getPosition(secondThing);
|
||||
Position thirdPosition = testTray.getPosition(thirdThing);
|
||||
assertEquals(1, firstPosition.getX(), 0.00001);
|
||||
assertEquals(0, firstPosition.getY(), 0.00001);
|
||||
assertEquals(6, secondPosition.getX(), 0.00001);
|
||||
assertEquals(0, secondPosition.getY(), 0.00001);
|
||||
assertEquals(-2, thirdPosition.getX(), 0.00001);
|
||||
assertEquals(1, thirdPosition.getY(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongPickUp() {
|
||||
|
@ -128,6 +149,7 @@ public class StoneTrayTest {
|
|||
assertSame(testTray.pickUp(testPosition), firstThing);
|
||||
assertNull(testTray.pickUp(testPosition));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIterate() {
|
||||
|
|
Reference in a new issue