summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-09 20:54:17 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-09 20:54:17 +0200
commit050ae5f2247ef073ad92b5ad084a4e3816f35da9 (patch)
tree126c100a4bf8371bfbb2c42adae662419f116dfe /src/jrummikub
parentfffca3fe9a1285dc3a9f009c3431cd907443b7af (diff)
downloadJRummikub-050ae5f2247ef073ad92b5ad084a4e3816f35da9.tar
JRummikub-050ae5f2247ef073ad92b5ad084a4e3816f35da9.zip
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
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/RoundControl.java16
-rw-r--r--src/jrummikub/view/IHandPanel.java18
-rw-r--r--src/jrummikub/view/impl/HandPanel.java59
3 files changed, 63 insertions, 30 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index efa6f62..154fcb9 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -14,6 +14,9 @@ import jrummikub.util.Pair;
import jrummikub.view.IView;
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 IView view;
private ITable clonedTable;
@@ -21,6 +24,8 @@ public class RoundControl {
public RoundControl(IGameState gameState, IView view) {
this.gameState = gameState;
this.view = view;
+ view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT);
+ view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH);
}
public void startRound() {
@@ -68,14 +73,17 @@ public class RoundControl {
for (int i = 0; i < gameState.getPlayerCount(); i++) {
IHand hand = gameState.getNthNextPlayer(i).getHand();
for (int j = 0; j < 7; j++) {
- hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0));
- hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
+ hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
+ 0));
+ hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
+ 1));
}
}
}
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 (clonedTable.isValid()) {
@@ -118,7 +126,7 @@ public class RoundControl {
return ret;
}
- private void dealStone() {
+ void dealStone() {
gameState
.getActivePlayer()
.getHand()
diff --git a/src/jrummikub/view/IHandPanel.java b/src/jrummikub/view/IHandPanel.java
index a58edab..3436062 100644
--- a/src/jrummikub/view/IHandPanel.java
+++ b/src/jrummikub/view/IHandPanel.java
@@ -8,11 +8,15 @@ import jrummikub.util.Pair;
* The view for a player's hand that displays his stones
*/
public interface IHandPanel extends IStonePanel, IClickable {
- /**
- * Set the player's stones to display on the board
- *
- * @param stones
- * the stones
- */
- public void setStones(Iterable<Pair<Stone, Position>> stones);
+ /**
+ * Set the player's stones to display on the board
+ *
+ * @param stones
+ * the stones
+ */
+ public void setStones(Iterable<Pair<Stone, Position>> stones);
+
+ public void setHandWidth(int width);
+
+ public void setHandHeight(int height);
}
diff --git a/src/jrummikub/view/impl/HandPanel.java b/src/jrummikub/view/impl/HandPanel.java
index 38a8440..6ad6270 100644
--- a/src/jrummikub/view/impl/HandPanel.java
+++ b/src/jrummikub/view/impl/HandPanel.java
@@ -25,15 +25,15 @@ import jrummikub.view.IHandPanel;
*/
@SuppressWarnings("serial")
class HandPanel extends AbstractStonePanel implements IHandPanel {
- private final static int HAND_HEIGHT = 2;
- private final static int HAND_WIDTH = 14;
+ private int handWidth = 1;
+ private int handHeight = 1;
private final static BufferedImage BACKGROUND;
static {
ImageIcon image = new ImageIcon(
HandPanel.class.getResource("/jrummikub/resource/wood.png"));
- BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
- BufferedImage.TYPE_INT_RGB);
+ BACKGROUND = new BufferedImage(image.getIconWidth(),
+ image.getIconHeight(), BufferedImage.TYPE_INT_RGB);
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
}
@@ -42,6 +42,20 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
private boolean repaintAll = true;
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
@@ -53,15 +67,7 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
@Override
public void componentResized(ComponentEvent e) {
- Insets insets = getInsets();
- 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;
+ rescale();
}
});
}
@@ -82,16 +88,17 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
protected void paintComponent(Graphics g1) {
Insets insets = getInsets();
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);
- int size = height / HAND_HEIGHT;
+ int size = height / handHeight;
if (repaintAll) {
if (scaledBackground.getHeight() != 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) {
g.drawImage(scaledBackground, xpos, size * i, null);
}
@@ -99,8 +106,10 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
}
for (Pair<Stone, Position> entry : getStones()) {
- getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(),
- selectedStones.contains(entry.getFirst()), entry.getFirst() == getHoveredStone());
+ getStonePainter().paintStone(g, entry.getFirst(),
+ 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
*
* @param stones
- * the selected stones
+ * the selected stones
*/
void setSelectedStones(Collection<Stone> stones) {
selectedStones = stones;
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;
+ }
}