summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-04-30 15:45:11 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-04-30 15:45:11 +0200
commit0ef783407075008514b9e3eb9b32ea67501e4206 (patch)
tree38c3ea0dcb950b88e7e08c67d6bbad57b9e73e38
parent59e6d9c45174b06140175b3ea35d47e0eb1651d9 (diff)
downloadJRummikub-0ef783407075008514b9e3eb9b32ea67501e4206.tar
JRummikub-0ef783407075008514b9e3eb9b32ea67501e4206.zip
Arrays zu Listen geƤndert, StoneTray Klasse mit Sizeable Interface angelegt, Testklassen erzeugt
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@26 72836036-5685-4462-b002-a69064685172
-rw-r--r--src/jrummikub/model/GameState.java2
-rw-r--r--src/jrummikub/model/Hand.java26
-rw-r--r--src/jrummikub/model/Sizeable.java9
-rw-r--r--src/jrummikub/model/StoneSet.java6
-rw-r--r--src/jrummikub/model/StoneTray.java31
-rw-r--r--src/jrummikub/model/Table.java28
-rw-r--r--src/jrummikub/util/Pair.java24
-rw-r--r--test/jrummikub/model/PlayerTest.java5
-rw-r--r--test/jrummikub/model/StoneSetTest.java (renamed from test/jrummikub/model/HandTest.java)3
-rw-r--r--test/jrummikub/model/StoneTrayTest.java6
10 files changed, 80 insertions, 60 deletions
diff --git a/src/jrummikub/model/GameState.java b/src/jrummikub/model/GameState.java
index ce81ece..d5c12ba 100644
--- a/src/jrummikub/model/GameState.java
+++ b/src/jrummikub/model/GameState.java
@@ -3,7 +3,7 @@ package jrummikub.model;
/** Class managing the overall and momentary GameState */
public class GameState {
private Table table;
- private Player[] players;
+ private List<Player> players;
private int activePlayer;
private StoneHeap gameHeap;
diff --git a/src/jrummikub/model/Hand.java b/src/jrummikub/model/Hand.java
index 9437b04..033dfa1 100644
--- a/src/jrummikub/model/Hand.java
+++ b/src/jrummikub/model/Hand.java
@@ -1,30 +1,6 @@
package jrummikub.model;
/** Class managing a {@link Player}'s {@link Stone}s */
-public class Hand {
- private Stone[] stones;
- private Position[] position;
-
- /**
- * Removes {@link Stone} from Hand and returns it
- *
- * @param position
- * position of {@link Stone} that will be removed
- */
- public Stone pickUp(Position position) {
-
- }
-
- /**
- * Adds {@link Stone} to the Hand
- *
- * @param stone
- * {@link Stone} to add to Hand
- * @param position
- * {@link Position} to put the {@link Stone}
- */
- public void drop(Stone stone, Position position) {
-
- }
+public class Hand extends StoneTray<Stone> {
}
diff --git a/src/jrummikub/model/Sizeable.java b/src/jrummikub/model/Sizeable.java
new file mode 100644
index 0000000..fa022cc
--- /dev/null
+++ b/src/jrummikub/model/Sizeable.java
@@ -0,0 +1,9 @@
+package jrummikub.model;
+
+/**
+ * Objects that have a size
+ */
+public interface Sizeable {
+ public float getWidth();
+ public float getHeight();
+}
diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java
index 67ad795..706ed3b 100644
--- a/src/jrummikub/model/StoneSet.java
+++ b/src/jrummikub/model/StoneSet.java
@@ -1,8 +1,10 @@
package jrummikub.model;
+import jrummikub.util.Pair;
+
/** Class managing {@link Stone}s joined together to form sets */
public class StoneSet {
- private Stone[] stones;
+ private List<Stone> stones;
/** Test for rule conflict within the StoneSet */
public boolean isValid() {
@@ -16,7 +18,7 @@ public class StoneSet {
* @param position
* Splitting {@link Position}
*/
- public StoneSet[] splitAt(int position) {
+ public Pair<StoneSet, StoneSet> splitAt(int position) {
}
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java
new file mode 100644
index 0000000..4a22870
--- /dev/null
+++ b/src/jrummikub/model/StoneTray.java
@@ -0,0 +1,31 @@
+package jrummikub.model;
+
+/** A StoneTray is a collection of positioned objects (for example {@link Stone}s or {@link StoneSet}s. */
+public abstract class StoneTray<E extends Sizeable> {
+ protected List<E> objects;
+ protected List<Position> positions;
+
+ /**
+ * Removes object from tray and returns it
+ *
+ * @param position
+ * position of the object that will be removed
+ */
+ public E pickUp(Position position) {
+
+ }
+
+
+ /**
+ * Adds object to the tray
+ *
+ * @param object
+ * object to add to Hand
+ * @param position
+ * {@link Position} to put the object
+ */
+ public void drop(E object, Position position) {
+
+ }
+
+}
diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java
index 923a6a1..8a1b40f 100644
--- a/src/jrummikub/model/Table.java
+++ b/src/jrummikub/model/Table.java
@@ -2,9 +2,7 @@ package jrummikub.model;
/** Class administering the {@link Stone}s on the game-Table */
-public class Table {
- private StoneSet[] sets;
- private Position[] positions;
+public class Table extends StoneTray<StoneSet> {
// Constructor
public Table gameTable = new Table();
@@ -15,17 +13,7 @@ public class Table {
* @param position
* {@link Position} of the selected {@link Stone}
*/
- public Stone pickUp(Position position) {
-
- }
-
- /**
- * Removes a {@link StoneSet} from the Table and returns it
- *
- * @param position
- * {@link Position} of the selected {@link StoneSet}
- */
- public StoneSet pickUpSet(Position position) {
+ public Stone pickUpStone(Position position) {
}
@@ -41,18 +29,6 @@ public class Table {
}
- /**
- * Adds {@link StoneSet} to Table
- *
- * @param position
- * Specifies {@link Position} to put the {@link StoneSet}
- * @param stones
- * The {@link StoneSet} to add to the Table
- */
- public void drop(Position position, StoneSet stones) {
-
- }
-
/** Tests the Table for rule conflicts by checking all the {@link StoneSets} */
public boolean isValid() {
diff --git a/src/jrummikub/util/Pair.java b/src/jrummikub/util/Pair.java
new file mode 100644
index 0000000..95af113
--- /dev/null
+++ b/src/jrummikub/util/Pair.java
@@ -0,0 +1,24 @@
+package jrummikub.util;
+
+/**
+ * A pair of objects
+ */
+public class Pair<T1, T2> {
+ final T1 first;
+ final T2 second;
+
+ public Pair(T1 first, T2 second) {
+ this.first = first;
+ this.second = second;
+ }
+
+ public T1 getFirst() {
+ return first;
+ }
+
+ public T2 getSecond() {
+ return second;
+ }
+
+
+}
diff --git a/test/jrummikub/model/PlayerTest.java b/test/jrummikub/model/PlayerTest.java
deleted file mode 100644
index 8e2e66b..0000000
--- a/test/jrummikub/model/PlayerTest.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package jrummikub.model;
-
-public class PlayerTest {
-
-}
diff --git a/test/jrummikub/model/HandTest.java b/test/jrummikub/model/StoneSetTest.java
index 012a56c..fc7ebda 100644
--- a/test/jrummikub/model/HandTest.java
+++ b/test/jrummikub/model/StoneSetTest.java
@@ -1,5 +1,6 @@
package jrummikub.model;
-public class HandTest {
+
+public class StoneSetTest {
}
diff --git a/test/jrummikub/model/StoneTrayTest.java b/test/jrummikub/model/StoneTrayTest.java
new file mode 100644
index 0000000..df9aaa9
--- /dev/null
+++ b/test/jrummikub/model/StoneTrayTest.java
@@ -0,0 +1,6 @@
+package jrummikub.model;
+
+
+public class StoneTrayTest {
+
+}