use of com.gianlu.pyxreborn.client.UI.Card.PyxCardGroup in project PretendYoureXyzzyReborn by devgianlu.
the class GameUI method onCardSelected.
@Override
public void onCardSelected(BaseCard card) {
if (Objects.equals(me, judge.user) && game.status == Game.Status.JUDGING) {
JsonObject obj = client.createRequest(Operations.JUDGE);
obj.addProperty(Fields.GID.toString(), game.gid);
obj.addProperty(Fields.CARD_ID.toString(), card.id);
try {
client.sendMessageBlocking(obj);
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
}
} else if (!Objects.equals(me, judge.user) && game.status == Game.Status.PLAYING) {
JsonObject obj = client.createRequest(Operations.PLAY_CARD);
obj.addProperty(Fields.GID.toString(), game.gid);
obj.addProperty(Fields.CARD_ID.toString(), card.id);
try {
client.sendMessageBlocking(obj);
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
for (int i = hand.getChildren().size() - 1; i >= 0; i--) {
Node node = hand.getChildren().get(i);
if (node instanceof PyxCardGroup) {
List<WhiteCard> cards = ((PyxCardGroup) node).cards;
for (WhiteCard c : cards) {
if (c.id == card.id) {
hand.getChildren().remove(i);
break;
}
}
}
}
}
}
use of com.gianlu.pyxreborn.client.UI.Card.PyxCardGroup in project PretendYoureXyzzyReborn by devgianlu.
the class GameUI method onMessage.
@Override
public void onMessage(Events event, JsonObject obj) {
switch(event) {
case GAME_CHAT:
case NEW_GAME:
case NEW_USER:
case GAME_REMOVED:
case USER_LEFT:
case CHAT:
// Not interested
return;
case GAME_NEW_PLAYER:
Platform.runLater(() -> playersList.add(new CPlayer(obj.getAsJsonObject(Fields.PLAYER.toString()))));
break;
case GAME_PLAYER_LEFT:
Platform.runLater(() -> {
CPlayer toRemove = Utils.find(playersList, obj.get(Fields.NICKNAME.toString()).getAsString());
if (toRemove != null)
playersList.remove(toRemove);
});
break;
case GAME_HAND_CHANGED:
List<WhiteCard> whiteCards = Utils.toList(obj.getAsJsonArray(Fields.HAND.toString()), WhiteCard.class);
Platform.runLater(() -> {
this.hand.getChildren().clear();
for (WhiteCard card : whiteCards) this.hand.getChildren().add(new PyxCardGroup(Collections.singletonList(card), this));
});
break;
case GAME_NEW_ROUND:
game.status = Game.Status.PLAYING;
judge = new CPlayer(obj.getAsJsonObject(Fields.JUDGE.toString()));
BlackCard blackCard = new BlackCard(obj.getAsJsonObject(Fields.BLACK_CARD.toString()));
Platform.runLater(() -> {
this.blackCard.getChildren().clear();
this.blackCard.getChildren().add(new PyxCard(blackCard, null));
this.playedCards.getChildren().clear();
if (!isSpectating()) {
if (Objects.equals(judge.user, me)) {
// I am the judge
instructions.setText("You're the Card Czar.");
hand.setDisable(true);
} else {
// I am not the judge
instructions.setText("Pick " + blackCard.numPick + " card(s) to play...");
hand.setDisable(false);
}
} else {
instructions.setText("You're a spectator.");
}
});
break;
case GAME_JUDGING:
game.status = Game.Status.JUDGING;
List<List<WhiteCard>> playedCards = new ArrayList<>();
for (JsonElement element : obj.getAsJsonArray(Fields.PLAYED_CARDS.toString())) playedCards.add(Utils.toList(element.getAsJsonArray(), WhiteCard.class));
Platform.runLater(() -> {
this.hand.getChildren().clear();
this.playedCards.getChildren().clear();
for (List<WhiteCard> cards : playedCards) {
PyxCardGroup group = new PyxCardGroup(cards, this);
this.playedCards.getChildren().add(group);
}
});
break;
case GAME_ROUND_ENDED:
int winningCard = obj.get(Fields.WINNER_CARD_ID.toString()).getAsInt();
CPlayer winner = new CPlayer(obj.getAsJsonObject(Fields.WINNER.toString()));
Platform.runLater(() -> {
instructions.setText(winner.user.nickname + " wins this round!");
for (Node child : this.playedCards.getChildren()) if (child instanceof PyxCardGroup)
for (WhiteCard card : ((PyxCardGroup) child).cards) if (card.id == winningCard)
((PyxCardGroup) child).setWinning();
});
break;
case GAME_STOPPED:
game.status = Game.Status.LOBBY;
Platform.runLater(() -> {
this.blackCard.getChildren().clear();
this.playedCards.getChildren().clear();
this.hand.getChildren().clear();
});
break;
case GAME_OPTIONS_CHANGED:
game.options = new CGame.Options(obj.getAsJsonObject(Fields.OPTIONS.toString()));
break;
case GAME_PLAYER_STATUS_CHANGED:
CPlayer player = new CPlayer(obj.getAsJsonObject(Fields.PLAYER.toString()));
Platform.runLater(() -> {
int index = playersList.indexOf(player);
if (index != -1)
playersList.set(index, player);
});
if (Objects.equals(player.user, me) && player.status == Player.Status.WAITING) {
Platform.runLater(() -> {
if (!isSpectating()) {
instructions.setText("Waiting for other players...");
hand.setDisable(true);
} else {
instructions.setText("You're a spectator.");
}
});
}
break;
}
}
Aggregations