Skip to content

Commit

Permalink
Added ZoneView class, made opponent hand use it
Browse files Browse the repository at this point in the history
  • Loading branch information
bazola committed Sep 19, 2014
1 parent 4bb39f5 commit 29aff1a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ public class GameClientController {
@FXML private ListView<String> serverMessages;
@FXML private VBox opponentStatBox;
@FXML private VBox playerStatBox;
@FXML private HBox actionBox;

@FXML private HBox opponentHandPane;
@FXML private HBox opponentBattlefieldPane;
@FXML private Pane opponentDeckPane;
@FXML private HBox playerHandPane;
@FXML private HBox playerBattlefieldPane;
@FXML private Pane playerDeckPane;
@FXML private HBox actionBox;


private final ObjectMapper mapper = new ObjectMapper();
private final BlockingQueue<Message> messages = new LinkedBlockingQueue<>();

Expand All @@ -67,18 +68,22 @@ public class GameClientController {
private int port;

private int gameId;
private int playerId;
private int playerIndex;

private int playerId;
private int opponentId;
private final Map<String, Integer> playerStatBoxMap = new HashMap<>();
private final Map<String, Integer> opponentStatBoxMap = new HashMap<>();

private int opponentHandId;
private int opponentBattlefieldId;
private int opponentDeckId;
private int playerHandId;
private int playerBattlefieldId;
private int playerDeckId;
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 final Map<Integer, ZoneView> zoneViewMap = new HashMap<>();


private int opponentHandSize;

Expand Down Expand Up @@ -209,7 +214,6 @@ private void processMessageFromServer(Message message) {

private void processNewGameMessage(NewGameMessage message) {
this.playerIndex = message.getPlayerIndex();

System.out.println(String.format("You are player: %d", this.playerIndex));
}

Expand Down Expand Up @@ -257,28 +261,34 @@ private void assignZoneIdForZoneMessage(ZoneMessage message) {
if(message.getOwner() == this.playerId) {
this.playerBattlefieldId = message.getId();
this.idMap.put(this.playerBattlefieldId, playerBattlefieldPane);
this.zoneViewMap.put(message.getId(), new ZoneView(message.getId(), playerBattlefieldPane));

} else {
this.opponentBattlefieldId = message.getId();
this.idMap.put(this.opponentBattlefieldId, opponentBattlefieldPane);
this.zoneViewMap.put(message.getId(), new ZoneView(message.getId(), opponentBattlefieldPane));
}
} else if (message.getName().equals("Hand")) {
if (message.getOwner() == this.playerId) {
this.playerHandId = message.getId();
this.idMap.put(this.playerHandId, playerHandPane);
this.zoneViewMap.put(message.getId(), new ZoneView(message.getId(), playerHandPane));
} else {
this.opponentHandId = message.getId();
this.opponentHandSize = message.getSize();
this.idMap.put(this.opponentHandId, opponentHandPane);
this.idMap.put(this.opponentHandId, opponentHandPane); //TO REMOVE

this.renderOpponentHand();
this.zoneViewMap.put(this.opponentHandId, new ZoneView(message.getId(), opponentHandPane));
this.createOpponentHand(message.getSize());
}
} else if (message.getName().equals("Deck")) {
if (message.getOwner() == this.playerId) {
this.playerDeckId = message.getId();
this.idMap.put(this.playerHandId, playerDeckPane);
this.zoneViewMap.put(message.getId(), new ZoneView(message.getId(), playerDeckPane));
} else {
this.opponentDeckId = message.getId();
this.idMap.put(this.opponentHandId, opponentDeckPane);
this.zoneViewMap.put(message.getId(), new ZoneView(message.getId(), opponentDeckPane));
}
}
}
Expand Down Expand Up @@ -348,20 +358,20 @@ private void repaintStatBox(Pane statBox, Map<String, Integer> playerMap) {
}
}

private void renderOpponentHand() {
//Opponent cards are rendered differently because the faces are not visible
private void createOpponentHand(int size) {
double paneHeight = opponentHandPane.getHeight();
double paneWidth = opponentHandPane.getWidth();

int maxCards = 10;
double cardWidth = paneWidth / maxCards;

for (int currentCard = 0; currentCard < this.opponentHandSize; currentCard++) {
Group cardGroup = new Group();

ZoneView opponentHand = this.zoneViewMap.get(this.opponentHandId);
for(int i = 0; i < size; i++) {
Pane card = new Pane();
Rectangle cardBack = new Rectangle(0,0,cardWidth,paneHeight);
cardBack.setFill(Color.AQUAMARINE);
cardGroup.getChildren().add(cardBack);
opponentHandPane.getChildren().add(cardGroup);
card.getChildren().add(cardBack);
opponentHand.addPane(i, card);
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions cardshifter-fx/src/main/java/com/cardshifter/client/ZoneView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.cardshifter.client;

import java.util.HashMap;
import java.util.Map;
import javafx.scene.layout.Pane;

public class ZoneView {

private final int zoneId;
private final Pane rootPane;
private final Map<Integer, Pane> zoneMap = new HashMap<>();

public ZoneView(int zoneId, Pane pane) {
this.zoneId = zoneId;
this.rootPane = pane;
}

public void addPane(int paneId, Pane pane) {
this.zoneMap.put(paneId, pane);
this.rootPane.getChildren().add(pane);
}

public void removePane(int paneId) {
Pane paneToRemove = this.zoneMap.get(paneId);
this.rootPane.getChildren().remove(paneToRemove);
this.zoneMap.remove(paneId);
}

public int getId() {
return this.zoneId;
}

public int getSize() {
return this.zoneMap.size();
}

public Pane getRootPane() {
return this.rootPane;
}

}

0 comments on commit 29aff1a

Please sign in to comment.