mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
fixed continue powerdown bugs closes #66
This commit is contained in:
parent
17a3d4f27a
commit
ee18396d3e
@ -44,6 +44,8 @@ public enum GameState {
|
|||||||
/**
|
/**
|
||||||
* Indicates that the game is no longer running
|
* Indicates that the game is no longer running
|
||||||
*/
|
*/
|
||||||
EXITED
|
EXITED,
|
||||||
|
|
||||||
|
SKIP_POWER_DOWN_SCREEN
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@ import com.badlogic.gdx.utils.viewport.ExtendViewport;
|
|||||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||||
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.networking.containers.ProgramAndPowerdownRequest;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This screen is used to wait for something
|
* This screen is used to wait for something
|
||||||
@ -68,6 +71,14 @@ public class LoadingScreen extends AbstractScreen {
|
|||||||
case EXITED:
|
case EXITED:
|
||||||
roboRallyWrapper.quit("All players died. Cannot continue playing.");
|
roboRallyWrapper.quit("All players died. Cannot continue playing.");
|
||||||
break;
|
break;
|
||||||
|
case CHOOSING_POWER_DOWN:
|
||||||
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(this.roboRallyWrapper));
|
||||||
|
break;
|
||||||
|
case SKIP_POWER_DOWN_SCREEN:
|
||||||
|
roboRallyWrapper.roboRallyGame.setGameState(GameState.LOADING);
|
||||||
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
||||||
|
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(false, new ArrayList<>()));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("The loading screen doesn't know what to do with " + gameState);
|
System.out.println("The loading screen doesn't know what to do with " + gameState);
|
||||||
break;
|
break;
|
||||||
|
@ -57,11 +57,18 @@ public class PowerDownScreen extends AbstractScreen {
|
|||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
camera.update();
|
camera.update();
|
||||||
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 powerdown next round";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
descriptiontext = "continue powerdown?";
|
||||||
|
}
|
||||||
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, "Click the button to enter Power Down next round",
|
|
||||||
|
roboRallyWrapper.font.draw(roboRallyWrapper.batch, descriptiontext,
|
||||||
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(10 - elapsedTime),
|
roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(10 - elapsedTime),
|
||||||
|
@ -11,6 +11,8 @@ import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
|
|||||||
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
||||||
import inf112.fiasko.roborally.objects.RoboRallyGame;
|
import inf112.fiasko.roborally.objects.RoboRallyGame;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This listener handles all receiving from the server
|
* This listener handles all receiving from the server
|
||||||
*/
|
*/
|
||||||
@ -40,7 +42,16 @@ class RoboRallyClientListener extends Listener {
|
|||||||
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
|
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
|
||||||
wrapper.server != null, info.getPlayerName(), wrapper.server);
|
wrapper.server != null, info.getPlayerName(), wrapper.server);
|
||||||
} else if (object instanceof ProgrammingCardDeck) {
|
} else if (object instanceof ProgrammingCardDeck) {
|
||||||
wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS);
|
if(((ProgrammingCardDeck) object).isEmpty()){
|
||||||
|
if (wrapper.roboRallyGame.getRobotPowerdown()){
|
||||||
|
wrapper.roboRallyGame.setGameState(GameState.SKIP_POWER_DOWN_SCREEN);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN);
|
||||||
|
}
|
||||||
|
wrapper.roboRallyGame.setProgram(new ArrayList<>());
|
||||||
|
}
|
||||||
|
else {wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS);}
|
||||||
new Thread(() -> wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object)).start();
|
new Thread(() -> wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object)).start();
|
||||||
} else if (object instanceof ProgamsContainer) {
|
} else if (object instanceof ProgamsContainer) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
@ -77,7 +77,7 @@ public class Player {
|
|||||||
* @param cardList list the size of 5 with programing cards
|
* @param cardList list the size of 5 with programing cards
|
||||||
*/
|
*/
|
||||||
public void setProgram(List<ProgrammingCard> cardList) {
|
public void setProgram(List<ProgrammingCard> cardList) {
|
||||||
if (cardList.size() != 5) {
|
if (cardList.size() != 5 && !cardList.isEmpty()) {
|
||||||
throw new IllegalArgumentException("The program must contain exactly 5 cards.");
|
throw new IllegalArgumentException("The program must contain exactly 5 cards.");
|
||||||
} else {
|
} else {
|
||||||
program = new ArrayList<>(cardList);
|
program = new ArrayList<>(cardList);
|
||||||
|
@ -15,6 +15,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represent a game which is drawable using libgdx
|
* This class represent a game which is drawable using libgdx
|
||||||
@ -33,6 +34,13 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
private ProgrammingCardDeck playerHand;
|
private ProgrammingCardDeck playerHand;
|
||||||
private Phase phase;
|
private Phase phase;
|
||||||
|
|
||||||
|
public Boolean getRobotPowerdown(){
|
||||||
|
if(getPlayerFromName(this.playerName)!=null){
|
||||||
|
return gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Robo Rally game
|
* Instantiates a new Robo Rally game
|
||||||
*
|
*
|
||||||
@ -173,19 +181,20 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
removeNonLockedProgrammingCardsFromPlayers();
|
removeNonLockedProgrammingCardsFromPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameBoard.getPowerDown(getPlayerFromName(this.playerName).getRobotID())) {
|
if (gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID())) {
|
||||||
setGameState(GameState.CHOOSING_STAY_IN_POWER_DOWN);
|
setGameState(GameState.CHOOSING_STAY_IN_POWER_DOWN);
|
||||||
} else {
|
} else {
|
||||||
setGameState(GameState.LOADING);
|
setGameState(GameState.LOADING);
|
||||||
|
|
||||||
}
|
}
|
||||||
//updateRobotPowerDown(); Should this be here?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveStayInPowerDown(PowerDownContainer powerDowns) {
|
public void receiveStayInPowerDown(PowerDownContainer powerDowns) {
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName()));
|
if(gameBoard.getPowerDown(player.getRobotID())) {
|
||||||
|
player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
respawnRobots();
|
respawnRobots();
|
||||||
sendAllDeadPlayersToServer();
|
sendAllDeadPlayersToServer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user