Added all missing comments

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@213 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-10 03:54:48 +02:00
parent 4a860e53cf
commit 3b49b2053e
38 changed files with 696 additions and 263 deletions

View file

@ -11,6 +11,9 @@ public class GameState implements IGameState {
private int activePlayer;
private StoneHeap gameHeap;
/**
* Create a new GameState with an empty table and (currntly) 4 new players.
*/
public GameState() {
table = new Table();
players = new ArrayList<Player>();
@ -37,7 +40,6 @@ public class GameState implements IGameState {
return players.size();
}
/** Changes the activePlayer to the next {@link Player} in the list */
@Override
public void nextPlayer() {
activePlayer = (activePlayer + 1) % players.size();

View file

@ -1,20 +1,56 @@
package jrummikub.model;
/**
* Interface for {@link GameState} model
*/
public interface IGameState {
/**
* Get the current {@link Table}
*
* @return The current Table
*/
public ITable getTable();
/**
* Sets the current {@link Table}
*
* @param table
* The new Table
*/
public void setTable(ITable table);
/**
* Returns the number of players
*
* @return number of players
*/
public int getPlayerCount();
/** Changes the activePlayer to the next {@link Player} in the list */
public void nextPlayer();
/**
* Returns the currently active player
*
* @return currently active player
*/
public IPlayer getActivePlayer();
/**
* Returns the heap of stones to draw from
*
* @return heap of stones
*/
public StoneHeap getGameHeap();
/**
* Returns the player that would be the active player after i turns
*
* @param i
* number of turns
* @return player active after i turns
*/
public IPlayer getNthNextPlayer(int i);
}

View file

@ -1,5 +1,8 @@
package jrummikub.model;
/**
* Interface for the {@link Hand} model
*/
public interface IHand extends IStoneTray<Stone> {
}

View file

@ -2,12 +2,30 @@ package jrummikub.model;
import java.awt.Color;
/**
* Interface for {@link Player} model
*/
public interface IPlayer {
/**
* Get the current hand of the player
*
* @return the player's hand
*/
public IHand getHand();
/**
* Return the player's color
*
* @return the player's color
*/
public Color getColor();
/**
* Return the name of the player
*
* @return the player's name
*/
public String getName();
}

View file

@ -2,6 +2,12 @@ package jrummikub.model;
import jrummikub.util.Pair;
/**
* Interface for the {@link StoneTray} model
*
* @param <E>
* Objects held by the IStoneTray
*/
public interface IStoneTray<E extends Sizeable> extends
Iterable<Pair<E, Position>>, Cloneable {
@ -9,7 +15,7 @@ public interface IStoneTray<E extends Sizeable> extends
* Removes object from tray and returns it
*
* @param position
* position of the object that will be removed
* position of the object that will be removed
* @return the picked up stone
*/
public E pickUp(Position position);
@ -18,9 +24,9 @@ public interface IStoneTray<E extends Sizeable> extends
* Adds object to the tray
*
* @param object
* object to add to Hand
* object to add to Hand
* @param position
* {@link Position} to put the object
* {@link Position} to put the object
*/
public void drop(E object, Position position);
@ -28,15 +34,32 @@ public interface IStoneTray<E extends Sizeable> extends
* Returns the position of an object that is already on the tray
*
* @param object
* object whose position is requested
* object whose position is requested
* @return position of the object or null when the object is not on the tray
*/
public Position getPosition(E object);
/**
* Tries to pick up (remove) a given object
*
* @param object
* object to pick up
* @return true when the object was successfully removed
*/
public boolean pickUp(E object);
/**
* Create a clone of the StoneTray
*
* @return cloned StoneTray
*/
public IStoneTray<E> clone();
/**
* Return the number of objects on the tray
*
* @return number of objects
*/
public int getSize();
}

View file

@ -2,20 +2,32 @@ package jrummikub.model;
import jrummikub.util.Pair;
/**
* Interface for the {@link Table} model
*/
public interface ITable extends IStoneTray<StoneSet> {
/**
* Removes {@link Stone} from the Table
*
* @param stone
* stone to pick up
* stone to pick up
* @return the stone sets that are created by taking pickung the the stone
*/
public Pair<StoneSet, StoneSet> pickUpStone(Stone stone);
/** Tests the Table for rule conflicts by checking all the {@link StoneSet} */
/**
* Tests the Table for rule conflicts by checking all the {@link StoneSet}
*
* @return whether all sets on the table are valid
*/
public boolean isValid();
/**
* Finds the {@link StoneSet} containing the given {@link Stone}
* @param stone stone whose set we're searching
* @return the set containing the stone or null if no set was found
*/
StoneSet findStoneSet(Stone stone);
}

View file

@ -9,8 +9,14 @@ public class Player implements IPlayer {
private String name;
private Color color;
// private String name;
/**
* Create a new player with a given name and color
*
* @param name
* player name
* @param color
* player's color
*/
public Player(String name, Color color) {
hand = new Hand();
this.name = name;

View file

@ -2,5 +2,12 @@ package jrummikub.model;
/** Class specifying possible StoneColors */
public enum StoneColor {
BLACK, ORANGE, BLUE, RED
/** */
BLACK,
/** */
ORANGE,
/** */
BLUE,
/** */
RED
}

View file

@ -43,7 +43,7 @@ public class StoneHeap {
* Removes several {@link Stone}s from the heap and returns them
*
* @param number
* number of requested Stones
* number of requested Stones
* @return list of drawn stones
*/
public List<Stone> drawStones(int number) {
@ -54,10 +54,21 @@ public class StoneHeap {
return drawnStones;
}
/**
* Get the number of stones left
*
* @return number of stones on the heap
*/
public int getSize() {
return heap.size();
}
/**
* Put stones back on the heap
*
* @param stones
* collection of stones to put back
*/
public void putBack(Collection<Stone> stones) {
heap.addAll(stones);
}

View file

@ -18,16 +18,34 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
static final float HORIZONTAL_BORDER = 0.125f;
private List<Stone> stones;
/**
* Create a new single stone stone set
*
* @param stone
* single stone of the set
*/
public StoneSet(Stone stone) {
stones = Collections.singletonList(stone);
}
/**
* Create a stone set from a list of stones
*
* @param stones
* list of stones to build a set of
*/
public StoneSet(List<Stone> stones) {
this.stones = new ArrayList<Stone>(stones);
}
/** Validity type of the set */
public enum Type {
GROUP, RUN, INVALID
/** Set is a valid group */
GROUP,
/** Set is a valid run */
RUN,
/** Set is invalid */
INVALID
}
/**
@ -40,8 +58,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
}
/**
* Test for rule conflict within the StoneSet and determine whether the set is
* a group or a run
* Test for rule conflict within the StoneSet and determine whether the set
* is a group or a run
*
* @return GROUP or RUN for valid sets, INVALID otherwise
*/
@ -62,13 +80,15 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
return GROUP;
}
// is run
if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2).getColor()) {
if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2)
.getColor()) {
return isValidRun(nonJoker1) ? RUN : INVALID;
}
// is group
else {
return isValidGroup(stones.get(nonJoker1).getValue()) ? GROUP : INVALID;
return isValidGroup(stones.get(nonJoker1).getValue()) ? GROUP
: INVALID;
}
}
@ -76,7 +96,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
* Test for rule conflict within the StoneSet, assuming we have a run
*
* @param referencePosition
* position of stone used as reference (any non-joker stone)
* position of stone used as reference (any non-joker stone)
*/
private boolean isValidRun(int referencePosition) {
StoneColor runColor = stones.get(referencePosition).getColor();
@ -130,7 +150,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
* Stone Sets
*
* @param position
* Splitting {@link Position}
* Splitting {@link Position}
* @return A pair of StoneSets, one for each split part
*/
public Pair<StoneSet, StoneSet> splitAt(int position) {
@ -140,7 +160,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
return new Pair<StoneSet, StoneSet>(this, null);
}
StoneSet firstSet = new StoneSet(stones.subList(0, position));
StoneSet secondSet = new StoneSet(stones.subList(position, stones.size()));
StoneSet secondSet = new StoneSet(stones.subList(position,
stones.size()));
return new Pair<StoneSet, StoneSet>(firstSet, secondSet);
}
@ -148,7 +169,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
* Joins StoneSet to another StoneSet and returns the resulting new StoneSet
*
* @param other
* StoneSet to be joined to active StoneSet
* StoneSet to be joined to active StoneSet
* @return the combined StoneSet
*/
public StoneSet join(StoneSet other) {
@ -171,7 +192,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
* Returns the i-th stone of the set (starting with 0)
*
* @param i
* number of the stone to return
* number of the stone to return
* @return the i-th stone
*/
public Stone get(int i) {