use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.
the class MatchScreen method render.
@Override
public void render(float delta) {
// Basic Update and Render Stage
if (startedMatch) {
mainStage.act(delta);
mainStage.draw();
// Set Info text to be whos turn it is
updateInfoText();
// Render Animations that are queued
animations(delta);
// Accept Opponent / Server sent move
listenForServerMessage();
// Check if player attempted MatchComponentsMove
playerMatchComponentsMoveCheck();
// Check if player attempted UseAbilityMove
playerUseAbilityMoveCheck();
} else {
if (game.getServerAPI().hasMessage()) {
Message matchStateData = game.getServerAPI().readMessage();
if (matchStateData.type == Type.MATCH_STATE_DATA) {
initializeStage(matchStateData);
startedMatch = true;
}
}
}
}
use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.
the class MatchScreen method playerUseAbilityMoveCheck.
private void playerUseAbilityMoveCheck() {
for (SoftwareActor softwareActor : softwareActors.get(game.getCurrentProfile().getUID())) {
if (softwareActor.activatedAbility()) {
Ability ability = softwareActor.getSoftware().getAbility();
if (isSelecting == false) {
this.selectIndex = 0;
selectedCards.clear();
selectedComponents.clear();
this.isSelecting = true;
}
if (ability.getSelectFilters().size() > 0) {
this.currentSelectFilter = ability.getSelectFilters().get(selectIndex);
if (this.currentSelectFilter instanceof ComponentFilter) {
if (!board.isSelecting()) {
board.startComponentSelection((ComponentFilter) this.currentSelectFilter);
}
if (board.didCompleteSelection()) {
selectedComponents.addAll(board.getSelected());
selectIndex++;
board.endComponentSelection();
}
} else if (this.currentSelectFilter instanceof CardFilter) {
CardFilter filter = (CardFilter) this.currentSelectFilter;
for (String uid : this.softwareActors.keySet()) {
for (SoftwareActor sa : this.softwareActors.get(uid)) {
if (!sa.isSelecting()) {
if (!filter.filter(sa.getSoftware(), matchData.getCurrentState(), null)) {
sa.setColor(Color.GRAY);
sa.setTouchable(Touchable.disabled);
} else {
sa.startSelection();
}
}
if (sa.isSelected()) {
this.selectedCards.add(sa);
selectIndex++;
for (String u : this.softwareActors.keySet()) {
for (SoftwareActor s : this.softwareActors.get(u)) {
s.endSelection();
sa.setColor(Color.WHITE);
sa.setTouchable(Touchable.enabled);
}
}
}
}
}
}
}
if (selectIndex == ability.getSelectFilters().size()) {
List<Component> components = new ArrayList<>();
List<Card> cards = new ArrayList<>();
for (ComponentActor selectedComponent : selectedComponents) {
components.add(selectedComponent.getComponent());
}
for (SoftwareActor selectedCard : selectedCards) {
cards.add(selectedCard.getSoftware());
}
UseAbilityMove move = new UseAbilityMove(game.getCurrentProfile().getUID(), softwareActor.getSoftware(), components, cards);
softwareActor.setActivatedAbility(false);
System.out.println("USED ABILITY MOVE");
if (GameRules.getAvailableMoves(matchData.getCurrentState()).contains(move)) {
game.getServerAPI().sendMessage(new Message(Type.MOVE_REQUEST, json.toJson(move)));
} else {
System.out.println("NOT VALID MOVE???");
}
this.isSelecting = false;
this.selectIndex = -1;
this.selectedCards.clear();
this.selectedComponents.clear();
for (String u : this.softwareActors.keySet()) {
for (SoftwareActor s : this.softwareActors.get(u)) {
s.endSelection();
s.setColor(Color.WHITE);
s.setTouchable(Touchable.enabled);
}
}
}
}
}
ComputerActor computerActor = computerActors.get(game.getCurrentProfile().getUID());
if (computerActor.activatedAbility()) {
UseAbilityMove move = new UseAbilityMove(game.getCurrentProfile().getUID(), computerActor.getComputer(), new ArrayList<>(), new ArrayList<>());
computerActor.setActivatedAbility(false);
if (GameRules.getAvailableMoves(matchData.getCurrentState()).contains(move)) {
game.getServerAPI().sendMessage(new Message(Type.MOVE_REQUEST, json.toJson(move)));
}
}
}
use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.
the class MatchScreen method listenForServerMessage.
private void listenForServerMessage() {
if (game.getServerAPI().hasMessage() && isAnimating() == false) {
Message serverMessage = game.getServerAPI().readMessage();
System.out.println(serverMessage.getType());
if (serverMessage.type == Type.MOVE_ACCEPT) {
List<MoveResult> results = json.fromJson(List.class, serverMessage.getMessage());
animate(results, this);
} else if (serverMessage.type == Type.PING) {
} else if (serverMessage.type == Type.MATCH_RESULTS) {
MatchResults results = json.fromJson(MatchResults.class, serverMessage.getMessage());
gameOver(results);
}
}
}
use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.
the class QueueScreen method render.
@Override
public void render(float f) {
stage.act(f);
stage.draw();
if (game.getServerAPI().hasMessage()) {
Message m = game.getServerAPI().readMessage();
if (m.type == Type.QUEUE_POSITION) {
queueStatus.setText("Queued: Position " + m.getMessage() + " in queue");
queued = true;
queueStatusTable.clearChildren();
queueStatusTable.add(cancelQueue);
queueStatusTable.add(queueStatus).growX().row();
}
if (m.type == Type.SUCCESS && canceled) {
queueStatusTable.clearChildren();
queueStatus.setText("Press Play to Queue");
queueStatusTable.add(queueStatus).growX().row();
canceled = false;
queued = false;
}
if (m.type == Type.FOUND_MATCH && queued) {
String content = m.getMessage();
Window window = new Window("Found Match!", skin);
Table t = new Table(skin);
Label label = new Label("Accept Match from " + content + "?", skin);
label.setAlignment(Align.center);
label.setWrap(true);
TextButton accept = new TextButton("Ready", skin);
TextButton deny = new TextButton("Cancel", skin);
t.add(label).grow().row();
t.add(accept).growX().row();
t.add(deny).growX().row();
window.add(t).grow();
stage.addActor(window);
accept.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
window.remove();
game.getServerAPI().sendMessage(new Message(Type.READY, "READY"));
ClientMatch clientMatch = new ClientMatch(content);
queued = false;
game.pushScreen(new MatchScreen(game, clientMatch));
}
});
deny.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
window.remove();
game.getServerAPI().sendMessage(new Message(Type.CANCEL_QUEUE, "CANCEL"));
canceled = true;
}
});
window.setSize(stage.getWidth() / 2, stage.getHeight() / 2);
window.setPosition(stage.getWidth() / 4, stage.getHeight() / 4);
}
}
}
use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.
the class QueueScreen method show.
@Override
public void show() {
this.camera = new OrthographicCamera(1920 / 4, 1080 / 4);
this.stage = ComputerCombatGame.makeNewStage(camera);
isRanked = false;
isLive = true;
Gdx.input.setInputProcessor(stage);
Table table = new Table();
table.defaults().space(3);
table.pad(3);
table.setFillParent(true);
Table titleTable = new Table(skin);
titleTable.setBackground("border");
Label title = new Label("Play", skin);
title.setAlignment(Align.center);
TextButton backButton = new TextButton("Back", skin);
backButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.getServerAPI().sendMessage(new Message(Type.CANCEL_QUEUE, game.getCurrentProfile().getUID()));
game.popScreen();
}
});
titleTable.add(backButton);
titleTable.add(title).growX().row();
table.add(titleTable).growX().row();
BorderedGrid mainTable = new BorderedGrid(skin);
decksTable = new Table(skin);
decksTable.defaults().space(3);
Label decksTitle = new Label("Decks", skin, "title");
decksTitle.setAlignment(Align.center);
decks = new Table();
decks.defaults().space(5).height(60).width(70);
populateDecks();
ScrollPane decksScroll = new ScrollPane(decks, skin);
decksScroll.setFadeScrollBars(false);
TextButton updateButton = new TextButton("Edit Decks", skin);
updateButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.getServerAPI().sendMessage(new Message(Type.CANCEL_QUEUE, game.getCurrentProfile().getUID()));
while (game.getServerAPI().hasMessage() == false) {
}
game.getServerAPI().readMessage();
queued = false;
canceled = false;
game.pushScreen(new DecksScreen(game));
}
});
decksTable.add(decksTitle).growX().row();
decksTable.add(decksScroll).grow().row();
decksTable.add(updateButton).growX();
mainTable.add(decksTable).left().width(120).growY().pad(5);
Table playTable = new Table();
playTable.defaults().space(3);
playTable.pad(5);
playTable.top();
Table toggleRankedButton = new Table(skin);
toggleRankedButton.setBackground("border");
toggleRankedButton.defaults().space(3);
toggleRankedButton.pad(10);
TextButton rankedButton = new TextButton("Ranked", skin);
TextButton casualButton = new TextButton("Casual", skin);
rankedButton.setColor(Color.LIGHT_GRAY);
casualButton.setColor(Color.WHITE);
rankedButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
rankedButton.setColor(Color.WHITE);
casualButton.setColor(Color.LIGHT_GRAY);
isRanked = true;
}
});
casualButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
rankedButton.setColor(Color.LIGHT_GRAY);
casualButton.setColor(Color.WHITE);
isRanked = false;
}
});
toggleRankedButton.add(rankedButton, casualButton);
Table modeToggleButton = new Table(skin);
modeToggleButton.pad(10);
modeToggleButton.defaults().space(3);
modeToggleButton.setBackground("border");
TextButton liveMatchButton = new TextButton("Live\n-----\nPlay against an opponent in real time", skin);
TextButton raidMatchButton = new TextButton("Raid\n-----\nPlay against an offline player's defenses", skin);
liveMatchButton.getLabel().setWrap(true);
raidMatchButton.getLabel().setWrap(true);
raidMatchButton.setColor(Color.LIGHT_GRAY);
liveMatchButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
raidMatchButton.setColor(Color.LIGHT_GRAY);
liveMatchButton.setColor(Color.WHITE);
isLive = true;
}
});
raidMatchButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
liveMatchButton.setColor(Color.LIGHT_GRAY);
raidMatchButton.setColor(Color.WHITE);
isLive = false;
}
});
modeToggleButton.add(liveMatchButton).grow();
modeToggleButton.add(raidMatchButton).grow();
TextButton playButton = new TextButton("Play", skin);
playButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (!queued && selectedDeck != null) {
Json json = new Json();
List<String> data = new ArrayList<>();
data.add(json.toJson(game.getCurrentProfile()));
data.add(json.toJson(selectedDeck.getDeck()));
data.add(json.toJson(new boolean[] { isRanked, isLive }));
Message requestQueue = new Message(Type.JOIN_QUEUE_REQUEST, json.toJson(data));
game.getServerAPI().sendMessage(requestQueue);
}
}
});
queueStatusTable = new Table(skin);
queueStatusTable.setBackground("border");
cancelQueue = new TextButton("Cancel", skin);
cancelQueue.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.getServerAPI().sendMessage(new Message(Type.CANCEL_QUEUE, game.getCurrentProfile().getUID()));
canceled = true;
}
});
queueStatus = new Label("Press Play to Queue", skin);
queueStatus.setAlignment(Align.center);
queueStatusTable.add(queueStatus).growX().row();
// queueStatusTable.add(cancelQueue);
playTable.add(toggleRankedButton).row();
playTable.add(modeToggleButton).grow().row();
playTable.add(playButton).growX().row();
playTable.add(queueStatusTable).growX().row();
mainTable.add(playTable).grow().row();
table.add(mainTable).grow().row();
stage.addActor(table);
}
Aggregations