mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
Conflicts: src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java src/main/java/inf112/fiasko/roborally/gamewrapper/screens/WinnerScreen.java src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java
This commit is contained in:
commit
ec53519f3b
@ -20,5 +20,7 @@ public enum GameState {
|
||||
//Indicates that the user is in the process of choosing whether to stay in power down
|
||||
CHOOSING_STAY_IN_POWER_DOWN,
|
||||
//Indicates that the user is in the process of sending their cards to the server
|
||||
SENDING_CARDS
|
||||
SENDING_CARDS,
|
||||
//Indicates that the game is won by a player
|
||||
GAME_IS_WON
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package inf112.fiasko.roborally.gamewrapper;
|
||||
package inf112.fiasko.roborally.game_wrapper;
|
||||
|
||||
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.BoardActiveScreen;
|
||||
@ -19,6 +19,19 @@ public class ScreenManager {
|
||||
private UsernameScreen usernameScreen;
|
||||
private IPAddressScreen ipAddressScreen;
|
||||
private LobbyScreen lobbyScreen;
|
||||
private WinnerScreen winnerScreen;
|
||||
|
||||
/**
|
||||
* Gets an instance of the winner screen
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A winner screen instance
|
||||
*/
|
||||
public synchronized WinnerScreen getWinnerScreen(RoboRallyWrapper roboRallyWrapper) {
|
||||
if (this.winnerScreen == null) {
|
||||
this.winnerScreen = new WinnerScreen(roboRallyWrapper);
|
||||
}
|
||||
return winnerScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the power down screen
|
||||
|
@ -1,4 +1,4 @@
|
||||
package inf112.fiasko.roborally.gamewrapper.screens;
|
||||
package inf112.fiasko.roborally.game_wrapper.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
@ -74,6 +74,11 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
roboRallyWrapper.batch.begin();
|
||||
drawBoard(roboRallyWrapper.batch);
|
||||
roboRallyWrapper.batch.end();
|
||||
|
||||
// Checks if there has been found a winning player and then changes the screen to display the winning screen
|
||||
if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.GAME_IS_WON) {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getWinnerScreen(roboRallyWrapper));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,76 @@
|
||||
package inf112.fiasko.roborally.game_wrapper.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
|
||||
import inf112.fiasko.roborally.game_wrapper.SimpleButton;
|
||||
|
||||
public class WinnerScreen extends AbstractScreen {
|
||||
private final RoboRallyWrapper roboRallyWrapper;
|
||||
|
||||
private final OrthographicCamera camera;
|
||||
private final Viewport viewport;
|
||||
private final Stage stage;
|
||||
|
||||
/**
|
||||
* Instantiates a new winner screen
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public WinnerScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
camera = new OrthographicCamera();
|
||||
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
|
||||
stage = new Stage();
|
||||
stage.setViewport(viewport);
|
||||
TextButton quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton();
|
||||
stage.addActor(quitButton);
|
||||
quitButton.setY(applicationHeight / 2f);
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
quitButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
Gdx.app.exit();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
quitButton.setX(applicationWidth / 2f + quitButton.getWidth()/2);
|
||||
this.roboRallyWrapper = roboRallyWrapper;
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(0.2f, 1f, 0.2f, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
camera.update();
|
||||
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "The winner is: " +
|
||||
roboRallyWrapper.roboRallyGame.getWinningPlayerName(),applicationWidth / 2f - 380 / 2f,
|
||||
applicationHeight / 2f + 100,380, 1,
|
||||
true);
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to exit the game",
|
||||
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
|
||||
true);
|
||||
roboRallyWrapper.batch.end();
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
viewport.update(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
}
|
||||
|
||||
}
|
@ -65,6 +65,17 @@ public interface IDrawableGame {
|
||||
*/
|
||||
GameState getGameState();
|
||||
|
||||
/**
|
||||
* Sets the current state og the game
|
||||
*/
|
||||
void setGameState(GameState gameState);
|
||||
|
||||
/**
|
||||
* Gets the name of the player who won
|
||||
* @return A string of the player name
|
||||
*/
|
||||
String getWinningPlayerName();
|
||||
|
||||
|
||||
RoboRallyClient getClient();
|
||||
|
||||
|
@ -36,6 +36,7 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
private String nameOfPlayer;
|
||||
private RoboRallyClient client;
|
||||
private RoboRallyServer server;
|
||||
private String winningPlayerName;
|
||||
|
||||
|
||||
|
||||
@ -47,14 +48,33 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
this.nameOfPlayer = nameOfPlayer;
|
||||
}
|
||||
|
||||
|
||||
public String getWinningPlayerName() {
|
||||
return winningPlayerName;
|
||||
}
|
||||
|
||||
public void setWinningPlayerName(String winningPlayerName) {
|
||||
this.winningPlayerName = winningPlayerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the gameState of the game
|
||||
* @return the gameState of the game
|
||||
*/
|
||||
@Override
|
||||
public GameState getGameState(){
|
||||
return gameState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the gameState of the game
|
||||
* @param gameState the gameState
|
||||
*/
|
||||
@Override
|
||||
public void setGameState(GameState gameState) {
|
||||
this.gameState = gameState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoboRallyClient getClient() {
|
||||
return client;
|
||||
@ -71,14 +91,6 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
this.server=server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the gameState of the game
|
||||
* @param gameState the gameState
|
||||
*/
|
||||
public void setGameState(GameState gameState) {
|
||||
this.gameState = gameState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new robo rally game
|
||||
* @param debug Whether to start the game in debugging mode
|
||||
@ -93,6 +105,7 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
initializeGame(boardName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new robo rally game
|
||||
*/
|
||||
@ -560,14 +573,13 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
|
||||
robot.setHasTouchedFlagThisTurn(true);
|
||||
if (victoryCheck(robot.getLastFlagVisited(), listOfFlags.size())) {
|
||||
Player winningPlayer;
|
||||
for (Player player : playerList) {
|
||||
if (player.getRobotID() != robotID) {
|
||||
continue;
|
||||
}
|
||||
winningPlayer = player;
|
||||
setWinningPlayerName(player.getName());
|
||||
setGameState(GameState.GAME_IS_WON);
|
||||
}
|
||||
//TODO: Make win screen announcing the winning player
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user