Skip to content

Commit

Permalink
implemented partially working updates, not all values persist
Browse files Browse the repository at this point in the history
  • Loading branch information
bazola committed Sep 18, 2014
1 parent f40b4f1 commit c88f3bb
Showing 1 changed file with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class GameClientController {
private int playerHandId;
private int playerBattlefieldId;
private final Map<Integer, Pane> idMap = new HashMap<>();
private final Map<String, Integer> playerStatBoxMap = new HashMap<>();
private final Map<String, Integer> opponentStatBoxMap = new HashMap<>();

private int opponentHandSize;

Expand Down Expand Up @@ -205,16 +207,17 @@ private void processNewGameMessage(NewGameMessage message) {
private void processPlayerMessage(PlayerMessage message) {
if (message.getIndex() == this.playerIndex) {
this.playerId = message.getId();
this.processPlayerMessageForPlayer(message, playerStatBox);
this.processPlayerMessageForPlayer(message, playerStatBox, playerStatBoxMap);
} else {
this.opponentId = message.getId();
this.processPlayerMessageForPlayer(message, opponentStatBox);
this.processPlayerMessageForPlayer(message, opponentStatBox, opponentStatBoxMap);
}
}
private void processPlayerMessageForPlayer(PlayerMessage message, Pane statBox) {
private void processPlayerMessageForPlayer(PlayerMessage message, Pane statBox, Map playerMap) {
statBox.getChildren().clear();
Map<String, Integer> sortedMap = new TreeMap<>(message.getProperties());
for(Map.Entry<String, Integer> entry : sortedMap.entrySet()) {
playerMap = sortedMap;
for (Map.Entry<String, Integer> entry : sortedMap.entrySet()) {
String key = entry.getKey();
statBox.getChildren().add(new Label(key));
int value = entry.getValue();
Expand Down Expand Up @@ -302,12 +305,29 @@ private void processUseableActionMessage(UseableActionMessage message) {

private void processUpdateMessage(UpdateMessage message) {
if (message.getId() == this.playerId) {
this.processUpdateMessageForPlayer(playerStatBox, message);
this.processUpdateMessageForPlayer(playerStatBox, message, playerStatBoxMap);
} else if (message.getId() == this.opponentId) {
this.processUpdateMessageForPlayer(opponentStatBox, message);
this.processUpdateMessageForPlayer(opponentStatBox, message, opponentStatBoxMap);
}
}
private void processUpdateMessageForPlayer(Pane statBox, UpdateMessage message) {
private void processUpdateMessageForPlayer(Pane statBox, UpdateMessage message, Map playerMap) {
String key = (String)message.getKey();
System.out.println(String.format("The old value = %d", playerMap.get(key)));
Integer value = (Integer)message.getValue();
playerMap.put(key, value);
System.out.println(String.format("new map value = %d", playerMap.get(key)));

this.repaintStatBox(statBox, playerMap);
}

private void repaintStatBox(Pane statBox, Map<String, Integer> playerMap) {
statBox.getChildren().clear();
for (Map.Entry<String, Integer> entry : playerMap.entrySet()) {
String key = entry.getKey();
statBox.getChildren().add(new Label(key));
int value = entry.getValue();
statBox.getChildren().add(new Label(String.format("%d",value)));
}
}

private void renderOpponentHand() {
Expand Down Expand Up @@ -348,5 +368,7 @@ private void renderOpponentHand() {
CardInfo: 52 in zone 46 - {SICKNESS=1, MANA_COST=5, ATTACK=5, HEALTH=5, ATTACK_AVAILABLE=1}
ZoneMessage [id=45, name=Deck, owner=44, size=34, known=false]
com.cardshifter.server.outgoing.ResetAvailableActionsMessage@2d326c35
UpdateMessage [id=44, key=MANA_MAX, value=2]
UpdateMessage [id=44, key=MANA, value=2]
*/

0 comments on commit c88f3bb

Please sign in to comment.