Fix many comments, fix tests, fix complexity
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@462 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
823ef9d4fe
commit
bc835d499f
8 changed files with 265 additions and 101 deletions
|
@ -228,10 +228,12 @@ public class RoundControl {
|
|||
} else {
|
||||
List<Stone> markedStones = new ArrayList<Stone>();
|
||||
for (Pair<StoneSet, Position> set : clonedTable) {
|
||||
if (!set.getFirst().isValid(roundState.getGameSettings())) {
|
||||
for (Stone stone : set.getFirst()) {
|
||||
markedStones.add(stone);
|
||||
}
|
||||
if (set.getFirst().isValid(roundState.getGameSettings())) {
|
||||
continue;
|
||||
}
|
||||
for (Stone stone : set.getFirst()) {
|
||||
markedStones.add(stone);
|
||||
|
||||
}
|
||||
}
|
||||
view.setStoneCollectionHidden(true);
|
||||
|
@ -401,8 +403,8 @@ public class RoundControl {
|
|||
.getGameSettings());
|
||||
}
|
||||
|
||||
bestScore = updateBestScore(bestScore, -stonePoints,
|
||||
playerHand.getSize());
|
||||
bestScore = updateBestScore(bestScore, -stonePoints, playerHand
|
||||
.getSize());
|
||||
|
||||
points.add(-stonePoints);
|
||||
pointSum += stonePoints;
|
||||
|
@ -424,8 +426,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);
|
||||
}
|
||||
|
|
|
@ -299,6 +299,11 @@ class ConnectionControl implements IConnectionControl {
|
|||
|
||||
String messageType = extension.getValue("messageType");
|
||||
|
||||
handleMessageTypes(extension, sender, messageType);
|
||||
}
|
||||
|
||||
private void handleMessageTypes(DefaultPacketExtension extension,
|
||||
String sender, String messageType) {
|
||||
if (messageType.equals("game_offer")) {
|
||||
UUID uuid = UUID.fromString(extension.getValue("uuid"));
|
||||
GameSettings settings = (GameSettings) Base64
|
||||
|
|
|
@ -10,8 +10,21 @@ import jrummikub.util.IListener1;
|
|||
import jrummikub.view.ISettingsPanel.SettingsMode;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
/**
|
||||
* Control for joining a network game
|
||||
*/
|
||||
public class GameJoinControl extends AbstractGameBeginControl {
|
||||
|
||||
/**
|
||||
* Creates new game join control
|
||||
*
|
||||
* @param connectionControl
|
||||
* the current connection control for events and messages
|
||||
* @param gameData
|
||||
* the game data for settings, game id
|
||||
* @param view
|
||||
* the view
|
||||
*/
|
||||
public GameJoinControl(final IConnectionControl connectionControl,
|
||||
final GameData gameData, final IView view) {
|
||||
super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN);
|
||||
|
@ -54,6 +67,9 @@ public class GameJoinControl extends AbstractGameBeginControl {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the join control and sets the settings panel in game join mode
|
||||
*/
|
||||
public void startGameJoin() {
|
||||
view.showSettingsPanel(true);
|
||||
}
|
||||
|
|
|
@ -11,8 +11,21 @@ import jrummikub.util.IListener1;
|
|||
import jrummikub.view.ISettingsPanel.SettingsMode;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
/**
|
||||
* Control for network game host
|
||||
*/
|
||||
public class GameOfferControl extends AbstractGameBeginControl {
|
||||
|
||||
/**
|
||||
* Creates new game offer control
|
||||
*
|
||||
* @param connectionControl
|
||||
* for events (listening and handling)
|
||||
* @param settings
|
||||
* the game settings for player list, colors, names
|
||||
* @param view
|
||||
* the view
|
||||
*/
|
||||
public GameOfferControl(final IConnectionControl connectionControl,
|
||||
final GameSettings settings, final IView view) {
|
||||
super(connectionControl, view,
|
||||
|
@ -57,6 +70,10 @@ public class GameOfferControl extends AbstractGameBeginControl {
|
|||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* sends the game offer and starts the settings panel for host using network
|
||||
* offer type
|
||||
*/
|
||||
public void startGameOffer() {
|
||||
connectionControl.offerGame(gameData);
|
||||
|
||||
|
|
|
@ -44,26 +44,27 @@ public class NetworkControl {
|
|||
this.view = view;
|
||||
connectionControl = new ConnectionControl(loginData);
|
||||
|
||||
addConnectionSetupListeners(loginData, view);
|
||||
addConnectionControlListeners(loginData, view);
|
||||
|
||||
connections.add(view.getGameListPanel().getJoinEvent()
|
||||
.add(new IListener1<GameData>() {
|
||||
connections.add(view.getGameListPanel().getJoinEvent().add(
|
||||
new IListener1<GameData>() {
|
||||
@Override
|
||||
public void handle(GameData gameData) {
|
||||
join(gameData);
|
||||
}
|
||||
}));
|
||||
|
||||
connections.add(view.getGameListPanel().getOpenNewGameEvent()
|
||||
.add(new IListener() {
|
||||
connections.add(view.getGameListPanel().getOpenNewGameEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
createSettingsControl();
|
||||
}
|
||||
}));
|
||||
|
||||
connections.add(view.getGameListPanel().getCancelEvent()
|
||||
.add(new IListener() {
|
||||
connections.add(view.getGameListPanel().getCancelEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
abort();
|
||||
|
@ -87,25 +88,6 @@ public class NetworkControl {
|
|||
*/
|
||||
public void addConnectionControlListeners(final LoginData loginData,
|
||||
final IView view) {
|
||||
connections.add(connectionControl.getConnectedEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
view.getGameListPanel().setChannelName(
|
||||
loginData.getChannelName());
|
||||
view.showGameListPanel(true);
|
||||
}
|
||||
}));
|
||||
|
||||
connections.add(connectionControl.getConnectionFailedEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}));
|
||||
|
||||
connections.add(connectionControl.getGameOfferEvent().add(
|
||||
new IListener1<GameData>() {
|
||||
@Override
|
||||
|
@ -149,6 +131,28 @@ public class NetworkControl {
|
|||
}));
|
||||
}
|
||||
|
||||
private void addConnectionSetupListeners(final LoginData loginData,
|
||||
final IView view) {
|
||||
connections.add(connectionControl.getConnectedEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
view.getGameListPanel().setChannelName(
|
||||
loginData.getChannelName());
|
||||
view.showGameListPanel(true);
|
||||
}
|
||||
}));
|
||||
|
||||
connections.add(connectionControl.getConnectionFailedEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void updateGameList() {
|
||||
List<GameData> gameList = new ArrayList<GameData>();
|
||||
|
||||
|
@ -220,8 +224,8 @@ public class NetworkControl {
|
|||
}
|
||||
view.showGameListPanel(false);
|
||||
|
||||
settingsControl = new NetworkSettingsControl(
|
||||
connectionControl.getNickname(), view, new GameSettings());
|
||||
settingsControl = new NetworkSettingsControl(connectionControl
|
||||
.getNickname(), view, new GameSettings());
|
||||
settingsControl.getOfferGameEvent().add(new IListener1<GameSettings>() {
|
||||
@Override
|
||||
public void handle(GameSettings settings) {
|
||||
|
|
Reference in a new issue