Jonah Bauer 3 years ago
parent 7c3fa7d0d6
commit d5bece96d1

@ -105,13 +105,22 @@ public class CardActor extends Actor {
private TextureRegion background; private TextureRegion background;
private TextureRegion border; private TextureRegion border;
public CardActor(Card card, TextureAtlas atlas) { private CardActor(TextureAtlas atlas) {
this.atlas = atlas; this.atlas = atlas;
setCard(card); this.border = atlas.findRegion(GameAtlas.CARDS_BORDER2);
setWidth(PREF_WIDTH); setWidth(PREF_WIDTH);
setHeight(PREF_HEIGHT); setHeight(PREF_HEIGHT);
setColor(0.8f, 0.8f, 0.8f, 1.0f); setColor(0.8f, 0.8f, 0.8f, 1.0f);
border = atlas.findRegion(GameAtlas.CARDS_BORDER2); }
public CardActor(Card card, TextureAtlas atlas) {
this(atlas);
setCard(card);
}
public CardActor(Card.Suit suit, TextureAtlas atlas) {
this(atlas);
setCard(suit);
} }
public void setCard(Card card) { public void setCard(Card card) {
@ -119,6 +128,18 @@ public class CardActor extends Actor {
this.background = atlas.findRegion(ATLAS_PATHS.get(card)); this.background = atlas.findRegion(ATLAS_PATHS.get(card));
} }
public void setCard(Card.Suit suit) {
this.card = null;
// TODO more appropriate images
this.background = atlas.findRegion(ATLAS_PATHS.get(switch (suit) {
case NONE -> Card.HIDDEN;
case GREEN -> Card.GREEN_1;
case YELLOW -> Card.YELLOW_1;
case BLUE -> Card.BLUE_1;
case RED -> Card.RED_1;
}));
}
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
var color = getColor(); var color = getColor();

@ -0,0 +1,29 @@
package eu.jonahbauer.wizard.client.libgdx.actors.game.overlay;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.model.Card;
public class ChangePredictionOverlay extends MakePredictionOverlay {
public ChangePredictionOverlay(GameScreen gameScreen, int round, int oldPrediction) {
super(
gameScreen,
oldPrediction == 0 ? new int[] {oldPrediction + 1}
: oldPrediction == round + 1 ? new int[] {oldPrediction - 1}
: new int[] {oldPrediction - 1, oldPrediction + 1}
);
}
@Override
public VerticalGroup createContent() {
var root = super.createContent();
var card = new CardActor(Card.CLOUD, atlas);
root.addActorAt(0, card);
root.padTop(- CardActor.PREF_HEIGHT);
return root;
}
}

@ -0,0 +1,65 @@
package eu.jonahbauer.wizard.client.libgdx.actors.game.overlay;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import java.util.stream.IntStream;
public class MakePredictionOverlay extends Overlay {
private final int[] values;
private final TextButton[] buttons;
public MakePredictionOverlay(GameScreen gameScreen, int round) {
this(gameScreen, IntStream.range(0, round + 2).toArray());
}
protected MakePredictionOverlay(GameScreen gameScreen, int[] values) {
super(gameScreen);
this.values = values;
this.buttons = new TextButton[values.length];
}
@Override
public VerticalGroup createContent() {
var root = new VerticalGroup().columnCenter().space(10);
var prompt = new Label("Please make your prediction:", data.skin);
var buttonGroup = new HorizontalGroup().space(20);
for (int i = 0; i < values.length; i++) {
buttons[i] = new TextButton(String.valueOf(i), data.skin);
buttonGroup.addActor(buttons[i]);
}
buttonGroup.addListener(new ClickListener() {
private boolean finished = false;
@Override
public void clicked(InputEvent event, float x, float y) {
if (finished) return;
finished = true;
var target = event.getTarget();
for (int i = 0; i < values.length; i++) {
if (buttons[i] == target) {
System.out.println(values[i]);
break;
}
}
getRoot().remove();
}
});
root.addActor(prompt);
root.addActor(buttonGroup);
return root;
}
}

@ -0,0 +1,43 @@
package eu.jonahbauer.wizard.client.libgdx.actors.game.overlay;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
public abstract class Overlay {
protected final MenuScreen.Data data;
protected final TextureAtlas atlas;
private Container<?> root;
private final Drawable background;
public Overlay(GameScreen gameScreen) {
this.data = gameScreen.getData();
this.atlas = gameScreen.getAtlas();
this.background = gameScreen.getOverlay();
}
protected abstract Actor createContent();
protected Container<?> getRoot() {
if (root == null) {
root = new Container<>(createContent());
root.setBackground(background);
root.setSize(WizardGame.WIDTH, WizardGame.HEIGHT);
root.setTouchable(Touchable.enabled);
}
return root;
}
public void show(Stage stage) {
stage.addActor(getRoot());
}
}

@ -0,0 +1,69 @@
package eu.jonahbauer.wizard.client.libgdx.actors.game.overlay;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.model.Card;
import java.util.EnumMap;
public class PickTrumpOverlay extends Overlay {
private final boolean allowNone;
private final EnumMap<Card.Suit, CardActor> cards = new EnumMap<>(Card.Suit.class);
public PickTrumpOverlay(GameScreen gameScreen, boolean allowNone) {
super(gameScreen);
this.allowNone = allowNone;
}
@Override
public Actor createContent() {
var root = new VerticalGroup().columnCenter().space(10);
var prompt = new Label("Please choose the trump suit:", data.skin);
var cardGroup = new HorizontalGroup().space(20);
cards.put(Card.Suit.RED, new CardActor(Card.Suit.RED, atlas));
cards.put(Card.Suit.GREEN, new CardActor(Card.Suit.GREEN, atlas));
cards.put(Card.Suit.BLUE, new CardActor(Card.Suit.BLUE, atlas));
cards.put(Card.Suit.YELLOW, new CardActor(Card.Suit.YELLOW, atlas));
if (allowNone) {
cards.put(Card.Suit.NONE, new CardActor(Card.Suit.NONE, atlas));
}
cards.values().forEach(cardGroup::addActor);
cardGroup.addListener(new ClickListener() {
private boolean finished = false;
@Override
public void clicked(InputEvent event, float x, float y) {
if (finished) return;
finished = true;
var target = event.getTarget();
for (Card.Suit suit : Card.Suit.values()) {
if (cards.get(suit) == target) {
// TODO
System.out.println(suit);
break;
}
}
getRoot().remove();
}
});
root.addActor(prompt);
root.addActor(cardGroup);
return root;
}
}

@ -0,0 +1,43 @@
package eu.jonahbauer.wizard.client.libgdx.actors.game.overlay;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import static eu.jonahbauer.wizard.client.libgdx.actions.MyActions.*;
public class StartRoundOverlay extends Overlay {
private final int round;
public StartRoundOverlay(GameScreen gameScreen, int round) {
super(gameScreen);
this.round = round;
}
@Override
public Actor createContent() {
var root = new VerticalGroup().columnCenter().space(10f);
var label = new Label("Round " + (round + 1), data.skin, "enchanted");
label.setFontScale(1.5f);
root.addActor(label);
return root;
}
@Override
public void show(Stage stage) {
var root = getRoot();
stage.addActor(root);
stage.addAction(sequence(
delay(2.0f),
target(alpha(0.0f, .1f, Interpolation.pow2Out), root),
removeActor(root)
));
}
}

@ -0,0 +1,87 @@
package eu.jonahbauer.wizard.client.libgdx.actors.game.overlay;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.model.Card;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import static eu.jonahbauer.wizard.client.libgdx.actions.MyActions.*;
public class TrumpOverlay extends Overlay {
private final String player;
private final Card card;
private final Card.Suit suit;
private final CardActor trumpCardActor;
public TrumpOverlay(GameScreen gameScreen, String player, Card card, Card.Suit suit) {
super(gameScreen);
this.player = player;
this.card = card;
this.suit = suit;
this.trumpCardActor = gameScreen.getTrumpCardActor();
}
@Override
public Actor createContent() {
var root = new VerticalGroup().columnCenter().space(10f);
String text;
if (player == null) {
text = switch (suit) {
case YELLOW -> "The trump suit is [#ffff00]yellow[#ffffff].";
case GREEN -> "The trump suit is [#00ff00]green[#ffffff].";
case BLUE -> "The trump suit is [#0000ff]blue[#ffffff].";
case RED -> "The trump suit is [#ff0000]red[#ffffff].";
default -> "There is no trump suit.";
};
} else {
text = player + switch (suit) {
case YELLOW -> " chose the trump suit [#ffff00]yellow[#ffffff].";
case GREEN -> " chose the trump suit [#00ff00]green[#ffffff].";
case BLUE -> " chose the trump suit [#0000ff]blue[#ffffff].";
case RED -> " chose the trump suit [#ff0000]red[#ffffff].";
default -> " has decided there will be no trump suit this round.";
};
}
var label = new Label(text, data.skin);
label.getStyle().font.getData().markupEnabled = true;
label.setFontScale(1.5f);
root.addActor(label);
root.addActor(trumpCardActor);
return root;
}
@Override
public void show(Stage stage) {
var root = getRoot();
trumpCardActor.setCard(card);
stage.addActor(root);
stage.addAction(sequence(
delay(2.0f),
parallel(
sequence(
target(alpha(0.0f, .1f, Interpolation.pow2Out), root),
removeActor(root)
),
sequence(
removeActorSilently(trumpCardActor),
target(changeParent(stage.getRoot()), trumpCardActor),
target(moveTo(10, 10, .25f), trumpCardActor)
)
)
));
}
}

@ -3,7 +3,6 @@ package eu.jonahbauer.wizard.client.libgdx.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.Touchable;
@ -22,7 +21,7 @@ import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardStack; import eu.jonahbauer.wizard.client.libgdx.actors.game.CardStack;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardsGroup; import eu.jonahbauer.wizard.client.libgdx.actors.game.CardsGroup;
import eu.jonahbauer.wizard.client.libgdx.actors.game.PadOfTruth; import eu.jonahbauer.wizard.client.libgdx.actors.game.PadOfTruth;
import eu.jonahbauer.wizard.client.libgdx.screens.eventscreens.*; import eu.jonahbauer.wizard.client.libgdx.actors.game.overlay.*;
import eu.jonahbauer.wizard.client.libgdx.util.Pair; import eu.jonahbauer.wizard.client.libgdx.util.Pair;
import eu.jonahbauer.wizard.common.messages.observer.*; import eu.jonahbauer.wizard.common.messages.observer.*;
import eu.jonahbauer.wizard.common.messages.server.GameMessage; import eu.jonahbauer.wizard.common.messages.server.GameMessage;
@ -39,22 +38,24 @@ import static eu.jonahbauer.wizard.client.libgdx.actions.MyActions.*;
public class GameScreen extends MenuScreen { public class GameScreen extends MenuScreen {
private final WizardGame game; private final WizardGame game;
@Getter
private TextureAtlas atlas; private TextureAtlas atlas;
@Getter
private Drawable overlay; private Drawable overlay;
private final List<UUID> players; private final List<UUID> players;
protected final UUID self; private final UUID self;
private final UUID session; private final UUID session;
private final Map<UUID, String> names; private final Map<UUID, String> names;
private final Map<Integer, Map<UUID, Integer>> scores = new HashMap<>(); private final Map<Integer, Map<UUID, Integer>> scores = new HashMap<>();
private int round = -1; private int round = -1;
private final Map<UUID, List<Card>> hands = new HashMap<>(); private final Map<UUID, List<Card>> hands = new HashMap<>();
protected final Map<UUID, Integer> predictions = new HashMap<>(); private final Map<UUID, Integer> predictions = new HashMap<>();
private final Map<UUID, List<List<Card>>> tricks = new HashMap<>(); private final Map<UUID, List<List<Card>>> tricks = new HashMap<>();
private Card.Suit trumpSuit; private Card.Suit trumpSuit;
protected Card trumpCard; private Card trumpCard;
private int trick = -1; private int trick = -1;
private final List<Pair<UUID, Card>> stack = new ArrayList<>(); private final List<Pair<UUID, Card>> stack = new ArrayList<>();
@ -63,11 +64,12 @@ public class GameScreen extends MenuScreen {
private CardsGroup handCards; private CardsGroup handCards;
private CardStack cardStack; private CardStack cardStack;
private PadOfTruth padOfTruth; private PadOfTruth padOfTruth;
protected CardActor trumpCardActor; @Getter
private CardActor trumpCardActor;
private VerticalGroup messages; private VerticalGroup messages;
private Map<UUID, Seat> seats = new HashMap<>(); private final Map<UUID, Seat> seats = new HashMap<>();
private Map<UUID, Label> nameLabels = new HashMap<>(); private final Map<UUID, Label> nameLabels = new HashMap<>();
public GameScreen(WizardGame game) { public GameScreen(WizardGame game) {
this(game, null); this(game, null);
@ -167,12 +169,12 @@ public class GameScreen extends MenuScreen {
} }
}); });
var roundButton = new TextButton("Round", data.skin, "simple"); var round = new TextButton("Round", data.skin, "simple");
roundButton.addListener(new ChangeListener() { round.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
onMessage(new GameMessage(new StateMessage("starting_round"))); onMessage(new GameMessage(new StateMessage("starting_round")));
roundButton.setText("Round " + GameScreen.this.round); round.setText("Round " + GameScreen.this.round);
} }
}); });
@ -185,8 +187,8 @@ public class GameScreen extends MenuScreen {
} }
}); });
var predictionsLocale = new TextButton("Predictions", data.skin, "simple"); var predictions = new TextButton("Predictions", data.skin, "simple");
predictionsLocale.addListener(new ChangeListener() { predictions.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
players.forEach(player -> onMessage(new GameMessage(new PredictionMessage(player, (int) (Math.random() * 5))))); players.forEach(player -> onMessage(new GameMessage(new PredictionMessage(player, (int) (Math.random() * 5)))));
@ -206,28 +208,11 @@ public class GameScreen extends MenuScreen {
} }
}); });
var chosenTrumpByOther = new TextButton("Chosen Trump By Other", data.skin, "simple");
chosenTrumpByOther.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
UUID player;
do {
player = players.get((int) (Math.random() * players.size()));
} while (player.equals(self));
Card.Suit suit;
suit = Card.Suit.values()[(int) (Math.random() * Card.Suit.values().length)];
prepareTrumpCardActor();
new ChosenTrumpByOtherScreen(data, player, names, suit, trumpCardActor, atlas);
onMessage(new GameMessage(new TrumpMessage(trumpCard, suit)));
}
});
var makePrediction = new TextButton("Make Prediction", data.skin, "simple"); var makePrediction = new TextButton("Make Prediction", data.skin, "simple");
makePrediction.addListener(new ChangeListener() { makePrediction.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
new MakePredictionScreen(data, round, self, predictions); onMessage(new GameMessage(new UserInputMessage(self, UserInputMessage.Action.MAKE_PREDICTION, Long.MAX_VALUE)));
} }
}); });
@ -235,7 +220,7 @@ public class GameScreen extends MenuScreen {
changePrediction.addListener(new ChangeListener() { changePrediction.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
new ChangePredictionScreen(data, round, self, predictions); onMessage(new GameMessage(new UserInputMessage(self, UserInputMessage.Action.CHANGE_PREDICTION, Long.MAX_VALUE)));
} }
}); });
@ -243,40 +228,21 @@ public class GameScreen extends MenuScreen {
chooseTrump.addListener(new ChangeListener() { chooseTrump.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
prepareTrumpCardActor(); onMessage(new GameMessage(new UserInputMessage(self, UserInputMessage.Action.PICK_TRUMP, Long.MAX_VALUE)));
setTrumpCardActor();
new ChooseTrumpScreen(data, trumpCardActor, trumpCard, atlas);
}
});
var predictionByOther = new TextButton("Prediction By Other", data.skin, "simple");
predictionByOther.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
UUID player;
do {
player = players.get((int) (Math.random() * players.size()));
} while (player.equals(self));
predictions.put(player, (int) (Math.random() * 7));
int randomPrediction = (int) (Math.random() * players.size() * 7);
new PredictionByOtherScreen(data, names.get(player), randomPrediction);
onMessage(new GameMessage(new PredictionMessage(player, randomPrediction)));
} }
}); });
var buttons = new VerticalGroup(); var buttons = new VerticalGroup();
buttons.top().left().columnLeft().setPosition(0, WizardGame.HEIGHT - buttons.getHeight()); buttons.top().left().columnLeft().setPosition(0, WizardGame.HEIGHT - buttons.getHeight());
buttons.addActor(roundButton); buttons.addActor(round);
buttons.addActor(deal); buttons.addActor(deal);
buttons.addActor(trump); buttons.addActor(trump);
buttons.addActor(predictionsLocale); buttons.addActor(predictions);
buttons.addActor(playCard); buttons.addActor(playCard);
buttons.addActor(playOtherCard); buttons.addActor(playOtherCard);
buttons.addActor(scores); buttons.addActor(scores);
buttons.addActor(chooseTrump); buttons.addActor(chooseTrump);
buttons.addActor(chosenTrumpByOther);
buttons.addActor(makePrediction); buttons.addActor(makePrediction);
buttons.addActor(predictionByOther);
buttons.addActor(changePrediction); buttons.addActor(changePrediction);
return buttons; return buttons;
} }
@ -318,25 +284,6 @@ public class GameScreen extends MenuScreen {
} }
} }
private void prepareTrumpCardActor() {
if (Arrays.stream(data.stage.getActors().toArray()).filter(p -> p instanceof CardActor).toArray().length != 0) {
trumpCardActor = (CardActor) Arrays.stream(data.stage.getActors().toArray()).filter(p -> p instanceof CardActor).findFirst().get();
} if (trumpCardActor != null) {
trumpCardActor.remove();
}
}
private void setTrumpCardActor() {
if(trumpCard == null) {
trumpCard = Card.values()[(int)(Math.random() * Card.values().length)];
}
if (trumpCardActor != null) {
trumpCardActor.setCard(trumpCard);
} else {
trumpCardActor = new CardActor(trumpCard, atlas);
}
}
private void prepareLabels() { private void prepareLabels() {
for (UUID player : players) { for (UUID player : players) {
if (self.equals(player)) continue; if (self.equals(player)) continue;
@ -380,23 +327,7 @@ public class GameScreen extends MenuScreen {
cardStack.clearChildren(); cardStack.clearChildren();
stack.clear(); stack.clear();
var group = new VerticalGroup().columnCenter().space(10f); new StartRoundOverlay(this, round).show(data.stage);
var overlay = new Container<>(group);
overlay.setBackground(this.overlay);
overlay.setBounds(0, 0, WizardGame.WIDTH, WizardGame.HEIGHT);
overlay.setTouchable(Touchable.enabled);
var label = new Label("Round " + (round + 1), data.skin, "enchanted");
label.setFontScale(1.5f);
group.addActor(label);
data.stage.addActor(overlay);
data.stage.addAction(sequence(
delay(2.0f),
target(alpha(0.0f, .1f, Interpolation.pow2Out), overlay),
removeActor(overlay)
));
} }
private void startTrick() { private void startTrick() {
@ -429,52 +360,11 @@ public class GameScreen extends MenuScreen {
this.trumpSuit = trumpSuit; this.trumpSuit = trumpSuit;
if (trumpCardActor != null) { if (trumpCardActor != null) {
trumpCardActor.remove(); trumpCardActor.remove();
}
if (trumpCard == null) return;
if (trumpCardActor != null) {
trumpCardActor.setCard(trumpCard);
} else { } else {
trumpCardActor = new CardActor(trumpCard, atlas); trumpCardActor = new CardActor(Card.HIDDEN, atlas);
} }
var group = new VerticalGroup().columnCenter().space(10f); new TrumpOverlay(this, null, trumpCard, trumpSuit).show(data.stage);
var overlay = new Container<>(group);
overlay.setBackground(this.overlay);
overlay.setBounds(0, 0, WizardGame.WIDTH, WizardGame.HEIGHT);
overlay.setTouchable(Touchable.enabled);
String text = switch (trumpSuit) {
case YELLOW -> "The trump suit is [#ffff00]yellow[#ffffff].";
case GREEN -> "The trump suit is [#00ff00]green[#ffffff].";
case BLUE -> "The trump suit is [#0000ff]blue[#ffffff].";
case RED -> "The trump suit is [#ff0000]red[#ffffff].";
default -> "There is no trump suit.";
};
var label = new Label(text, data.skin);
label.getStyle().font.getData().markupEnabled = true;
label.setFontScale(1.5f);
group.addActor(label);
group.addActor(trumpCardActor);
data.stage.addActor(overlay);
data.stage.addAction(sequence(
delay(2.0f),
parallel(
sequence(
target(alpha(0.0f, .1f, Interpolation.pow2Out), overlay),
removeActor(overlay)
),
sequence(
removeActorSilently(trumpCardActor),
target(changeParent(data.stage.getRoot()), trumpCardActor),
target(moveTo(10,10, .25f), trumpCardActor)
)
)
));
} }
private void addPrediction(UUID player, int prediction) { private void addPrediction(UUID player, int prediction) {
@ -523,14 +413,16 @@ public class GameScreen extends MenuScreen {
} }
private void setActivePlayer(UUID player, UserInputMessage.Action action) { private void setActivePlayer(UUID player, UserInputMessage.Action action) {
if (activePlayer != null) { if (activePlayer != null && nameLabels.containsKey(activePlayer.getKey())) {
nameLabels.get(activePlayer.getKey()).getStyle().fontColor = Color.WHITE; nameLabels.get(activePlayer.getKey()).getStyle().fontColor = Color.WHITE;
} }
if (player == null && action == null) { if (player == null && action == null) {
activePlayer = null; activePlayer = null;
} else { } else {
activePlayer = Pair.of(player, action); activePlayer = Pair.of(player, action);
nameLabels.get(activePlayer.getKey()).getStyle().fontColor = Color.RED; if (nameLabels.containsKey(player)) {
nameLabels.get(player).getStyle().fontColor = Color.RED;
}
} }
} }
@ -568,6 +460,11 @@ public class GameScreen extends MenuScreen {
} else if (observerMessage instanceof UserInputMessage userInput) { } else if (observerMessage instanceof UserInputMessage userInput) {
setActivePlayer(userInput.getPlayer(), userInput.getAction()); setActivePlayer(userInput.getPlayer(), userInput.getAction());
if (self.equals(userInput.getPlayer())) { if (self.equals(userInput.getPlayer())) {
switch (userInput.getAction()) {
case PICK_TRUMP -> new PickTrumpOverlay(this, false).show(data.stage);
case MAKE_PREDICTION -> new MakePredictionOverlay(this, round).show(data.stage);
case CHANGE_PREDICTION -> new ChangePredictionOverlay(this, round, predictions.get(self)).show(data.stage);
}
// TODO do something // TODO do something
} }
} else if (observerMessage instanceof StateMessage state) { } else if (observerMessage instanceof StateMessage state) {
@ -582,6 +479,10 @@ public class GameScreen extends MenuScreen {
} }
} }
public MenuScreen.Data getData() {
return data;
}
@Getter @Getter
public enum Seat { public enum Seat {
BOTTOM(WizardGame.WIDTH * 0.5f, 0, 0, 0, Align.bottom, WizardGame.WIDTH * 0.5f, 300), BOTTOM(WizardGame.WIDTH * 0.5f, 0, 0, 0, Align.bottom, WizardGame.WIDTH * 0.5f, 300),

@ -1,110 +0,0 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import eu.jonahbauer.wizard.common.messages.client.InteractionMessage;
import eu.jonahbauer.wizard.common.messages.player.PredictMessage;
import java.util.Map;
import java.util.UUID;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.removeActor;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.run;
public class ChangePredictionScreen extends EventScreen {
final int round;
final UUID player;
final Map<UUID, Integer> predictions;
public ChangePredictionScreen(MenuScreen.Data data, int round, UUID player, Map<UUID, Integer> predictions) {
super(data);
this.round = round;
this.player = player;
this.predictions = predictions;
var labelTop = new Label("One of your tricks contains the Card Cloud.", data.skin);
labelTop.setFontScale(2.0f);
group.addActor(labelTop);
showEventScreen();
}
@Override
public void showEventScreen() {
ChangeListener changeListener = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if(actor instanceof TextButton textButton) {
int chosenPrediction = Integer.parseInt(textButton.getText().toString());
//Nur zur Demo - eigtl. Senden von predictMessage und Auswerten vin predictionMessage
predictions.put(player, Integer.parseInt(textButton.getText().toString()));
data.stage.addAction(removeActor(screen));
new InteractionMessage(new PredictMessage(chosenPrediction));
}
}
};
if (predictions.get(player) != null) {
int i = predictions.get(player);
var labelZeroPrediction = new Label("Your original prediction is", data.skin);
labelZeroPrediction.setFontScale(2.0f);
group.addActor(labelZeroPrediction);
var originalPrediction = new Label(i + "", data.skin, "enchanted");
group.addActor(originalPrediction);
var labelPredictionUpper = new Label("According to the game rules your prediction", data.skin);
labelPredictionUpper.setFontScale(2.0f);
group.addActor(labelPredictionUpper);
if (i == 0 || i == round) {
var labelPredictionLower = new Label("must " + (i == 0 ? "increase" : "decrease") + " by one to", data.skin);
labelPredictionLower.setFontScale(2.0f);
group.addActor(labelPredictionLower);
var newPrediction = new Label((i == 0 ? (i + 1) : (i - 1)) + "", data.skin, "enchanted");
group.addActor(newPrediction);
var okButton = new TextButton("OK", data.skin);
okButton.addListener(
new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
data.stage.addAction(removeActor(screen));
}
}
);
group.addActor(okButton);
screen.addActor(group);
if (i == 0) {
//nur Demo
predictions.put(player, ++i);
//eigtl.
new InteractionMessage(new PredictMessage(i));
} else {
//nur Demo
predictions.put(player, --i);
//eigtl.
new InteractionMessage(new PredictMessage(i));
}
} else {
var labelPredictionMiddle = new Label("must increase or decrease by one.", data.skin);
labelPredictionMiddle.setFontScale(2.0f);
group.addActor(labelPredictionMiddle);
var labelPredictionLower = new Label("Please choose one of these two options", data.skin);
labelPredictionLower.setFontScale(2.0f);
group.addActor(labelPredictionLower);
var horizontalGroup = new HorizontalGroup();
horizontalGroup.space(50.0f);
var decreaseButton = new TextButton((i - 1) + "", data.skin);
var increaseButton = new TextButton((i + 1) + "", data.skin);
decreaseButton.addListener(changeListener);
increaseButton.addListener(changeListener);
horizontalGroup.addActor(decreaseButton);
horizontalGroup.addActor(increaseButton);
group.addActor(horizontalGroup);
screen.addActor(group);
}
data.stage.addAction(run(() -> data.stage.addActor(screen)));
}
}
}

@ -1,124 +0,0 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import eu.jonahbauer.wizard.common.messages.client.InteractionMessage;
import eu.jonahbauer.wizard.common.messages.player.PickTrumpMessage;
import eu.jonahbauer.wizard.common.model.Card;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
public class ChooseTrumpScreen extends EventScreen {
private CardActor trumpCardActor;
private Card trumpCard;
private TextureAtlas atlas;
public ChooseTrumpScreen(MenuScreen.Data data, CardActor trumpCardActor, Card trumpCard, TextureAtlas atlas) {
super(data);
this.trumpCardActor = trumpCardActor;
this.trumpCard = trumpCard;
this.atlas = atlas;
showEventScreen();
}
@Override
public void showEventScreen() {
BitmapFont font = data.skin.getFont("default-font");
font.getData().setScale(1.5f);
var verticalGroup = new VerticalGroup().align(Align.center);
screen.add(verticalGroup);
var labelTop = new Label("The determined Trump Card Actor is: ", data.skin);
verticalGroup.addActor(labelTop);
verticalGroup.addActor(trumpCardActor);
var labelMiddle = new Label("Please choose a Trump Color", data.skin);
var horizontalGroupBottom = new HorizontalGroup();
horizontalGroupBottom.space(40.0f);
horizontalGroupBottom.padTop(30.0f);
font.getData().setScale(2.5f);
var chooseGreen = new TextButton("Green", data.skin, "toggle");
chooseGreen.setColor(Card.Suit.GREEN.getRed(), Card.Suit.GREEN.getGreen(), Card.Suit.GREEN.getBlue(),Card.Suit.GREEN.getAlpha());
horizontalGroupBottom.addActor(chooseGreen);
var chooseBlue = new TextButton("Blue", data.skin, "toggle");
chooseBlue.setColor(Card.Suit.BLUE.getRed(), Card.Suit.BLUE.getGreen(), Card.Suit.BLUE.getBlue(),Card.Suit.BLUE.getAlpha());
horizontalGroupBottom.addActor(chooseBlue);
var chooseYellow = new TextButton("Yellow", data.skin, "toggle");
chooseYellow.setColor(Card.Suit.YELLOW.getRed(), Card.Suit.YELLOW.getGreen(), Card.Suit.YELLOW.getBlue(),Card.Suit.YELLOW.getAlpha());
horizontalGroupBottom.addActor(chooseYellow);
var chooseRed = new TextButton("Red", data.skin, "toggle");
chooseRed.setColor(Card.Suit.RED.getRed(), Card.Suit.RED.getGreen(), Card.Suit.RED.getBlue(),Card.Suit.RED.getAlpha());
horizontalGroupBottom.addActor(chooseRed);
if(trumpCard == Card.WEREWOLF) {
var chooseNone = new Label("Kein Trumpf", data.skin);
chooseNone.setColor(Card.Suit.NONE.getRed(), Card.Suit.NONE.getGreen(), Card.Suit.NONE.getBlue(),Card.Suit.NONE.getAlpha());
horizontalGroupBottom.addActor(chooseNone);
}
verticalGroup.addActor(labelMiddle);
verticalGroup.addActor(horizontalGroupBottom);
var chosenLabel = new Label("Sie haben gewählt", data.skin);
ChangeListener changeListener = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Card.Suit suit;
if(actor instanceof TextButton textButton) {
switch (textButton.getLabel().getText().toString()) {
//TODO - Eigene Karte nur mit Trumpfarbe? - Karte für keinen Trumpf?
//trumpCardActor.setCard(Card.values()[Card.XY.ordinal()]);
case "Green" -> {
trumpCardActor.setCard(Card.values()[0]);
suit = Card.Suit.GREEN;
}
case "Yellow" -> {
trumpCardActor.setCard(Card.values()[1]);
suit = Card.Suit.YELLOW;
}
case "Blue" -> {
trumpCardActor.setCard(Card.values()[2]);
suit = Card.Suit.BLUE;
}
case "Red" -> {
trumpCardActor.setCard(Card.values()[3]);
suit = Card.Suit.RED;
}
case "None" -> {
trumpCardActor.setCard(Card.values()[4]);
suit = Card.Suit.NONE;
}
default -> throw new AssertionError();
}
data.stage.addAction(sequence(
removeActor(horizontalGroupBottom),
removeActor(labelMiddle),
removeActor(labelTop),
run(() -> verticalGroup.addActorAt(0, chosenLabel)),
delay(2.0f),
removeActor(chosenLabel),
addAction(moveTo(10,10, 0.25f), trumpCardActor),
delay(.1f),
addAction(alpha(0.0f, .1f, Interpolation.pow2Out), background),
delay(.1f),
run(() -> data.stage.addActor(trumpCardActor)),
removeActor(screen)));
new InteractionMessage(new PickTrumpMessage(suit));
}
}
};
horizontalGroupBottom.addListener(changeListener);
data.stage.addAction(run(() -> data.stage.addActor(screen)));
}
}

