Remove player labels at the table edges
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@283 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
cff3180460
commit
3d74d11974
8 changed files with 89 additions and 193 deletions
|
@ -36,9 +36,9 @@ public class RoundControl {
|
|||
* Create a new RoundControl using the given gameState and view
|
||||
*
|
||||
* @param roundState
|
||||
* initial round state
|
||||
* initial round state
|
||||
* @param view
|
||||
* view used for user interaction
|
||||
* view used for user interaction
|
||||
*/
|
||||
public RoundControl(IRoundState roundState, IView view) {
|
||||
this.roundState = roundState;
|
||||
|
@ -75,14 +75,8 @@ public class RoundControl {
|
|||
clonedTable = (ITable) roundState.getTable().clone();
|
||||
view.enableStartTurnPanel(true);
|
||||
view.getTablePanel().setStoneSets(clonedTable);
|
||||
view.setCurrentPlayerName(roundState.getActivePlayer()
|
||||
.getPlayerSettings().getName());
|
||||
view.getTablePanel().setLeftPlayerName(
|
||||
roundState.getNthNextPlayer(1).getPlayerSettings().getName());
|
||||
view.getTablePanel().setTopPlayerName(
|
||||
roundState.getNthNextPlayer(2).getPlayerSettings().getName());
|
||||
view.getTablePanel().setRightPlayerName(
|
||||
roundState.getNthNextPlayer(3).getPlayerSettings().getName());
|
||||
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
|
||||
.getName());
|
||||
}
|
||||
|
||||
private void startTurn() {
|
||||
|
@ -103,10 +97,8 @@ public class RoundControl {
|
|||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
||||
for (int j = 0; j < 7; j++) {
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(j,
|
||||
0));
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(j,
|
||||
1));
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(j, 0));
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(j, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,8 +113,7 @@ public class RoundControl {
|
|||
}
|
||||
|
||||
return totalValue == 0
|
||||
|| totalValue >= roundState.getGameSettings()
|
||||
.getInitialMeldThreshold();
|
||||
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
|
||||
}
|
||||
|
||||
private void endOfTurn() {
|
||||
|
@ -158,8 +149,7 @@ public class RoundControl {
|
|||
}
|
||||
if (!roundState.getActivePlayer().getLaidOut()) {
|
||||
// Player touched forbidden stones
|
||||
if (!tableSetDifference(clonedTable, roundState.getTable())
|
||||
.isEmpty()) {
|
||||
if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) {
|
||||
rejectMove();
|
||||
return;
|
||||
}
|
||||
|
@ -168,8 +158,7 @@ public class RoundControl {
|
|||
return;
|
||||
}
|
||||
}
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
||||
clonedTable);
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
|
||||
|
||||
roundState.setTable(clonedTable);
|
||||
|
||||
|
@ -185,8 +174,7 @@ public class RoundControl {
|
|||
}
|
||||
|
||||
private void rejectMove() {
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
||||
clonedTable);
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
|
||||
// deal penalty, reset
|
||||
roundState.getGameHeap().putBack(tableDiff);
|
||||
dealPenalty(tableDiff.size());
|
||||
|
@ -258,7 +246,8 @@ public class RoundControl {
|
|||
|
||||
boolean foundRegularWinner = false;
|
||||
int winnerPlayerNumber = 0;
|
||||
Pair<Integer, Integer> bestScore = new Pair<Integer, Integer>(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
Pair<Integer, Integer> bestScore = new Pair<Integer, Integer>(
|
||||
Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
int pointSum = 0;
|
||||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||
IPlayer player = roundState.getNthPlayer(i);
|
||||
|
@ -276,9 +265,9 @@ public class RoundControl {
|
|||
} else {
|
||||
stonePoints = playerHand.getStonePoints();
|
||||
}
|
||||
|
||||
|
||||
bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize());
|
||||
|
||||
|
||||
points.add(-stonePoints);
|
||||
pointSum += stonePoints;
|
||||
}
|
||||
|
@ -287,7 +276,8 @@ public class RoundControl {
|
|||
points.set(winnerPlayerNumber, pointSum);
|
||||
} else {
|
||||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||
if (bestScore.equals(new Pair<Integer, Integer>(points.get(i), roundState.getNthPlayer(i).getHand().getSize()))) {
|
||||
if (bestScore.equals(new Pair<Integer, Integer>(points.get(i),
|
||||
roundState.getNthPlayer(i).getHand().getSize()))) {
|
||||
winners.set(i, true);
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +288,8 @@ public class RoundControl {
|
|||
private static Pair<Integer, Integer> updateBestScore(
|
||||
Pair<Integer, Integer> bestScore, int stonePoints, int size) {
|
||||
if (bestScore.getFirst() == stonePoints) {
|
||||
return new Pair<Integer, Integer>(stonePoints, Math.min(bestScore.getSecond(), size));
|
||||
return new Pair<Integer, Integer>(stonePoints, Math.min(
|
||||
bestScore.getSecond(), size));
|
||||
} else if (bestScore.getFirst() < stonePoints) {
|
||||
return new Pair<Integer, Integer>(stonePoints, size);
|
||||
}
|
||||
|
|
|
@ -9,30 +9,6 @@ import jrummikub.util.Pair;
|
|||
* The view of the table, where the stone sets lie
|
||||
*/
|
||||
public interface ITablePanel extends IStonePanel, IClickable {
|
||||
/**
|
||||
* Sets the player name on the left label
|
||||
*
|
||||
* @param playerName
|
||||
* the name to set
|
||||
*/
|
||||
public void setLeftPlayerName(String playerName);
|
||||
|
||||
/**
|
||||
* Sets the player name on the top label
|
||||
*
|
||||
* @param playerName
|
||||
* the name to set
|
||||
*/
|
||||
public void setTopPlayerName(String playerName);
|
||||
|
||||
/**
|
||||
* Sets the player name on the right label
|
||||
*
|
||||
* @param playerName
|
||||
* the name to set
|
||||
*/
|
||||
public void setRightPlayerName(String playerName);
|
||||
|
||||
/**
|
||||
* Sets the stone sets lying on the table
|
||||
*
|
||||
|
|
|
@ -87,4 +87,11 @@ public interface IView {
|
|||
* @return the event
|
||||
*/
|
||||
IEvent getNewRoundEvent();
|
||||
|
||||
/**
|
||||
* Shows or hides the game settings panel
|
||||
*
|
||||
* @param show specifies if the panel shall be shown or hidden
|
||||
*/
|
||||
void showSettingsPanel(boolean show);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package jrummikub.view.impl;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
|
@ -17,7 +16,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import jrummikub.model.Position;
|
||||
|
@ -49,7 +47,6 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
private final float COLLECTION_RATIO = 0.12f;
|
||||
private final int COLLECTION_GAP = 5;
|
||||
|
||||
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
|
||||
private StoneCollectionPanel stoneCollection;
|
||||
|
||||
private Iterable<Pair<StoneSet, Position>> stoneSets = Collections.emptySet();
|
||||
|
@ -61,21 +58,6 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
private StoneSet leftHoveredConnector;
|
||||
private StoneSet rightHoveredConnector;
|
||||
|
||||
@Override
|
||||
public void setLeftPlayerName(String playerName) {
|
||||
leftPlayerLabel.setText(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopPlayerName(String playerName) {
|
||||
topPlayerLabel.setText(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRightPlayerName(String playerName) {
|
||||
rightPlayerLabel.setText(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event1<StoneSet> getLeftConnectorClickEvent() {
|
||||
return leftConnectorClickEvent;
|
||||
|
@ -124,36 +106,12 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
repaint();
|
||||
}
|
||||
|
||||
private void createLabels() {
|
||||
leftPlayerLabel = new JLabel();
|
||||
leftPlayerLabel.setForeground(Color.WHITE);
|
||||
leftPlayerLabel.setHorizontalAlignment(JLabel.LEFT);
|
||||
leftPlayerLabel.setHorizontalTextPosition(JLabel.LEFT);
|
||||
add(leftPlayerLabel);
|
||||
|
||||
topPlayerLabel = new JLabel();
|
||||
topPlayerLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER);
|
||||
topPlayerLabel.setVerticalAlignment(JLabel.TOP);
|
||||
topPlayerLabel.setVerticalTextPosition(JLabel.TOP);
|
||||
topPlayerLabel.setForeground(Color.WHITE);
|
||||
add(topPlayerLabel);
|
||||
|
||||
rightPlayerLabel = new JLabel();
|
||||
rightPlayerLabel.setForeground(Color.WHITE);
|
||||
rightPlayerLabel.setHorizontalAlignment(JLabel.RIGHT);
|
||||
rightPlayerLabel.setHorizontalTextPosition(JLabel.RIGHT);
|
||||
add(rightPlayerLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Table instance
|
||||
*/
|
||||
TablePanel() {
|
||||
setLayout(null);
|
||||
|
||||
createLabels();
|
||||
|
||||
stoneCollection = new StoneCollectionPanel();
|
||||
stoneCollection.getOtherClickEvent().add(new IListener1<Point>() {
|
||||
|
||||
|
@ -206,10 +164,6 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||
|
||||
leftPlayerLabel.setBounds(x, y, width, height);
|
||||
topPlayerLabel.setBounds(x, y, width, height);
|
||||
rightPlayerLabel.setBounds(x, y, width, height);
|
||||
|
||||
int collectionHeight = (int) (height * COLLECTION_RATIO);
|
||||
stoneCollection
|
||||
.setBounds(x, y + height - collectionHeight - COLLECTION_GAP, width,
|
||||
|
|
|
@ -154,6 +154,11 @@ public class View extends JFrame implements IView {
|
|||
winPanel.setVisible(enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showSettingsPanel(boolean show) {
|
||||
settingsPanel.setVisible(show);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentPlayerName(String playerName) {
|
||||
playerPanel.setCurrentPlayerName(playerName);
|
||||
|
@ -175,5 +180,4 @@ public class View extends JFrame implements IView {
|
|||
public IEvent getFinalScoreEvent() {
|
||||
return winPanel.getFinalScoreEvent();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue