Kombinerer kortvelging og powerdown. Closes #78

This commit is contained in:
Kristian Knarvik 2020-04-27 18:39:06 +02:00
parent ee4c15c999
commit cc71a50370
2 changed files with 55 additions and 30 deletions

View File

@ -15,6 +15,7 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.gamewrapper.SimpleButton; import inf112.fiasko.roborally.gamewrapper.SimpleButton;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
import inf112.fiasko.roborally.objects.ProgrammingCard; import inf112.fiasko.roborally.objects.ProgrammingCard;
import inf112.fiasko.roborally.objects.ProgrammingCardDeck; import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
@ -63,9 +64,17 @@ public class CardChoiceScreen extends InteractiveScreen implements Screen {
TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton(); TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton();
stage.addActor(confirmCards); stage.addActor(confirmCards);
confirmCards.setY(viewport.getWorldHeight() - confirmCards.getHeight()); confirmCards.setY(viewport.getWorldHeight() - confirmCards.getHeight());
confirmCards.setX(15); confirmCards.setX(0);
confirmCards.addListener(getConfirmListener()); confirmCards.addListener(getConfirmListener());
TextButton confirmCardsAndPowerDown = new SimpleButton("Confirm + PowerDown",
roboRallyWrapper.font).getButton();
stage.addActor(confirmCardsAndPowerDown);
confirmCardsAndPowerDown.setY(viewport.getWorldHeight() - confirmCardsAndPowerDown.getHeight());
confirmCardsAndPowerDown.setX(confirmCards.getWidth());
confirmCardsAndPowerDown.addListener(getConfirmAndPowerDownListener());
stage.setViewport(viewport); stage.setViewport(viewport);
} }
@ -83,25 +92,52 @@ public class CardChoiceScreen extends InteractiveScreen implements Screen {
@Override @Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) { public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
if (chosenCards.size() == maxCards) { confirmCards(false);
List<ProgrammingCard> oldProgram = roboRallyWrapper.roboRallyGame.getProgram();
int lockedCardsInt = 5 - maxCards;
List<ProgrammingCard> newProgram = getCards();
for (int i = 4; i > (4 - lockedCardsInt); i--) {
newProgram.add(oldProgram.get(i));
}
roboRallyWrapper.roboRallyGame.setProgram(newProgram);
roboRallyWrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper));
} else {
JOptionPane.showMessageDialog(null, "You need to choose all your cards"
+ " before confirming.");
}
} }
}; };
} }
/**
* Generates a listener for confirming cards and entering power down
*
* @return An input listener
*/
private ClickListener getConfirmAndPowerDownListener() {
return new ClickListener() {
@Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
confirmCards(true);
}
};
}
/**
* Confirm cards and send to server if all are chosen
*/
private void confirmCards(Boolean requestPowerDown) {
if (chosenCards.size() == maxCards) {
List<ProgrammingCard> oldProgram = roboRallyWrapper.roboRallyGame.getProgram();
int lockedCardsInt = 5 - maxCards;
List<ProgrammingCard> newProgram = getCards();
for (int i = 4; i > (4 - lockedCardsInt); i--) {
newProgram.add(oldProgram.get(i));
}
//Save the program to get locked cards later
roboRallyWrapper.roboRallyGame.setProgram(newProgram);
roboRallyWrapper.roboRallyGame.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(requestPowerDown, newProgram));
} else {
JOptionPane.showMessageDialog(null, "You need to choose all your cards"
+ " before confirming.");
}
}
/** /**
* Gets a list of programming cards from the player's chosen cards * Gets a list of programming cards from the player's chosen cards
* *

View File

@ -7,7 +7,6 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.gamewrapper.SimpleButton; import inf112.fiasko.roborally.gamewrapper.SimpleButton;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
/** /**
* This screen is used for asking players whether they want to power down * This screen is used for asking players whether they want to power down
@ -54,17 +53,12 @@ public class PowerDownScreen extends AbstractScreen {
public void render(float delta) { public void render(float delta) {
super.render(delta); super.render(delta);
roboRallyWrapper.batch.setProjectionMatrix(camera.combined); roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
String descriptionText;
if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_POWER_DOWN) {
descriptionText = "Click the button to enter power down next turn";
} else {
descriptionText = "Click the button to continue your power down the next turn";
}
int elapsedTime = (int) Math.floor((System.currentTimeMillis() - startTime) / 1000f); int elapsedTime = (int) Math.floor((System.currentTimeMillis() - startTime) / 1000f);
roboRallyWrapper.batch.begin(); roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, descriptionText, roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to continue your power down the" +
" next turn",
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1, applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
true); true);
roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(5 - elapsedTime), roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(5 - elapsedTime),
@ -89,13 +83,8 @@ public class PowerDownScreen extends AbstractScreen {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
roboRallyWrapper.client.sendElement(bool); roboRallyWrapper.client.sendElement(bool);
break; break;
case CHOOSING_POWER_DOWN:
roboRallyWrapper.roboRallyGame.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(bool,
roboRallyWrapper.roboRallyGame.getProgram()));
break;
default: default:
roboRallyWrapper.quit("The game is in an unexpected state. Cannot continue.");
throw new IllegalStateException("The game is in an unexpected state. Cannot continue."); throw new IllegalStateException("The game is in an unexpected state. Cannot continue.");
} }
} }