@ -1,91 +0,0 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import eu.jonahbauer.wizard.common.model.Card;
import java.util.Map;
import java.util.UUID;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
public class ChosenTrumpByOtherScreen extends EventScreen {
private final UUID player;
private final Map<UUID, String> names;
private final Card.Suit suit;
private CardActor trumpCardActor;
private final TextureAtlas atlas;
public ChosenTrumpByOtherScreen(MenuScreen.Data data, UUID player, Map<UUID, String> names, Card.Suit suit,
CardActor trumpCardActor, TextureAtlas atlas) {
super(data);
this.player = player;
this.names = names;
this.suit = suit;
this.trumpCardActor = trumpCardActor;
this.atlas = atlas;
showEventScreen();
}
@Override
public void showEventScreen() {
var playerName = new Label(names.get(player) + " has chosen the trump color: ", data.skin);
playerName.setFontScale(1.5f);
group.addActor(playerName);
Label colorLabel;
switch (suit) {
case GREEN -> {
colorLabel = new Label(Card.Suit.GREEN.toString(), data.skin);
colorLabel.setColor(Card.Suit.GREEN.getRed(), Card.Suit.GREEN.getGreen(), Card.Suit.GREEN.getBlue(),Card.Suit.GREEN.getAlpha());
}
case BLUE -> {
colorLabel = new Label(Card.Suit.BLUE.toString(), data.skin);
colorLabel.setColor(Card.Suit.BLUE.getRed(), Card.Suit.BLUE.getGreen(), Card.Suit.BLUE.getBlue(),Card.Suit.BLUE.getAlpha());
}
case YELLOW -> {
colorLabel = new Label(Card.Suit.YELLOW.toString(), data.skin);
colorLabel.setColor(Card.Suit.YELLOW.getRed(), Card.Suit.YELLOW.getGreen(), Card.Suit.YELLOW.getBlue(),Card.Suit.YELLOW.getAlpha());
}
case RED -> {
colorLabel = new Label(Card.Suit.RED.toString(), data.skin);
colorLabel.setColor(Card.Suit.RED.getRed(), Card.Suit.RED.getGreen(), Card.Suit.RED.getBlue(),Card.Suit.RED.getAlpha());
}
case NONE -> {
colorLabel = new Label(Card.Suit.NONE.toString(), data.skin);
colorLabel.setColor(Card.Suit.NONE.getRed(), Card.Suit.NONE.getGreen(), Card.Suit.NONE.getBlue(),Card.Suit.NONE.getAlpha());
}
default -> throw new AssertionError();
}
group.addActor(colorLabel);
//TODO - Bild/Region für ausgewählte Farbe
//Card trumpCard = Card.values()[suit.ordinal()];
//trumpCardActor.setCard(Card.values()[suit.ordinal()]);
Card trumpCard = Card.BLUE_1;
if (trumpCardActor != null) {
trumpCardActor.setCard(trumpCard);
} else {
trumpCardActor = new CardActor(trumpCard, atlas);
}
group.addActor(trumpCardActor);
screen.addActor(group);
data.stage.addAction(sequence(
run(() -> data.stage.addActor(screen)),
delay(2.0f),
removeActor(playerName),
removeActor(colorLabel),
addAction(moveTo(10,10, 0.25f), trumpCardActor),
delay(.1f),
addAction(alpha(0.0f, .1f, Interpolation.pow2Out), background),
delay(.1f),
run(() -> data.stage.addActor(trumpCardActor)),
removeActor(screen)
));
}
}

@ -1,48 +0,0 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
public abstract class EventScreen {
protected Container<Actor> background;
protected Stack screen;
protected VerticalGroup group;
protected MenuScreen.Data data;
public EventScreen(MenuScreen.Data data) {
this.data = data;
this.background = createBackground();
this.screen = createStack(background);
this.group = createGroup();
}
public Container<Actor> createBackground() {
var background = new Container<>();
background.setBackground(new TextureRegionDrawable(data.uiskinAtlas.findRegion(UiskinAtlas.WHITE)));
background.setColor(0.0f, 0.0f, 0.0f, 0.5f);
background.setFillParent(true);
background.setTouchable(Touchable.enabled);
return background;
}
public Stack createStack(Container<Actor> background) {
var stack = new Stack();
stack.setFillParent(true);
stack.add(background);
return stack;
}
public VerticalGroup createGroup() {
return new VerticalGroup().align(Align.center);
}
public abstract void showEventScreen();
}

@ -1,64 +0,0 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import eu.jonahbauer.wizard.common.messages.client.InteractionMessage;
import eu.jonahbauer.wizard.common.messages.player.PredictMessage;
import java.util.Map;
import java.util.UUID;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.removeActor;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.run;
public class MakePredictionScreen extends EventScreen {
int round;
private UUID player;
private final Map<UUID, Integer> predictions;
public MakePredictionScreen(MenuScreen.Data data, int round, UUID player,Map<UUID, Integer> predictions) {
super(data);
this.round = round;
this.player = player;
this.predictions = predictions;
showEventScreen();
}
@Override
public void showEventScreen() {
if(round == -1)
return;
var label = new Label("Please chose your prediction", data.skin);
label.setFontScale(2.0f);
group.addActor(label);
var changeListener = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if(actor instanceof TextButton textButton) {
int chosenPrediction = Integer.parseInt(textButton.getText().toString());
predictions.put(player, chosenPrediction);
data.stage.addAction(removeActor(screen));
new InteractionMessage(new PredictMessage(chosenPrediction));
}
}
};
var horizontalGroup = new HorizontalGroup();
horizontalGroup.space(30.0f);
for(int i = 0; i <= round; i++) {
var button = new TextButton(i + "", data.skin);
horizontalGroup.addActor(button);
button.addListener(changeListener);
}
group.addActor(horizontalGroup);
screen.addActor(group);
data.stage.addAction(run(() -> data.stage.addActor(screen)));
}
}

@ -1,38 +0,0 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
public class PredictionByOtherScreen extends EventScreen {
private String name;
private int prediction;
public PredictionByOtherScreen(MenuScreen.Data data, String name, int prediction) {
super(data);
this.name = name;
this.prediction = prediction;
group.space(10.0f);
BitmapFont font = data.skin.getFont("default-font");
font.getData().setScale(1.5f);
showEventScreen();
}
@Override
public void showEventScreen() {
var playerName = new Label(name + "'s preditction is: ", data.skin);
group.addActor(playerName);
var predictionLabel = new Label(prediction + "", data.skin, "enchanted");
group.addActor(predictionLabel);
screen.addActor(group);
data.stage.addAction(sequence(
run(() -> data.stage.addActor(screen)),
delay(2.5f),
removeActor(screen)
));
}
}

@ -26,78 +26,6 @@ public enum Card {
JUGGLER, JUGGLER_BLUE, JUGGLER_RED, JUGGLER_GREEN, JUGGLER_YELLOW; JUGGLER, JUGGLER_BLUE, JUGGLER_RED, JUGGLER_GREEN, JUGGLER_YELLOW;
public enum Suit { public enum Suit {
NONE { NONE, YELLOW, RED, GREEN, BLUE
public float getRed() {
return 255.0f;
}
public float getGreen() {
return 255.0f;
}
public float getBlue() {
return 255.0f;
}
},
YELLOW {
public float getRed() {
return 255.0f;
}
public float getGreen() {
return 255.0f;
}
public float getBlue() {
return 0.0f;
}
},
RED{
public float getRed() {
return 238.0f;
}
public float getGreen() {
return 0.0f;
}
public float getBlue() {
return 0.0f;
}
},
GREEN{
public float getRed() {
return 0.0f;
}
public float getGreen() {
return 255.0f;
}
public float getBlue() {
return 0.0f;
}
},
BLUE{
public float getRed() {
return 0.0f;
}
public float getGreen() {
return 0.0f;
}
public float getBlue() {
return 139.0f;
}
};
public float getAlpha() {
return 0.5f;
}
public float getRed() {
return 0.f;
}
public float getGreen() {
return 0.f;
}
public float getBlue() {
return 0.f;
}
} }
} }
Loading…
Cancel
Save