Angefangener Test für Hand-Steine-verschwinden-fix
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@194 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
fffca3fe9a
commit
050ae5f224
4 changed files with 85 additions and 38 deletions
|
@ -14,6 +14,9 @@ import jrummikub.util.Pair;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
public class RoundControl {
|
public class RoundControl {
|
||||||
|
// TODO move to game control once existent
|
||||||
|
final static int HAND_HEIGHT = 2;
|
||||||
|
final static int HAND_WIDTH = 14;
|
||||||
private IGameState gameState;
|
private IGameState gameState;
|
||||||
private IView view;
|
private IView view;
|
||||||
private ITable clonedTable;
|
private ITable clonedTable;
|
||||||
|
@ -21,6 +24,8 @@ public class RoundControl {
|
||||||
public RoundControl(IGameState gameState, IView view) {
|
public RoundControl(IGameState gameState, IView view) {
|
||||||
this.gameState = gameState;
|
this.gameState = gameState;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT);
|
||||||
|
view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRound() {
|
public void startRound() {
|
||||||
|
@ -68,14 +73,17 @@ 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, 0));
|
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
||||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
|
0));
|
||||||
|
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
||||||
|
1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endOfTurn() {
|
private void endOfTurn() {
|
||||||
Set<Stone> tableDiff = tableDifference(gameState.getTable(), clonedTable);
|
Set<Stone> tableDiff = tableDifference(gameState.getTable(),
|
||||||
|
clonedTable);
|
||||||
|
|
||||||
if (!tableDiff.isEmpty()) { // Player has made a move
|
if (!tableDiff.isEmpty()) { // Player has made a move
|
||||||
if (clonedTable.isValid()) {
|
if (clonedTable.isValid()) {
|
||||||
|
@ -118,7 +126,7 @@ public class RoundControl {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dealStone() {
|
void dealStone() {
|
||||||
gameState
|
gameState
|
||||||
.getActivePlayer()
|
.getActivePlayer()
|
||||||
.getHand()
|
.getHand()
|
||||||
|
|
|
@ -8,11 +8,15 @@ import jrummikub.util.Pair;
|
||||||
* The view for a player's hand that displays his stones
|
* The view for a player's hand that displays his stones
|
||||||
*/
|
*/
|
||||||
public interface IHandPanel extends IStonePanel, IClickable {
|
public interface IHandPanel extends IStonePanel, IClickable {
|
||||||
/**
|
/**
|
||||||
* Set the player's stones to display on the board
|
* Set the player's stones to display on the board
|
||||||
*
|
*
|
||||||
* @param stones
|
* @param stones
|
||||||
* the stones
|
* the stones
|
||||||
*/
|
*/
|
||||||
public void setStones(Iterable<Pair<Stone, Position>> stones);
|
public void setStones(Iterable<Pair<Stone, Position>> stones);
|
||||||
|
|
||||||
|
public void setHandWidth(int width);
|
||||||
|
|
||||||
|
public void setHandHeight(int height);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,15 @@ import jrummikub.view.IHandPanel;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class HandPanel extends AbstractStonePanel implements IHandPanel {
|
class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
private final static int HAND_HEIGHT = 2;
|
private int handWidth = 1;
|
||||||
private final static int HAND_WIDTH = 14;
|
private int handHeight = 1;
|
||||||
|
|
||||||
private final static BufferedImage BACKGROUND;
|
private final static BufferedImage BACKGROUND;
|
||||||
static {
|
static {
|
||||||
ImageIcon image = new ImageIcon(
|
ImageIcon image = new ImageIcon(
|
||||||
HandPanel.class.getResource("/jrummikub/resource/wood.png"));
|
HandPanel.class.getResource("/jrummikub/resource/wood.png"));
|
||||||
BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
|
BACKGROUND = new BufferedImage(image.getIconWidth(),
|
||||||
BufferedImage.TYPE_INT_RGB);
|
image.getIconHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
|
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,20 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
|
|
||||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHandWidth(int width) {
|
||||||
|
handWidth = width;
|
||||||
|
rescale();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHandHeight(int height) {
|
||||||
|
handHeight = height;
|
||||||
|
rescale();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Board instance
|
* Creates a new Board instance
|
||||||
*/
|
*/
|
||||||
|
@ -53,15 +67,7 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
Insets insets = getInsets();
|
rescale();
|
||||||
int size = (getHeight() - insets.top - insets.bottom) / HAND_HEIGHT;
|
|
||||||
|
|
||||||
getStonePainter().setScale(size * StonePainter.HEIGHT_SCALE);
|
|
||||||
|
|
||||||
setSize(new Dimension(HAND_WIDTH * getStonePainter().getStoneWidth()
|
|
||||||
+ insets.left + insets.right, getHeight()));
|
|
||||||
|
|
||||||
repaintAll = true;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -82,16 +88,17 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
protected void paintComponent(Graphics g1) {
|
protected void paintComponent(Graphics g1) {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
- insets.right, height = getHeight() - insets.top
|
||||||
|
- insets.bottom;
|
||||||
Graphics2D g = (Graphics2D) g1.create(x, y, width, height);
|
Graphics2D g = (Graphics2D) g1.create(x, y, width, height);
|
||||||
|
|
||||||
int size = height / HAND_HEIGHT;
|
int size = height / handHeight;
|
||||||
|
|
||||||
if (repaintAll) {
|
if (repaintAll) {
|
||||||
if (scaledBackground.getHeight() != size)
|
if (scaledBackground.getHeight() != size)
|
||||||
scaledBackground = getScaledBackground(size);
|
scaledBackground = getScaledBackground(size);
|
||||||
|
|
||||||
for (int i = 0; i < HAND_HEIGHT; ++i) {
|
for (int i = 0; i < handHeight; ++i) {
|
||||||
for (int xpos = -size * i / 3; xpos < width; xpos += size) {
|
for (int xpos = -size * i / 3; xpos < width; xpos += size) {
|
||||||
g.drawImage(scaledBackground, xpos, size * i, null);
|
g.drawImage(scaledBackground, xpos, size * i, null);
|
||||||
}
|
}
|
||||||
|
@ -99,8 +106,10 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Pair<Stone, Position> entry : getStones()) {
|
for (Pair<Stone, Position> entry : getStones()) {
|
||||||
getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(),
|
getStonePainter().paintStone(g, entry.getFirst(),
|
||||||
selectedStones.contains(entry.getFirst()), entry.getFirst() == getHoveredStone());
|
entry.getSecond(),
|
||||||
|
selectedStones.contains(entry.getFirst()),
|
||||||
|
entry.getFirst() == getHoveredStone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,10 +124,22 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
* Sets the stones that are to be painted selected
|
* Sets the stones that are to be painted selected
|
||||||
*
|
*
|
||||||
* @param stones
|
* @param stones
|
||||||
* the selected stones
|
* the selected stones
|
||||||
*/
|
*/
|
||||||
void setSelectedStones(Collection<Stone> stones) {
|
void setSelectedStones(Collection<Stone> stones) {
|
||||||
selectedStones = stones;
|
selectedStones = stones;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rescale() {
|
||||||
|
Insets insets = getInsets();
|
||||||
|
int size = (getHeight() - insets.top - insets.bottom) / handHeight;
|
||||||
|
|
||||||
|
getStonePainter().setScale(size * StonePainter.HEIGHT_SCALE);
|
||||||
|
|
||||||
|
setSize(new Dimension(handWidth * getStonePainter().getStoneWidth()
|
||||||
|
+ insets.left + insets.right, getHeight()));
|
||||||
|
|
||||||
|
repaintAll = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ public class RoundControlTest {
|
||||||
- testGameState.table.getSize(), testGameState.getGameHeap()
|
- testGameState.table.getSize(), testGameState.getGameHeap()
|
||||||
.getSize());
|
.getSize());
|
||||||
for (int i = 0; i < testGameState.getPlayerCount(); i++) {
|
for (int i = 0; i < testGameState.getPlayerCount(); i++) {
|
||||||
assertEquals(14, testGameState.getNthNextPlayer(i).getHand().getSize());
|
assertEquals(14, testGameState.getNthNextPlayer(i).getHand()
|
||||||
|
.getSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +68,8 @@ public class RoundControlTest {
|
||||||
private void checkTableDisplay() {
|
private void checkTableDisplay() {
|
||||||
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets
|
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets
|
||||||
.iterator();
|
.iterator();
|
||||||
Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table.clone().sets
|
Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table
|
||||||
.iterator();
|
.clone().sets.iterator();
|
||||||
|
|
||||||
while (stoneSetsView.hasNext()) {
|
while (stoneSetsView.hasNext()) {
|
||||||
assertTrue(stoneSetsModel.hasNext());
|
assertTrue(stoneSetsModel.hasNext());
|
||||||
|
@ -85,6 +86,17 @@ public class RoundControlTest {
|
||||||
view.displayStartTurnPanel = false;
|
view.displayStartTurnPanel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO hier weitermachen
|
||||||
|
@Test
|
||||||
|
public void testDealStone() {
|
||||||
|
testRound.deal();
|
||||||
|
checkCorrectlyDealed();
|
||||||
|
for (int i = 0; i < 28 - 14; i++) {
|
||||||
|
testRound.dealStone();
|
||||||
|
}
|
||||||
|
assertEquals(28, testGameState.getActivePlayer().getHand().getSize());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeal() {
|
public void testDeal() {
|
||||||
testRound.deal();
|
testRound.deal();
|
||||||
|
@ -136,7 +148,8 @@ public class RoundControlTest {
|
||||||
|
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
assertFalse(view.displayStartTurnPanel);
|
assertFalse(view.displayStartTurnPanel);
|
||||||
Stone stone = testGameState.players.get(0).hand.stones.remove(0).getFirst();
|
Stone stone = testGameState.players.get(0).hand.stones.remove(0)
|
||||||
|
.getFirst();
|
||||||
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
||||||
resetTurnStart();
|
resetTurnStart();
|
||||||
view.getPlayerPanel().endTurnEvent.emit();
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
@ -194,7 +207,8 @@ public class RoundControlTest {
|
||||||
|
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
assertFalse(view.displayStartTurnPanel);
|
assertFalse(view.displayStartTurnPanel);
|
||||||
Stone stone = testGameState.players.get(0).hand.stones.remove(0).getFirst();
|
Stone stone = testGameState.players.get(0).hand.stones.remove(0)
|
||||||
|
.getFirst();
|
||||||
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
||||||
testGameState.players.get(0).hand.stones.clear();
|
testGameState.players.get(0).hand.stones.clear();
|
||||||
resetTurnStart();
|
resetTurnStart();
|
||||||
|
|
Reference in a new issue