Rechtschreibfehler und überflüssige pickUp(position) Klasse gefixt
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@227 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
cdd0949db3
commit
982c2e6e2b
7 changed files with 27 additions and 85 deletions
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock class for {@link Hand}
|
* Mock class for {@link Hand}
|
||||||
*/
|
*/
|
||||||
|
@ -14,15 +15,10 @@ public class MockHand implements IHand {
|
||||||
/** */
|
/** */
|
||||||
public List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>();
|
public List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>();
|
||||||
/** */
|
/** */
|
||||||
public Set<Stone> pickups = new HashSet<Stone>();
|
public Set<Stone> pickups = new HashSet<Stone>();
|
||||||
/** */
|
/** */
|
||||||
public Iterable<Pair<Stone, Position>> iterable;
|
public Iterable<Pair<Stone, Position>> iterable;
|
||||||
|
|
||||||
@Override
|
|
||||||
public Stone pickUp(Position position) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drop(Stone object, Position position) {
|
public void drop(Stone object, Position position) {
|
||||||
stones.add(new Pair<Stone, Position>(object, position));
|
stones.add(new Pair<Stone, Position>(object, position));
|
||||||
|
@ -36,7 +32,8 @@ public class MockHand implements IHand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean pickUp(Stone object) {
|
public boolean pickUp(Stone object) {
|
||||||
List<Pair<Stone, Position>> itList = new ArrayList<Pair<Stone, Position>>(stones);
|
List<Pair<Stone, Position>> itList = new ArrayList<Pair<Stone, Position>>(
|
||||||
|
stones);
|
||||||
for (Pair<Stone, Position> entry : itList) {
|
for (Pair<Stone, Position> entry : itList) {
|
||||||
if (entry.getFirst() == object) {
|
if (entry.getFirst() == object) {
|
||||||
stones.remove(entry);
|
stones.remove(entry);
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock class for {@link Table}
|
* Mock class for {@link Table}
|
||||||
*/
|
*/
|
||||||
|
@ -31,12 +32,6 @@ public class MockTable implements ITable {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public StoneSet pickUp(Position position) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drop(StoneSet object, Position position) {
|
public void drop(StoneSet object, Position position) {
|
||||||
sets.add(new Pair<StoneSet, Position>(object, position));
|
sets.add(new Pair<StoneSet, Position>(object, position));
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class GameState implements IGameState {
|
||||||
private StoneHeap gameHeap;
|
private StoneHeap gameHeap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new GameState with an empty table and (currntly) 4 new players.
|
* Create a new GameState with an empty table and (currently) 4 new players.
|
||||||
*/
|
*/
|
||||||
public GameState() {
|
public GameState() {
|
||||||
table = new Table();
|
table = new Table();
|
||||||
|
|
|
@ -11,15 +11,6 @@ import jrummikub.util.Pair;
|
||||||
public interface IStoneTray<E extends Sizeable> extends
|
public interface IStoneTray<E extends Sizeable> extends
|
||||||
Iterable<Pair<E, Position>>, Cloneable {
|
Iterable<Pair<E, Position>>, Cloneable {
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes object from tray and returns it
|
|
||||||
*
|
|
||||||
* @param position
|
|
||||||
* position of the object that will be removed
|
|
||||||
* @return the picked up stone
|
|
||||||
*/
|
|
||||||
public E pickUp(Position position);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds object to the tray
|
* Adds object to the tray
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.Random;
|
||||||
|
|
||||||
public class StoneHeap {
|
public class StoneHeap {
|
||||||
List<Stone> heap;
|
List<Stone> heap;
|
||||||
Random generator = new Random();
|
private Random generator = new Random();
|
||||||
|
|
||||||
/** Creates 106 Stones according to standard rules */
|
/** Creates 106 Stones according to standard rules */
|
||||||
public StoneHeap() {
|
public StoneHeap() {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import jrummikub.util.Pair;
|
||||||
* or {@link StoneSet}s.
|
* or {@link StoneSet}s.
|
||||||
*
|
*
|
||||||
* @param <E>
|
* @param <E>
|
||||||
* Type of positioned objects (must implement Sizeable)
|
* Type of positioned objects (must implement Sizeable)
|
||||||
*/
|
*/
|
||||||
public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
protected HashMap<E, Pair<E, Position>> objects = new HashMap<E, Pair<E, Position>>();
|
protected HashMap<E, Pair<E, Position>> objects = new HashMap<E, Pair<E, Position>>();
|
||||||
|
@ -22,31 +22,6 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
LEFT, RIGHT, TOP, BOTTOM;
|
LEFT, RIGHT, TOP, BOTTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public E pickUp(Position position) {
|
|
||||||
for (Map.Entry<E, Pair<E, Position>> i : objects.entrySet()) {
|
|
||||||
Position currentPosition = i.getValue().getSecond();
|
|
||||||
E currentObject = i.getKey();
|
|
||||||
// Tests if position is left of, above ... the current object
|
|
||||||
if (position.getX() < currentPosition.getX()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (position.getY() < currentPosition.getY()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (position.getX() > currentPosition.getX() + currentObject.getWidth()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (position.getY() > currentPosition.getY() + currentObject.getHeight()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Position is inside the current object
|
|
||||||
objects.remove(i.getKey());
|
|
||||||
return currentObject;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drop(E object, Position position) {
|
public void drop(E object, Position position) {
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
@ -75,7 +50,8 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
if (currentObject == object)
|
if (currentObject == object)
|
||||||
continue;
|
continue;
|
||||||
Position currentPosition = getPosition(currentObject);
|
Position currentPosition = getPosition(currentObject);
|
||||||
if (!objectsOverlap(object, position, currentObject, currentPosition)) {
|
if (!objectsOverlap(object, position, currentObject,
|
||||||
|
currentPosition)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Object would be placed inside the current object
|
// Object would be placed inside the current object
|
||||||
|
@ -86,16 +62,16 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
// Move object to avoid overlap
|
// Move object to avoid overlap
|
||||||
switch (newDirection) {
|
switch (newDirection) {
|
||||||
case TOP:
|
case TOP:
|
||||||
newPosition = new Position(currentPosition.getX(), position.getY()
|
newPosition = new Position(currentPosition.getX(),
|
||||||
- currentObject.getHeight());
|
position.getY() - currentObject.getHeight());
|
||||||
break;
|
break;
|
||||||
case BOTTOM:
|
case BOTTOM:
|
||||||
newPosition = new Position(currentPosition.getX(), position.getY()
|
newPosition = new Position(currentPosition.getX(),
|
||||||
+ object.getHeight());
|
position.getY() + object.getHeight());
|
||||||
break;
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
newPosition = new Position(position.getX() - currentObject.getWidth(),
|
newPosition = new Position(position.getX()
|
||||||
currentPosition.getY());
|
- currentObject.getWidth(), currentPosition.getY());
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
newPosition = new Position(position.getX() + object.getWidth(),
|
newPosition = new Position(position.getX() + object.getWidth(),
|
||||||
|
@ -109,14 +85,14 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the object may be placed on the given position, computes new
|
* Checks whether the object may be placed on the given position, computes
|
||||||
* position if not
|
* new position if not
|
||||||
*
|
*
|
||||||
* @param object
|
* @param object
|
||||||
* to be dropped
|
* to be dropped
|
||||||
* @param dir
|
* @param dir
|
||||||
* @param p
|
* @param p
|
||||||
* the object is dropped at
|
* the object is dropped at
|
||||||
* @return null if the drop is valid, new position otherwise
|
* @return null if the drop is valid, new position otherwise
|
||||||
*/
|
*/
|
||||||
protected Pair<Position, Direction> fixInvalidDrop(E object, Position pos,
|
protected Pair<Position, Direction> fixInvalidDrop(E object, Position pos,
|
||||||
|
@ -173,13 +149,15 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
float blockingRight = blocking.getSecond().getX()
|
float blockingRight = blocking.getSecond().getX()
|
||||||
+ blocking.getFirst().getWidth();
|
+ blocking.getFirst().getWidth();
|
||||||
float overlapRight = Math.min(objectRight, blockingRight);
|
float overlapRight = Math.min(objectRight, blockingRight);
|
||||||
float overlapLeft = Math.max(position.getX(), blocking.getSecond().getX());
|
float overlapLeft = Math.max(position.getX(), blocking.getSecond()
|
||||||
|
.getX());
|
||||||
float overlapX = overlapRight - overlapLeft;
|
float overlapX = overlapRight - overlapLeft;
|
||||||
float objectBottom = position.getY() + object.getHeight();
|
float objectBottom = position.getY() + object.getHeight();
|
||||||
float blockingBottom = blocking.getSecond().getY()
|
float blockingBottom = blocking.getSecond().getY()
|
||||||
+ blocking.getFirst().getHeight();
|
+ blocking.getFirst().getHeight();
|
||||||
float overlapBottom = Math.min(objectBottom, blockingBottom);
|
float overlapBottom = Math.min(objectBottom, blockingBottom);
|
||||||
float overlapTop = Math.max(position.getY(), blocking.getSecond().getY());
|
float overlapTop = Math.max(position.getY(), blocking.getSecond()
|
||||||
|
.getY());
|
||||||
float overlapY = overlapBottom - overlapTop;
|
float overlapY = overlapBottom - overlapTop;
|
||||||
// vertical or horizontal Shift
|
// vertical or horizontal Shift
|
||||||
// TODO magic factor
|
// TODO magic factor
|
||||||
|
|
|
@ -7,8 +7,9 @@ import jrummikub.util.Pair;
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link StoneTray}
|
* Tests for {@link StoneTray}
|
||||||
*/
|
*/
|
||||||
public class StoneTrayTest {
|
public class StoneTrayTest {
|
||||||
class Thing implements Sizeable {
|
class Thing implements Sizeable {
|
||||||
|
@ -32,6 +33,7 @@ public class StoneTrayTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private StoneTray<Thing> testTray;
|
private StoneTray<Thing> testTray;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void createTray() {
|
public void createTray() {
|
||||||
|
@ -146,15 +148,6 @@ public class StoneTrayTest {
|
||||||
assertEquals(1, thirdPosition.getY(), 0.00001);
|
assertEquals(1, thirdPosition.getY(), 0.00001);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
|
||||||
@Test
|
|
||||||
public void testWrongPickUp() {
|
|
||||||
Thing firstThing = new Thing(5, 5);
|
|
||||||
testTray.drop(firstThing, new Position(0, 0));
|
|
||||||
Position testPosition = new Position(-2, -2);
|
|
||||||
assertNull(testTray.pickUp(testPosition));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testPickUpByObject() {
|
public void testPickUpByObject() {
|
||||||
|
@ -169,18 +162,6 @@ public class StoneTrayTest {
|
||||||
assertTrue(testTray.iterator().hasNext());
|
assertTrue(testTray.iterator().hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
|
||||||
@Test
|
|
||||||
public void testRightPickUp() {
|
|
||||||
Thing firstThing = new Thing(5, 5);
|
|
||||||
testTray.drop(firstThing, new Position(0, 0));
|
|
||||||
Thing secondThing = new Thing(3, 3);
|
|
||||||
testTray.drop(secondThing, new Position(-5, -5));
|
|
||||||
Position testPosition = new Position(3, 3);
|
|
||||||
assertSame(testTray.pickUp(testPosition), firstThing);
|
|
||||||
assertNull(testTray.pickUp(testPosition));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testIterate() {
|
public void testIterate() {
|
||||||
|
|
Reference in a new issue