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/element_properties/GameState.java src/main/java/inf112/fiasko/roborally/objects/IDrawableGame.java src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
This commit is contained in:
commit
5361546e4f
@ -17,6 +17,8 @@ public enum GameState {
|
||||
CHOOSING_POWER_DOWN,
|
||||
//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,
|
||||
//Indicates that the game is won by a player
|
||||
GAME_IS_WON
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import inf112.fiasko.roborally.game_wrapper.screens.*;
|
||||
*/
|
||||
public class ScreenManager {
|
||||
private BoardActiveScreen boardActiveScreen;
|
||||
private CardChoiceScreen cardChoiceScreen;
|
||||
private PowerDownScreen powerDownScreen;
|
||||
private LoadingScreen loadingScreen;
|
||||
private UsernameScreen usernameScreen;
|
||||
@ -109,15 +108,5 @@ public class ScreenManager {
|
||||
return boardActiveScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the card choice screen
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A card choice screen instance
|
||||
*/
|
||||
public synchronized CardChoiceScreen getCardChoiceScreen(RoboRallyWrapper roboRallyWrapper) {
|
||||
if (this.cardChoiceScreen == null) {
|
||||
this.cardChoiceScreen = new CardChoiceScreen(roboRallyWrapper);
|
||||
}
|
||||
return cardChoiceScreen;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
|
||||
import inf112.fiasko.roborally.game_wrapper.SimpleButton;
|
||||
import inf112.fiasko.roborally.objects.IDeck;
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
||||
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
|
||||
|
||||
import java.awt.*;
|
||||
@ -44,12 +45,14 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
private final int maxCards;
|
||||
private final Stage stage;
|
||||
private final InputMultiplexer inputMultiplexer;
|
||||
private ProgrammingCardDeck deck;
|
||||
|
||||
/**
|
||||
* Instantiates a new card choice screen
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper, ProgrammingCardDeck deck) {
|
||||
this.deck = deck;
|
||||
this.roboRallyWrapper = roboRallyWrapper;
|
||||
camera = new OrthographicCamera();
|
||||
int applicationWidth = 600;
|
||||
@ -89,6 +92,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
stage.setViewport(viewport);
|
||||
inputMultiplexer.addProcessor(this);
|
||||
inputMultiplexer.addProcessor(stage);
|
||||
if(roboRallyWrapper.roboRallyGame.getClient()==null){
|
||||
roboRallyWrapper.roboRallyGame.setClient(roboRallyWrapper.client);
|
||||
roboRallyWrapper.roboRallyGame.setServer(roboRallyWrapper.server);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,13 +47,17 @@ public class LoadingScreen extends AbstractScreen {
|
||||
roboRallyWrapper.batch.end();
|
||||
long time = System.currentTimeMillis();
|
||||
//TODO: Allow to set any condition and next screen
|
||||
if (roboRallyWrapper.roboRallyGame.getGameState() != initialGameState) {
|
||||
if (roboRallyWrapper.roboRallyGame != null && roboRallyWrapper.roboRallyGame.getGameState() != initialGameState ) {
|
||||
handleScreenChange();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleScreenChange() {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper));
|
||||
switch (initialGameState) {
|
||||
case SENDING_CARDS:
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,7 +68,12 @@ public class LoadingScreen extends AbstractScreen {
|
||||
@Override
|
||||
public void show() {
|
||||
startTime = System.currentTimeMillis();
|
||||
initialGameState = roboRallyWrapper.roboRallyGame.getGameState();
|
||||
if (roboRallyWrapper.roboRallyGame == null){
|
||||
initialGameState = GameState.INITIAL_SETUP;
|
||||
}
|
||||
else {
|
||||
initialGameState = roboRallyWrapper.roboRallyGame.getGameState();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,8 +14,10 @@ import inf112.fiasko.roborally.game_wrapper.SimpleButton;
|
||||
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
|
||||
import inf112.fiasko.roborally.objects.Player;
|
||||
import inf112.fiasko.roborally.utility.IOUtil;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This screen allows the host to wait for players to join
|
||||
@ -44,9 +46,13 @@ public class LobbyScreen extends AbstractScreen {
|
||||
startGameButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
List<Player> playerlist = IOUtil.playerGenerator(roboRallyWrapper.server.getPlayerNames(),
|
||||
Map<Connection,String> playernames = roboRallyWrapper.server.getPlayerNames();
|
||||
List<Player> playerlist = IOUtil.playerGenerator(playernames,
|
||||
roboRallyWrapper.server.getRobotID());
|
||||
roboRallyWrapper.server.sendToAllClients(new GameStartInfo("Checkmate.txt",playerlist));
|
||||
for (Connection connection:playernames.keySet()) {
|
||||
roboRallyWrapper.server.sendToClient(connection,new GameStartInfo("Checkmate.txt"
|
||||
,playerlist,playernames.get(connection)));
|
||||
}
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
|
||||
return true;//her we do stuff
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ import com.esotericsoftware.kryonet.Client;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
import com.esotericsoftware.kryonet.Listener;
|
||||
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
|
||||
import inf112.fiasko.roborally.game_wrapper.screens.CardChoiceScreen;
|
||||
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
|
||||
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
||||
import inf112.fiasko.roborally.objects.RoboRallyGame;
|
||||
import inf112.fiasko.roborally.utility.NetworkUtil;
|
||||
|
||||
@ -16,7 +18,6 @@ import java.io.IOException;
|
||||
*/
|
||||
public class RoboRallyClient {
|
||||
private final Client client;
|
||||
|
||||
/**
|
||||
* Instantiates a new Robo Rally client
|
||||
* @param ipAddress The ip address of the server to connect to
|
||||
@ -64,7 +65,10 @@ class RoboRallyClientListener extends Listener {
|
||||
} else if (object instanceof GameStartInfo) {
|
||||
GameStartInfo info = (GameStartInfo) object;
|
||||
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
|
||||
wrapper.server != null);
|
||||
wrapper.server != null,info.getPlayerName());
|
||||
}
|
||||
else if(object instanceof ProgrammingCardDeck){
|
||||
wrapper.setScreen(new CardChoiceScreen(wrapper,(ProgrammingCardDeck) object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,8 +53,13 @@ public class RoboRallyServer {
|
||||
public void sendToAllClients(Object object) {
|
||||
server.sendToAllTCP(object);
|
||||
}
|
||||
|
||||
public void sendToClient(Connection connection, Object object){
|
||||
server.sendToTCP(connection.getID(),object);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This listener handles all sending and responses for the server
|
||||
*/
|
||||
|
@ -10,12 +10,21 @@ import java.util.List;
|
||||
public class GameStartInfo {
|
||||
private String boardName;
|
||||
private List<Player> playerList;
|
||||
private String playerName;
|
||||
|
||||
/**
|
||||
* Empty initialization method used by kryo
|
||||
*/
|
||||
public GameStartInfo() {}
|
||||
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the board to be used
|
||||
* @param boardName The name of the board to be used, with extension
|
||||
@ -37,7 +46,8 @@ public class GameStartInfo {
|
||||
* @param boardName The name of the board to be used, with extension
|
||||
* @param playerList List of players for the game
|
||||
*/
|
||||
public GameStartInfo(String boardName, List<Player> playerList) {
|
||||
public GameStartInfo(String boardName, List<Player> playerList,String name) {
|
||||
this.playerName=name;
|
||||
this.boardName = boardName;
|
||||
this.playerList = playerList;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.GameState;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyClient;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyServer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -74,4 +76,10 @@ public interface IDrawableGame {
|
||||
*/
|
||||
String getWinningPlayerName();
|
||||
|
||||
|
||||
RoboRallyClient getClient();
|
||||
|
||||
void setClient(RoboRallyClient client);
|
||||
|
||||
void setServer(RoboRallyServer server);
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import com.esotericsoftware.kryonet.Client;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
import inf112.fiasko.roborally.element_properties.Action;
|
||||
import inf112.fiasko.roborally.element_properties.Direction;
|
||||
import inf112.fiasko.roborally.element_properties.GameState;
|
||||
import inf112.fiasko.roborally.element_properties.Position;
|
||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||
import inf112.fiasko.roborally.element_properties.TileType;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyClient;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyServer;
|
||||
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
||||
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
|
||||
|
||||
@ -30,8 +34,22 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
private final boolean host;
|
||||
private Deck<ProgrammingCard> mainDeck;
|
||||
private GameState gameState = GameState.INITIAL_SETUP;
|
||||
private String nameOfPlayer;
|
||||
private RoboRallyClient client;
|
||||
private RoboRallyServer server;
|
||||
private String winningPlayerName;
|
||||
|
||||
|
||||
|
||||
public String getNameOfPlayer() {
|
||||
return nameOfPlayer;
|
||||
}
|
||||
|
||||
public void setNameOfPlayer(String nameOfPlayer) {
|
||||
this.nameOfPlayer = nameOfPlayer;
|
||||
}
|
||||
|
||||
|
||||
public String getWinningPlayerName() {
|
||||
return winningPlayerName;
|
||||
}
|
||||
@ -58,11 +76,28 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
this.gameState = gameState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoboRallyClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClient(RoboRallyClient client) {
|
||||
this.client=client;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServer(RoboRallyServer server) {
|
||||
this.server=server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new robo rally game
|
||||
* @param debug Whether to start the game in debugging mode
|
||||
*/
|
||||
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, boolean debug) {
|
||||
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, boolean debug, String name) {
|
||||
this.nameOfPlayer = name;
|
||||
this.host = host;
|
||||
this.playerList = playerList;
|
||||
if (debug) {
|
||||
@ -75,7 +110,8 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
/**
|
||||
* Instantiates a new robo rally game
|
||||
*/
|
||||
public RoboRallyGame(List<Player> playerList, String boardName,boolean host) {
|
||||
public RoboRallyGame(List<Player> playerList, String boardName,boolean host,String nameOfPlayer) {
|
||||
this.nameOfPlayer = nameOfPlayer;
|
||||
this.host = host;
|
||||
this.playerList = playerList;
|
||||
initializeGame(boardName);
|
||||
@ -194,6 +230,14 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
|
||||
TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
|
||||
}
|
||||
private Player getPlayerFromName(String name){
|
||||
for (Player player:playerList) {
|
||||
if(player.getName().equals(name)){
|
||||
return player;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all the steps of one turn in the game
|
||||
@ -226,15 +270,26 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
gameBoard.executePowerdown();
|
||||
if (host) {
|
||||
distributeProgrammingCardsToPlayers();
|
||||
for (Connection connection: server.getPlayerNames().keySet()) {
|
||||
String playerName = server.getPlayerNames().get(connection);
|
||||
Player player = getPlayerFromName(playerName);
|
||||
if(player.getPlayerDeck()!=null) {
|
||||
server.sendToClient(connection, player.getPlayerDeck());
|
||||
}
|
||||
}
|
||||
}
|
||||
setGameState(GameState.CHOOSING_CARDS);
|
||||
// TODO: Make program for this player, if not in power down
|
||||
// TODO: Ask player for new power down
|
||||
// Run the phases of the game
|
||||
runPhase(1);
|
||||
runPhase(2);
|
||||
runPhase(3);
|
||||
runPhase(4);
|
||||
runPhase(5);
|
||||
while (getGameState()==GameState.CHOOSING_CARDS) {
|
||||
//loops waiting for the player to be done choosing their cards
|
||||
}
|
||||
runPhase(1);
|
||||
runPhase(2);
|
||||
runPhase(3);
|
||||
runPhase(4);
|
||||
runPhase(5);
|
||||
|
||||
// Repair robots on repair tiles
|
||||
repairAllRobotsOnRepairTiles();
|
||||
|
@ -12,7 +12,7 @@ public class RoboRallyGameTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false);
|
||||
game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false, "Jonny");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user