summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-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
7 files changed, 72 insertions, 54 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;
+ }
+
+
+}