Kommentare und kleinere Umbauten
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@426 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
570187c950
commit
f5a05f2c8d
12 changed files with 231 additions and 70 deletions
|
@ -35,9 +35,9 @@ public class SettingsControl {
|
|||
* Create a new settings control
|
||||
*
|
||||
* @param view
|
||||
* the view to use
|
||||
* the view to use
|
||||
* @param settings
|
||||
* initial game settings
|
||||
* initial game settings
|
||||
*/
|
||||
public SettingsControl(IView view, GameSettings settings) {
|
||||
this.view = view;
|
||||
|
@ -71,8 +71,8 @@ public class SettingsControl {
|
|||
}
|
||||
|
||||
/**
|
||||
* the start game event is emitted when the user wants to start a game and the
|
||||
* settings made are valid
|
||||
* the start game event is emitted when the user wants to start a game and
|
||||
* the settings made are valid
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
|
@ -89,7 +89,8 @@ public class SettingsControl {
|
|||
|
||||
private void addOptionListeners1() {
|
||||
connections.add(view.getSettingsPanel()
|
||||
.getChangeInitialMeldThresholdEvent().add(new IListener1<Integer>() {
|
||||
.getChangeInitialMeldThresholdEvent()
|
||||
.add(new IListener1<Integer>() {
|
||||
@Override
|
||||
public void handle(Integer value) {
|
||||
settings.setInitialMeldThreshold(value);
|
||||
|
@ -114,7 +115,8 @@ public class SettingsControl {
|
|||
update();
|
||||
}
|
||||
}));
|
||||
connections.add(view.getSettingsPanel().getChangeNumberOfStonesDealtEvent()
|
||||
connections.add(view.getSettingsPanel()
|
||||
.getChangeNumberOfStonesDealtEvent()
|
||||
.add(new IListener1<Integer>() {
|
||||
@Override
|
||||
public void handle(Integer value) {
|
||||
|
@ -303,8 +305,9 @@ public class SettingsControl {
|
|||
view.getSettingsPanel().enableRemovePlayerButtons(
|
||||
Collections.nCopies(settings.getPlayerList().size(),
|
||||
enableRemoveButtons));
|
||||
view.getSettingsPanel().enableAddPlayerButton(
|
||||
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
|
||||
view.getSettingsPanel()
|
||||
.enableAddPlayerButton(
|
||||
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
|
||||
|
||||
checkSettings();
|
||||
|
||||
|
@ -317,6 +320,9 @@ public class SettingsControl {
|
|||
}
|
||||
|
||||
protected boolean checkSettings() {
|
||||
if (!checkName()) {
|
||||
return false;
|
||||
}
|
||||
if (!checkErrors()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -329,7 +335,7 @@ public class SettingsControl {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean checkErrors() {
|
||||
private boolean checkName() {
|
||||
for (PlayerSettings player : settings.getPlayerList()) {
|
||||
if (player.getName().isEmpty()) {
|
||||
view.getSettingsPanel().setError(
|
||||
|
@ -350,17 +356,22 @@ public class SettingsControl {
|
|||
for (int j = i + 1; j < settings.getPlayerList().size(); ++j) {
|
||||
PlayerSettings player2 = settings.getPlayerList().get(j);
|
||||
if (player2.getName().equals(name) && player2.getType() == type) {
|
||||
view.getSettingsPanel().setError(
|
||||
ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR);
|
||||
view.getSettingsPanel()
|
||||
.setError(
|
||||
ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR);
|
||||
view.getSettingsPanel().enableStartGameButton(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkErrors() {
|
||||
int totalStonesDealt = settings.getNumberOfStonesDealt()
|
||||
* settings.getPlayerList().size();
|
||||
int totalStones = settings.getHighestValue() * settings.getStoneSetNumber()
|
||||
int totalStones = settings.getHighestValue()
|
||||
* settings.getStoneSetNumber()
|
||||
* settings.getStoneColors().size() + settings.getJokerNumber();
|
||||
|
||||
if (totalStones <= totalStonesDealt) {
|
||||
|
|
|
@ -7,10 +7,10 @@ import javax.swing.SwingUtilities;
|
|||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.Event1;
|
||||
import jrummikub.util.GameData;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.util.IEvent1;
|
||||
import jrummikub.util.LoginData;
|
||||
import jrummikub.view.IGameListPanel.GameData;
|
||||
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
|
|
|
@ -9,12 +9,11 @@ import java.util.UUID;
|
|||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.util.Connection;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.GameData;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.IListener1;
|
||||
import jrummikub.util.LoginData;
|
||||
import jrummikub.view.IGameListPanel;
|
||||
import jrummikub.view.IGameListPanel.GameData;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
/**
|
||||
|
@ -45,7 +44,7 @@ public class NetworkControl {
|
|||
addConnectionControlListeners(loginData, view);
|
||||
|
||||
connections.add(view.getGameListPanel().getJoinEvent()
|
||||
.add(new IListener1<IGameListPanel.GameData>() {
|
||||
.add(new IListener1<GameData>() {
|
||||
@Override
|
||||
public void handle(GameData value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -107,7 +106,7 @@ public class NetworkControl {
|
|||
}));
|
||||
|
||||
connections.add(connectionControl.getGameOfferEvent().add(
|
||||
new IListener1<IGameListPanel.GameData>() {
|
||||
new IListener1<GameData>() {
|
||||
@Override
|
||||
public void handle(GameData value) {
|
||||
GameData game = gameMap.get(value.getGameID());
|
||||
|
|
|
@ -21,12 +21,12 @@ public class NetworkSettingsControl extends SettingsControl {
|
|||
/**
|
||||
* Creates a new network settings control
|
||||
*
|
||||
* @param connectionControl
|
||||
* for gameOffers
|
||||
* @param nickname
|
||||
* to be set as player name
|
||||
* @param view
|
||||
* for events and handlers
|
||||
* for events and handlers
|
||||
* @param settings
|
||||
* for playerNumber, color...
|
||||
* for playerNumber, color...
|
||||
*/
|
||||
public NetworkSettingsControl(String nickname, IView view,
|
||||
GameSettings settings) {
|
||||
|
@ -45,8 +45,9 @@ public class NetworkSettingsControl extends SettingsControl {
|
|||
|
||||
@Override
|
||||
protected void update() {
|
||||
view.getSettingsPanel().enableAddPlayerButton(
|
||||
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
|
||||
view.getSettingsPanel()
|
||||
.enableAddPlayerButton(
|
||||
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
|
||||
|
||||
checkSettings();
|
||||
|
||||
|
|
Reference in a new issue