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
This commit is contained in:
commit
9f716cc9a3
@ -16,5 +16,7 @@ public enum GameState {
|
|||||||
//Indicates that the user is in the process of choosing whether to power down
|
//Indicates that the user is in the process of choosing whether to power down
|
||||||
CHOOSING_POWER_DOWN,
|
CHOOSING_POWER_DOWN,
|
||||||
//Indicates that the user is in the process of choosing whether to stay in power down
|
//Indicates that the user is in the process of choosing whether to stay in power down
|
||||||
CHOOSING_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
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import inf112.fiasko.roborally.game_wrapper.screens.StartMenuScreen;
|
|||||||
*/
|
*/
|
||||||
public class ScreenManager {
|
public class ScreenManager {
|
||||||
private BoardActiveScreen boardActiveScreen;
|
private BoardActiveScreen boardActiveScreen;
|
||||||
private CardChoiceScreen cardChoiceScreen;
|
|
||||||
private PowerDownScreen powerDownScreen;
|
private PowerDownScreen powerDownScreen;
|
||||||
private LoadingScreen loadingScreen;
|
private LoadingScreen loadingScreen;
|
||||||
private UsernameScreen usernameScreen;
|
private UsernameScreen usernameScreen;
|
||||||
@ -103,15 +102,5 @@ public class ScreenManager {
|
|||||||
return boardActiveScreen;
|
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.game_wrapper.SimpleButton;
|
||||||
import inf112.fiasko.roborally.objects.IDeck;
|
import inf112.fiasko.roborally.objects.IDeck;
|
||||||
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
||||||
|
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
||||||
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
|
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -44,12 +45,14 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
|||||||
private final int maxCards;
|
private final int maxCards;
|
||||||
private final Stage stage;
|
private final Stage stage;
|
||||||
private final InputMultiplexer inputMultiplexer;
|
private final InputMultiplexer inputMultiplexer;
|
||||||
|
private ProgrammingCardDeck deck;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new card choice screen
|
* Instantiates a new card choice screen
|
||||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this 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;
|
this.roboRallyWrapper = roboRallyWrapper;
|
||||||
camera = new OrthographicCamera();
|
camera = new OrthographicCamera();
|
||||||
int applicationWidth = 600;
|
int applicationWidth = 600;
|
||||||
@ -89,6 +92,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
|||||||
stage.setViewport(viewport);
|
stage.setViewport(viewport);
|
||||||
inputMultiplexer.addProcessor(this);
|
inputMultiplexer.addProcessor(this);
|
||||||
inputMultiplexer.addProcessor(stage);
|
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();
|
roboRallyWrapper.batch.end();
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
//TODO: Allow to set any condition and next screen
|
//TODO: Allow to set any condition and next screen
|
||||||
if (roboRallyWrapper.roboRallyGame.getGameState() != initialGameState) {
|
if (roboRallyWrapper.roboRallyGame != null && roboRallyWrapper.roboRallyGame.getGameState() != initialGameState ) {
|
||||||
handleScreenChange();
|
handleScreenChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void 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
|
@Override
|
||||||
@ -64,7 +68,12 @@ public class LoadingScreen extends AbstractScreen {
|
|||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
startTime = System.currentTimeMillis();
|
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.networking.containers.GameStartInfo;
|
||||||
import inf112.fiasko.roborally.objects.Player;
|
import inf112.fiasko.roborally.objects.Player;
|
||||||
import inf112.fiasko.roborally.utility.IOUtil;
|
import inf112.fiasko.roborally.utility.IOUtil;
|
||||||
|
import com.esotericsoftware.kryonet.Connection;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This screen allows the host to wait for players to join
|
* This screen allows the host to wait for players to join
|
||||||
@ -44,9 +46,13 @@ public class LobbyScreen extends AbstractScreen {
|
|||||||
startGameButton.addListener(new InputListener() {
|
startGameButton.addListener(new InputListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
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.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));
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
|
||||||
return true;//her we do stuff
|
return true;//her we do stuff
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,10 @@ import com.esotericsoftware.kryonet.Client;
|
|||||||
import com.esotericsoftware.kryonet.Connection;
|
import com.esotericsoftware.kryonet.Connection;
|
||||||
import com.esotericsoftware.kryonet.Listener;
|
import com.esotericsoftware.kryonet.Listener;
|
||||||
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
|
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.ErrorResponse;
|
||||||
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
|
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
|
||||||
|
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
||||||
import inf112.fiasko.roborally.objects.RoboRallyGame;
|
import inf112.fiasko.roborally.objects.RoboRallyGame;
|
||||||
import inf112.fiasko.roborally.utility.NetworkUtil;
|
import inf112.fiasko.roborally.utility.NetworkUtil;
|
||||||
|
|
||||||
@ -16,7 +18,6 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class RoboRallyClient {
|
public class RoboRallyClient {
|
||||||
private final Client client;
|
private final Client client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Robo Rally client
|
* Instantiates a new Robo Rally client
|
||||||
* @param ipAddress The ip address of the server to connect to
|
* @param ipAddress The ip address of the server to connect to
|
||||||
@ -64,7 +65,10 @@ class RoboRallyClientListener extends Listener {
|
|||||||
} else if (object instanceof GameStartInfo) {
|
} else if (object instanceof GameStartInfo) {
|
||||||
GameStartInfo info = (GameStartInfo) object;
|
GameStartInfo info = (GameStartInfo) object;
|
||||||
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
|
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) {
|
public void sendToAllClients(Object object) {
|
||||||
server.sendToAllTCP(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
|
* This listener handles all sending and responses for the server
|
||||||
*/
|
*/
|
||||||
|
@ -10,12 +10,21 @@ import java.util.List;
|
|||||||
public class GameStartInfo {
|
public class GameStartInfo {
|
||||||
private String boardName;
|
private String boardName;
|
||||||
private List<Player> playerList;
|
private List<Player> playerList;
|
||||||
|
private String playerName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty initialization method used by kryo
|
* Empty initialization method used by kryo
|
||||||
*/
|
*/
|
||||||
public GameStartInfo() {}
|
public GameStartInfo() {}
|
||||||
|
|
||||||
|
public void setPlayerName(String playerName) {
|
||||||
|
this.playerName = playerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlayerName() {
|
||||||
|
return playerName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the name of the board to be used
|
* Sets the name of the board to be used
|
||||||
* @param boardName The name of the board to be used, with extension
|
* @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 boardName The name of the board to be used, with extension
|
||||||
* @param playerList List of players for the game
|
* @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.boardName = boardName;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package inf112.fiasko.roborally.objects;
|
package inf112.fiasko.roborally.objects;
|
||||||
|
|
||||||
import inf112.fiasko.roborally.element_properties.GameState;
|
import inf112.fiasko.roborally.element_properties.GameState;
|
||||||
|
import inf112.fiasko.roborally.networking.RoboRallyClient;
|
||||||
|
import inf112.fiasko.roborally.networking.RoboRallyServer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -63,4 +65,10 @@ public interface IDrawableGame {
|
|||||||
*/
|
*/
|
||||||
GameState getGameState();
|
GameState getGameState();
|
||||||
|
|
||||||
|
|
||||||
|
RoboRallyClient getClient();
|
||||||
|
|
||||||
|
void setClient(RoboRallyClient client);
|
||||||
|
|
||||||
|
void setServer(RoboRallyServer server);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package inf112.fiasko.roborally.objects;
|
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.Action;
|
||||||
import inf112.fiasko.roborally.element_properties.Direction;
|
import inf112.fiasko.roborally.element_properties.Direction;
|
||||||
import inf112.fiasko.roborally.element_properties.GameState;
|
import inf112.fiasko.roborally.element_properties.GameState;
|
||||||
import inf112.fiasko.roborally.element_properties.Position;
|
import inf112.fiasko.roborally.element_properties.Position;
|
||||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||||
import inf112.fiasko.roborally.element_properties.TileType;
|
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.BoardLoaderUtil;
|
||||||
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
|
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
|
||||||
|
|
||||||
@ -30,6 +34,19 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
private final boolean host;
|
private final boolean host;
|
||||||
private Deck<ProgrammingCard> mainDeck;
|
private Deck<ProgrammingCard> mainDeck;
|
||||||
private GameState gameState = GameState.INITIAL_SETUP;
|
private GameState gameState = GameState.INITIAL_SETUP;
|
||||||
|
private String nameOfPlayer;
|
||||||
|
private RoboRallyClient client;
|
||||||
|
private RoboRallyServer server;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getNameOfPlayer() {
|
||||||
|
return nameOfPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameOfPlayer(String nameOfPlayer) {
|
||||||
|
this.nameOfPlayer = nameOfPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the gameState of the game
|
* Returns the gameState of the game
|
||||||
@ -39,6 +56,22 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
return gameState;
|
return 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the gameState of the game
|
* Sets the gameState of the game
|
||||||
* @param gameState the gameState
|
* @param gameState the gameState
|
||||||
@ -51,7 +84,8 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
* Instantiates a new robo rally game
|
* Instantiates a new robo rally game
|
||||||
* @param debug Whether to start the game in debugging mode
|
* @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.host = host;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@ -60,11 +94,11 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
initializeGame(boardName);
|
initializeGame(boardName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new robo rally game
|
* 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.host = host;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
initializeGame(boardName);
|
initializeGame(boardName);
|
||||||
@ -183,6 +217,14 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
|
repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
|
||||||
TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
|
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
|
* Runs all the steps of one turn in the game
|
||||||
@ -215,15 +257,26 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
gameBoard.executePowerdown();
|
gameBoard.executePowerdown();
|
||||||
if (host) {
|
if (host) {
|
||||||
distributeProgrammingCardsToPlayers();
|
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: Make program for this player, if not in power down
|
||||||
// TODO: Ask player for new power down
|
// TODO: Ask player for new power down
|
||||||
// Run the phases of the game
|
// Run the phases of the game
|
||||||
runPhase(1);
|
while (getGameState()==GameState.CHOOSING_CARDS) {
|
||||||
runPhase(2);
|
//loops waiting for the player to be done choosing their cards
|
||||||
runPhase(3);
|
}
|
||||||
runPhase(4);
|
runPhase(1);
|
||||||
runPhase(5);
|
runPhase(2);
|
||||||
|
runPhase(3);
|
||||||
|
runPhase(4);
|
||||||
|
runPhase(5);
|
||||||
|
|
||||||
// Repair robots on repair tiles
|
// Repair robots on repair tiles
|
||||||
repairAllRobotsOnRepairTiles();
|
repairAllRobotsOnRepairTiles();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user