Define hand size constants in model
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@225 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
8f47c06e31
commit
32d07341a5
4 changed files with 26 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
||||||
package jrummikub.control;
|
package jrummikub.control;
|
||||||
|
|
||||||
import jrummikub.model.GameState;
|
import jrummikub.model.GameState;
|
||||||
|
import jrummikub.model.Hand;
|
||||||
import jrummikub.util.IListener;
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
|
@ -8,20 +9,19 @@ import jrummikub.view.IView;
|
||||||
* Controls a Game, at some point including all Rounds, starts new Rounds
|
* Controls a Game, at some point including all Rounds, starts new Rounds
|
||||||
*/
|
*/
|
||||||
public class GameControl {
|
public class GameControl {
|
||||||
final static int HAND_HEIGHT = 2;
|
|
||||||
final static int HAND_WIDTH = 14;
|
|
||||||
private IView view;
|
private IView view;
|
||||||
private RoundControl roundControl;
|
private RoundControl roundControl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param view the view
|
* @param view
|
||||||
|
* the view
|
||||||
*/
|
*/
|
||||||
public GameControl(IView view) {
|
public GameControl(IView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT);
|
view.getPlayerPanel().getHandPanel().setHandHeight(Hand.HEIGHT);
|
||||||
view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH);
|
view.getPlayerPanel().getHandPanel().setHandWidth(Hand.WIDTH);
|
||||||
|
|
||||||
view.getNewGameEvent().add(new IListener() {
|
view.getNewGameEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import jrummikub.model.Hand;
|
||||||
import jrummikub.model.IGameState;
|
import jrummikub.model.IGameState;
|
||||||
import jrummikub.model.IHand;
|
import jrummikub.model.IHand;
|
||||||
import jrummikub.model.ITable;
|
import jrummikub.model.ITable;
|
||||||
|
@ -98,17 +99,14 @@ public class RoundControl {
|
||||||
for (int i = 0; i < gameState.getPlayerCount(); i++) {
|
for (int i = 0; i < gameState.getPlayerCount(); i++) {
|
||||||
IHand hand = gameState.getNthNextPlayer(i).getHand();
|
IHand hand = gameState.getNthNextPlayer(i).getHand();
|
||||||
for (int j = 0; j < 7; j++) {
|
for (int j = 0; j < 7; j++) {
|
||||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0));
|
||||||
0));
|
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
|
||||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
|
||||||
1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endOfTurn() {
|
private void endOfTurn() {
|
||||||
Set<Stone> tableDiff = tableDifference(gameState.getTable(),
|
Set<Stone> tableDiff = tableDifference(gameState.getTable(), clonedTable);
|
||||||
clonedTable);
|
|
||||||
|
|
||||||
if (!tableDiff.isEmpty()) { // Player has made a move
|
if (!tableDiff.isEmpty()) { // Player has made a move
|
||||||
if (clonedTable.isValid()) {
|
if (clonedTable.isValid()) {
|
||||||
|
@ -156,8 +154,7 @@ public class RoundControl {
|
||||||
.getActivePlayer()
|
.getActivePlayer()
|
||||||
.getHand()
|
.getHand()
|
||||||
.drop(gameState.getGameHeap().drawStone(),
|
.drop(gameState.getGameHeap().drawStone(),
|
||||||
new Position(GameControl.HAND_WIDTH - 1,
|
new Position(Hand.WIDTH - 1, Hand.HEIGHT - 1));
|
||||||
GameControl.HAND_HEIGHT - 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dealPenalty(int count) {
|
private void dealPenalty(int count) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import jrummikub.model.Hand;
|
||||||
import jrummikub.model.IHand;
|
import jrummikub.model.IHand;
|
||||||
import jrummikub.model.ITable;
|
import jrummikub.model.ITable;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
|
@ -242,11 +243,11 @@ public class TurnControl {
|
||||||
for (Stone stone : stones) {
|
for (Stone stone : stones) {
|
||||||
hand.drop(stone, new Position(x, y));
|
hand.drop(stone, new Position(x, y));
|
||||||
x++;
|
x++;
|
||||||
if (x >= GameControl.HAND_WIDTH) {
|
if (x >= Hand.WIDTH) {
|
||||||
x = 0;
|
x = 0;
|
||||||
y++;
|
y++;
|
||||||
|
|
||||||
if (y >= GameControl.HAND_HEIGHT) {
|
if (y >= Hand.HEIGHT) {
|
||||||
// TODO We can't handle this yet...
|
// TODO We can't handle this yet...
|
||||||
throw new ArrayIndexOutOfBoundsException();
|
throw new ArrayIndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,14 @@ import static jrummikub.model.StoneTray.Direction.*;
|
||||||
|
|
||||||
/** Class managing a {@link Player}'s {@link Stone}s */
|
/** Class managing a {@link Player}'s {@link Stone}s */
|
||||||
public class Hand extends StoneTray<Stone> implements IHand {
|
public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
|
/**
|
||||||
|
* The width of the hand
|
||||||
|
*/
|
||||||
|
public final static int WIDTH = 14;
|
||||||
|
/**
|
||||||
|
* The height of the hand
|
||||||
|
*/
|
||||||
|
public final static int HEIGHT = 2;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
|
protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
|
||||||
|
@ -13,20 +21,20 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
float x = pos.getX();
|
float x = pos.getX();
|
||||||
float y = pos.getY();
|
float y = pos.getY();
|
||||||
|
|
||||||
if (x >= 0 && x <= 13) {
|
if (x >= 0 && x <= WIDTH - 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
return new Pair<Position, Direction>(new Position(0, 0), RIGHT);
|
return new Pair<Position, Direction>(new Position(0, 0), RIGHT);
|
||||||
} else {
|
} else {
|
||||||
return new Pair<Position, Direction>(new Position(13, 0), LEFT);
|
return new Pair<Position, Direction>(new Position(WIDTH - 1, 0), LEFT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
return new Pair<Position, Direction>(new Position(0, 1), RIGHT);
|
return new Pair<Position, Direction>(new Position(0, 1), RIGHT);
|
||||||
} else {
|
} else {
|
||||||
return new Pair<Position, Direction>(new Position(13, 1), LEFT);
|
return new Pair<Position, Direction>(new Position(WIDTH - 1, 1), LEFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue