Fixed some comment and metrics warnings

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@552 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-06-21 18:51:23 +02:00
parent 2a553fe6a5
commit d09041304b
8 changed files with 179 additions and 120 deletions

View file

@ -6,7 +6,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
@ -16,7 +15,8 @@ import jrummikub.model.StoneSet;
import jrummikub.util.Pair; import jrummikub.util.Pair;
/** /**
* Logic behind the ai turns * Logic behind the AI turns. Ability to correctly find turns is completly
* tested by the HandTest testcases.
*/ */
public class TurnLogic { public class TurnLogic {
private GameSettings settings; private GameSettings settings;

View file

@ -38,57 +38,7 @@ public class ApplicationControl {
this.view = view; this.view = view;
saveControl = new SaveControl(view); saveControl = new SaveControl(view);
view.getMenuNewGameEvent().add(new IListener() { addQuitGameHandlers();
@Override
public void handle() {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
view.showQuitWarningPanel(true);
tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override
public void handle() {
abortControls();
startApplication();
view.showQuitWarningPanel(false);
tempConnection.remove();
tempConnection = null;
}
});
}
});
view.getQuitEvent().add(new IListener() {
@Override
public void handle() {
if (networkControl != null) {
return;
}
if (gameControl == null) {
System.exit(0);
} else {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS);
view.showQuitWarningPanel(true);
tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override
public void handle() {
System.exit(0);
}
});
}
}
});
view.getQuitWarningPanel().getCancelEvent().add(new IListener() {
@Override
public void handle() {
view.showQuitWarningPanel(false);
if (tempConnection != null) {
tempConnection.remove();
tempConnection = null;
}
}
});
view.getNetworkGameEvent().add(new IListener() { view.getNetworkGameEvent().add(new IListener() {
@Override @Override
@ -118,6 +68,66 @@ public class ApplicationControl {
}); });
} }
private void addQuitGameHandlers() {
view.getMenuNewGameEvent().add(new IListener() {
@Override
public void handle() {
showRestartWarning();
}
});
view.getQuitEvent().add(new IListener() {
@Override
public void handle() {
if (networkControl != null) {
return;
}
if (gameControl == null) {
System.exit(0);
} else {
showQuitWarning();
}
}
});
view.getQuitWarningPanel().getCancelEvent().add(new IListener() {
@Override
public void handle() {
view.showQuitWarningPanel(false);
if (tempConnection != null) {
tempConnection.remove();
tempConnection = null;
}
}
});
}
private void showRestartWarning() {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
view.showQuitWarningPanel(true);
tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override
public void handle() {
abortControls();
startApplication();
view.showQuitWarningPanel(false);
tempConnection.remove();
tempConnection = null;
}
});
}
private void showQuitWarning() {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS);
view.showQuitWarningPanel(true);
tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override
public void handle() {
System.exit(0);
}
});
}
/** /**
* Create a new network login control * Create a new network login control
*/ */

View file

@ -27,7 +27,7 @@ public class LoginControl {
* Constructor for login Control * Constructor for login Control
* *
* @param view * @param view
* for events which need handling * for events which need handling
*/ */
public LoginControl(final IView view) { public LoginControl(final IView view) {
this.view = view; this.view = view;
@ -40,18 +40,21 @@ public class LoginControl {
} }
})); }));
connections.add(view.getLoginPanel().getCancelEvent().add(new IListener() { connections.add(view.getLoginPanel().getCancelEvent()
@Override .add(new IListener() {
public void handle() { @Override
abort(); public void handle() {
cancelEvent.emit(); abort();
} cancelEvent.emit();
})); }
}));
} }
/** /**
* Open Login panel * Open Login panel
* *
* @param reset
* when true resets the information in the login panel
*/ */
public void startLogin(boolean reset) { public void startLogin(boolean reset) {
if (reset) { if (reset) {

View file

@ -44,19 +44,20 @@ public class RoundControl {
/** There are invalid set(s) on the table */ /** There are invalid set(s) on the table */
INVALID_SETS, INVALID_SETS,
/** /**
* The player tried to modify the table without providing the initial meld * The player tried to modify the table without providing the initial
* threshold first * meld threshold first
*/ */
INITIAL_MELD_ERROR, INITIAL_MELD_ERROR,
/** /**
* The player didn't provide enough points for the initial meld threshold * The player didn't provide enough points for the initial meld
* threshold
*/ */
NOT_ENOUGH_POINTS NOT_ENOUGH_POINTS
} }
/** /**
* Table, stone sets and type of an invalid turn to allow a user to track his * Table, stone sets and type of an invalid turn to allow a user to track
* own errors * his own errors
*/ */
public static class InvalidTurnInfo implements Serializable { public static class InvalidTurnInfo implements Serializable {
private static final long serialVersionUID = -3591000741414366776L; private static final long serialVersionUID = -3591000741414366776L;
@ -69,11 +70,11 @@ public class RoundControl {
* Creates new InvalidTurnInfo * Creates new InvalidTurnInfo
* *
* @param table * @param table
* the table after the turn * the table after the turn
* @param type * @param type
* the type of the invalid turn * the type of the invalid turn
* @param invalidSets * @param invalidSets
* the sets causing the turn to be invalid * the sets causing the turn to be invalid
*/ */
public InvalidTurnInfo(ITable table, InvalidTurnType type, public InvalidTurnInfo(ITable table, InvalidTurnType type,
Collection<StoneSet> invalidSets) { Collection<StoneSet> invalidSets) {
@ -119,17 +120,27 @@ public class RoundControl {
protected List<Connection> connections = new ArrayList<Connection>(); protected List<Connection> connections = new ArrayList<Connection>();
private boolean mayPause; private boolean mayPause;
/**
* Create a new RoundControl using the given roundState and view
*
* @param roundState
* initial round state
* @param view
* view used for user interaction
*/
public RoundControl(IRoundState roundState, IView view) { public RoundControl(IRoundState roundState, IView view) {
this(roundState, view, true); this(roundState, view, true);
} }
/** /**
* Create a new RoundControl using the given gameState and view * Create a new RoundControl using the given roundState and view
* *
* @param roundState * @param roundState
* initial round state * initial round state
* @param view * @param view
* view used for user interaction * view used for user interaction
* @param mayPause
* true when players are allowed to pause
*/ */
protected RoundControl(IRoundState roundState, IView view, boolean mayPause) { protected RoundControl(IRoundState roundState, IView view, boolean mayPause) {
this.roundState = roundState; this.roundState = roundState;
@ -205,7 +216,7 @@ public class RoundControl {
* Sets the current round state * Sets the current round state
* *
* @param state * @param state
* to be set * to be set
*/ */
protected void setRoundState(IRoundState state) { protected void setRoundState(IRoundState state) {
roundState = state; roundState = state;
@ -244,11 +255,12 @@ public class RoundControl {
} }
view.getTablePanel().setStoneSets(roundState.getTable().clone()); view.getTablePanel().setStoneSets(roundState.getTable().clone());
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() view.setCurrentPlayerName(roundState.getActivePlayer()
.getName()); .getPlayerSettings().getName());
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() view.setCurrentPlayerColor(roundState.getActivePlayer()
.getColor()); .getPlayerSettings().getColor());
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut()); view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer()
.getLaidOut());
turnControl = createTurnControl(roundState.getActivePlayer() turnControl = createTurnControl(roundState.getActivePlayer()
.getPlayerSettings().getType()); .getPlayerSettings().getType());
@ -284,9 +296,8 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(turnMode); view.getPlayerPanel().setEndTurnMode(turnMode);
} }
turnControl.setup( turnControl.setup(new ITurnControl.TurnInfo(roundState, turnMode,
new ITurnControl.TurnInfo(roundState, turnMode, mayPause), mayPause), roundState.getGameSettings(), view);
roundState.getGameSettings(), view);
turnControl.getEndOfTurnEvent().add( turnControl.getEndOfTurnEvent().add(
new IListener2<IRoundState, InvalidTurnInfo>() { new IListener2<IRoundState, InvalidTurnInfo>() {
@Override @Override
@ -327,7 +338,7 @@ public class RoundControl {
* Override this * Override this
* *
* @param turnControl * @param turnControl
* current turn control * current turn control
*/ */
protected void addTurnControlListeners(ITurnControl turnControl) { protected void addTurnControlListeners(ITurnControl turnControl) {
} }
@ -336,7 +347,7 @@ public class RoundControl {
* Creates new turn control of the specified type * Creates new turn control of the specified type
* *
* @param type * @param type
* of the new turn control * of the new turn control
* @return the new turn control * @return the new turn control
*/ */
protected ITurnControl createTurnControl(Type type) { protected ITurnControl createTurnControl(Type type) {
@ -350,8 +361,10 @@ public class RoundControl {
protected void deal() { protected void deal() {
for (int i = 0; i < roundState.getPlayerCount(); i++) { for (int i = 0; i < roundState.getPlayerCount(); i++) {
IHand hand = roundState.getNthNextPlayer(i).getHand(); IHand hand = roundState.getNthNextPlayer(i).getHand();
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) { for (int j = 0; j < roundState.getGameSettings()
hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0)); .getNumberOfStonesDealt(); j++) {
hand.drop(roundState.getGameHeap().drawStone(), new Position(0,
0));
} }
} }
@ -362,7 +375,7 @@ public class RoundControl {
* End the players turn * End the players turn
* *
* @param invalidTurnInfo * @param invalidTurnInfo
* info about the player's last turn * info about the player's last turn
*/ */
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) { protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
boolean isHuman = roundState.getActivePlayer().getPlayerSettings() boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
@ -380,16 +393,16 @@ public class RoundControl {
view.setInvalidStoneSets(invalidTurnInfo.getInvalidSets()); view.setInvalidStoneSets(invalidTurnInfo.getInvalidSets());
switch (invalidTurnInfo.getType()) { switch (invalidTurnInfo.getType()) {
case INITIAL_MELD_ERROR: case INITIAL_MELD_ERROR:
view.setInitialMeldFirstError(); view.setInitialMeldFirstError();
break; break;
case INVALID_SETS: case INVALID_SETS:
view.setStoneCollectionHidden(true); view.setStoneCollectionHidden(true);
break; break;
case NOT_ENOUGH_POINTS: case NOT_ENOUGH_POINTS:
view.setInitialMeldError(roundState.getGameSettings() view.setInitialMeldError(roundState.getGameSettings()
.getInitialMeldThreshold()); .getInitialMeldThreshold());
break; break;
} }
if (!isHuman) { if (!isHuman) {
@ -399,7 +412,8 @@ public class RoundControl {
} }
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL); view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
view.getPlayerPanel().setTime(roundState.getGameSettings().getTotalTime(), view.getPlayerPanel().setTime(
roundState.getGameSettings().getTotalTime(),
roundState.getGameSettings().getTotalTime()); roundState.getGameSettings().getTotalTime());
nextPlayer(); nextPlayer();
@ -487,10 +501,12 @@ public class RoundControl {
stonePoints = playerHand.isInitialMeldPossible(roundState stonePoints = playerHand.isInitialMeldPossible(roundState
.getGameSettings()) ? 200 : 100; .getGameSettings()) ? 200 : 100;
} else { } else {
stonePoints = playerHand.getStonePoints(roundState.getGameSettings()); stonePoints = playerHand.getStonePoints(roundState
.getGameSettings());
} }
bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize()); bestScore = updateBestScore(bestScore, -stonePoints,
playerHand.getSize());
points.add(-stonePoints); points.add(-stonePoints);
pointSum += stonePoints; pointSum += stonePoints;
@ -514,11 +530,11 @@ public class RoundControl {
* (everybody still has stones on hand) * (everybody still has stones on hand)
* *
* @param bestScore * @param bestScore
* of previous rounds * of previous rounds
* @param stonePoints * @param stonePoints
* sum of points still left on hands * sum of points still left on hands
* @param size * @param size
* number of players in game (= size of score list in columns) * number of players in game (= size of score list in columns)
* @return Pair of maximum points and hand size * @return Pair of maximum points and hand size
*/ */
private static Pair<Integer, Integer> updateBestScore( private static Pair<Integer, Integer> updateBestScore(
@ -542,8 +558,8 @@ public class RoundControl {
} }
/** /**
* Redeal stones and restart round if a player was allowed to redeal and chose * Redeal stones and restart round if a player was allowed to redeal and
* to do so * chose to do so
*/ */
private void redeal() { private void redeal() {
turnControl = null; turnControl = null;

View file

@ -19,12 +19,12 @@ public interface ITurnControl {
* Start the turn * Start the turn
* *
* @param info * @param info
* the current turn state * the current turn state
* *
* @param settings * @param settings
* the game settings * the game settings
* @param view * @param view
* view for user interaction. * view for user interaction.
*/ */
public void setup(TurnInfo info, GameSettings settings, IView view); public void setup(TurnInfo info, GameSettings settings, IView view);
@ -60,7 +60,8 @@ public interface ITurnControl {
public IEvent1<ITable> getTableUpdateEvent(); public IEvent1<ITable> getTableUpdateEvent();
/** /**
* The TurnInfo class encapsulates all information concerning the current turn * The TurnInfo class encapsulates all information concerning the current
* turn
*/ */
public class TurnInfo { public class TurnInfo {
private IRoundState roundState; private IRoundState roundState;
@ -78,12 +79,15 @@ public interface ITurnControl {
/** /**
* Creates a new TurnInfo instance * Creates a new TurnInfo instance
* *
* @param hasLaidOut * @param roundState
* has the player laid out yet? * current round state
* @param turnMode * @param turnMode
* the turn mode * the turn mode
* @param mayPause
* player is allowed to paues
*/ */
public TurnInfo(IRoundState roundState, TurnMode turnMode, boolean mayPause) { public TurnInfo(IRoundState roundState, TurnMode turnMode,
boolean mayPause) {
this.roundState = roundState; this.roundState = roundState;
oldTable = roundState.getTable(); oldTable = roundState.getTable();
@ -97,6 +101,11 @@ public interface ITurnControl {
this.mayPause = mayPause; this.mayPause = mayPause;
} }
/**
* Get the current round state
*
* @return the current round state
*/
public IRoundState getRoundState() { public IRoundState getRoundState() {
return roundState; return roundState;
} }
@ -155,6 +164,11 @@ public interface ITurnControl {
return turnMode; return turnMode;
} }
/**
* Return whether pausing is allowed during this turn
*
* @return true if pause is allowed
*/
public boolean isMayPause() { public boolean isMayPause() {
return mayPause; return mayPause;
} }

View file

@ -1,6 +1,5 @@
package jrummikub.server; package jrummikub.server;
import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import org.apache.vysper.mina.TCPEndpoint; import org.apache.vysper.mina.TCPEndpoint;
@ -13,7 +12,9 @@ import org.apache.vysper.xmpp.modules.extension.xep0045_muc.storage.InMemoryRoom
import org.apache.vysper.xmpp.modules.roster.persistence.MemoryRosterManager; import org.apache.vysper.xmpp.modules.roster.persistence.MemoryRosterManager;
import org.apache.vysper.xmpp.server.XMPPServer; import org.apache.vysper.xmpp.server.XMPPServer;
@SuppressWarnings("deprecation") /**
* Implements a simple XMPP server with a global server password
*/
public class DedicatedServer { public class DedicatedServer {
String serverPassword; String serverPassword;
String hostName; String hostName;
@ -44,6 +45,12 @@ public class DedicatedServer {
return hostName; return hostName;
} }
/**
* Start the server, this blocks
*
* @throws Exception
* when there is an error during startup
*/
public void start() throws Exception { public void start() throws Exception {
XMPPServer server = new XMPPServer(hostName); XMPPServer server = new XMPPServer(hostName);
@ -67,6 +74,9 @@ public class DedicatedServer {
} }
/**
* Allow authorization using a single password for all users
*/
public class ServerPasswordAuthorization implements UserAuthorization { public class ServerPasswordAuthorization implements UserAuthorization {
@Override @Override
public boolean verifyCredentials(Entity entity, String password, public boolean verifyCredentials(Entity entity, String password,
@ -81,9 +91,16 @@ public class DedicatedServer {
} }
} }
/**
* Main for a simple command line dedicated server
*
* @param args
* first argument specifies the server password, it is "jrummikub"
* when none is specified
*/
public static void main(String[] args) { public static void main(String[] args) {
DedicatedServer server = new DedicatedServer(args.length >= 1 ? args[0]
DedicatedServer server = new DedicatedServer("password"); : "jrummikub");
System.out.println("Server hostname is " + server.getHostName()); System.out.println("Server hostname is " + server.getHostName());
try { try {
server.start(); server.start();

View file

@ -221,6 +221,9 @@ public interface IView {
*/ */
public void showLoginPanel(boolean show); public void showLoginPanel(boolean show);
/**
* Clears user input of the resetLoginPanel
*/
public void resetLoginPanel(); public void resetLoginPanel();
/** /**

View file

@ -369,10 +369,6 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
g.setClip(oldClip); g.setClip(oldClip);
if (leftHoveredConnector == null && rightHoveredConnector == null) {
return; // We're done here...
}
g.translate(translation.getFirst(), translation.getSecond()); g.translate(translation.getFirst(), translation.getSecond());
g.setClip(hoveredConnectorArea); g.setClip(hoveredConnectorArea);
g.setTransform(oldTransform); g.setTransform(oldTransform);