mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Splitter opp interfacer for tegning og intragering
Endrer ting slik at spillet får vite om server og klient ved initialisering Registerer Action for kryo Oppdaterer konstruktør i RoboRallyGameTest
This commit is contained in:
parent
fa0d53524c
commit
f46d2f4e29
@ -6,13 +6,13 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyClient;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyServer;
|
||||
import inf112.fiasko.roborally.objects.IDrawableGame;
|
||||
import inf112.fiasko.roborally.objects.IRoboRallyGame;
|
||||
|
||||
public class RoboRallyWrapper extends Game {
|
||||
public SpriteBatch batch;
|
||||
public BitmapFont font;
|
||||
public ScreenManager screenManager;
|
||||
public IDrawableGame roboRallyGame;
|
||||
public IRoboRallyGame roboRallyGame;
|
||||
public RoboRallyServer server;
|
||||
public RoboRallyClient client;
|
||||
|
||||
|
@ -14,8 +14,8 @@ import com.badlogic.gdx.utils.viewport.ExtendViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
import inf112.fiasko.roborally.elementproperties.GameState;
|
||||
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
|
||||
import inf112.fiasko.roborally.objects.IDrawableGame;
|
||||
import inf112.fiasko.roborally.objects.IDrawableObject;
|
||||
import inf112.fiasko.roborally.objects.IRoboRallyGame;
|
||||
import inf112.fiasko.roborally.utility.IOUtil;
|
||||
import inf112.fiasko.roborally.utility.TextureConverterUtil;
|
||||
|
||||
@ -27,7 +27,7 @@ import java.util.List;
|
||||
public class BoardActiveScreen extends AbstractScreen implements InputProcessor {
|
||||
private final RoboRallyWrapper roboRallyWrapper;
|
||||
private final OrthographicCamera camera;
|
||||
private IDrawableGame debugGame;
|
||||
private IRoboRallyGame debugGame;
|
||||
|
||||
private final int tileDimensions = 64;
|
||||
private float cameraZoom = 1;
|
||||
@ -97,7 +97,7 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
@Override
|
||||
public boolean keyUp(int keyCode) {
|
||||
if (keyCode == Input.Keys.HOME) {
|
||||
IDrawableGame temp = roboRallyWrapper.roboRallyGame;
|
||||
IRoboRallyGame temp = roboRallyWrapper.roboRallyGame;
|
||||
roboRallyWrapper.roboRallyGame = debugGame;
|
||||
this.debugGame = temp;
|
||||
return true;
|
||||
|
@ -52,12 +52,6 @@ public class LoadingScreen extends AbstractScreen {
|
||||
|
||||
private void handleScreenChange() {
|
||||
switch (initialGameState) {
|
||||
case BEGINNING_OF_GAME:
|
||||
if(roboRallyWrapper.roboRallyGame.getClient()==null){
|
||||
roboRallyWrapper.roboRallyGame.setClient(roboRallyWrapper.client);
|
||||
roboRallyWrapper.roboRallyGame.setServer(roboRallyWrapper.server);
|
||||
}
|
||||
|
||||
case SENDING_CARDS:
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper));
|
||||
break;
|
||||
|
@ -32,7 +32,7 @@ class RoboRallyClientListener extends Listener {
|
||||
} else if (object instanceof GameStartInfo) {
|
||||
GameStartInfo info = (GameStartInfo) object;
|
||||
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
|
||||
wrapper.server != null,info.getPlayerName());
|
||||
wrapper.server != null, info.getPlayerName(), wrapper.client, wrapper.server);
|
||||
wrapper.setScreen(wrapper.screenManager.getLoadingScreen(wrapper));
|
||||
}
|
||||
else if(object instanceof ProgrammingCardDeck){
|
||||
|
@ -19,7 +19,7 @@ class RoboRallyServerListener extends Listener {
|
||||
private Connection host;
|
||||
private final Map<Connection, RobotID> clients;
|
||||
private final Map<Connection, String> playerNames;
|
||||
private List<Connection> deadPlayers;
|
||||
private final List<Connection> deadPlayers;
|
||||
|
||||
/**
|
||||
* Instantiates a new Robo Rally server listener
|
||||
|
@ -1,9 +1,5 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.elementproperties.GameState;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyClient;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyServer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -58,28 +54,4 @@ public interface IDrawableGame {
|
||||
* @return A list of all robots to draw
|
||||
*/
|
||||
List<Robot> getRobotsToDraw();
|
||||
|
||||
/**
|
||||
* Gets the current state og the game
|
||||
* @return The state the game is currently in
|
||||
*/
|
||||
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();
|
||||
|
||||
void setClient(RoboRallyClient client);
|
||||
|
||||
void setServer(RoboRallyServer server);
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.elementproperties.GameState;
|
||||
|
||||
/**
|
||||
* This interface describes
|
||||
*/
|
||||
public interface IInteractableGame {
|
||||
/**
|
||||
* Gets the current state og the game
|
||||
* @return The state the game is currently in
|
||||
*/
|
||||
GameState getGameState();
|
||||
|
||||
/**
|
||||
* Sets the state of the game
|
||||
* @param gameState The new state of the game
|
||||
*/
|
||||
void setGameState(GameState gameState);
|
||||
|
||||
/**
|
||||
* Gets the name of the player who won
|
||||
* @return A string of the player name
|
||||
*/
|
||||
String getWinningPlayerName();
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
public interface IRoboRallyGame extends IDrawableGame, IInteractableGame {}
|
@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* This class represent a game which is drawable using libgdx
|
||||
*/
|
||||
public class RoboRallyGame implements IDrawableGame {
|
||||
public class RoboRallyGame implements IRoboRallyGame {
|
||||
private Board gameBoard;
|
||||
private List<BoardElementContainer<Tile>> cogwheels;
|
||||
private List<BoardElementContainer<Tile>> conveyorBelts;
|
||||
@ -33,19 +33,19 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
private final boolean host;
|
||||
private Deck<ProgrammingCard> mainDeck;
|
||||
private GameState gameState = GameState.BEGINNING_OF_GAME;
|
||||
private String nameOfPlayer;
|
||||
private RoboRallyClient client;
|
||||
private String playerName;
|
||||
private final RoboRallyClient client;
|
||||
private RoboRallyServer server;
|
||||
private String winningPlayerName;
|
||||
|
||||
|
||||
|
||||
public String getNameOfPlayer() {
|
||||
return nameOfPlayer;
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setNameOfPlayer(String nameOfPlayer) {
|
||||
this.nameOfPlayer = nameOfPlayer;
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
|
||||
@ -75,30 +75,17 @@ 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, String name) {
|
||||
this.nameOfPlayer = name;
|
||||
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String name, RoboRallyClient client,
|
||||
RoboRallyServer server, boolean debug) {
|
||||
this.playerName = name;
|
||||
this.host = host;
|
||||
this.playerList = playerList;
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
if (debug) {
|
||||
initializeDebugMode();
|
||||
} else {
|
||||
@ -109,10 +96,13 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
/**
|
||||
* Instantiates a new robo rally game
|
||||
*/
|
||||
public RoboRallyGame(List<Player> playerList, String boardName,boolean host,String nameOfPlayer) {
|
||||
this.nameOfPlayer = nameOfPlayer;
|
||||
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName, RoboRallyClient client,
|
||||
RoboRallyServer server) {
|
||||
this.playerName = playerName;
|
||||
this.host = host;
|
||||
this.playerList = playerList;
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
initializeGame(boardName);
|
||||
}
|
||||
|
||||
@ -275,7 +265,7 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
for (Connection connection: server.getPlayerNames().keySet()) {
|
||||
String playerName = server.getPlayerNames().get(connection);
|
||||
Player player = getPlayerFromName(playerName);
|
||||
if(player.getPlayerDeck()!=null) {
|
||||
if (player != null && player.getPlayerDeck() != null) {
|
||||
server.sendToClient(connection, player.getPlayerDeck());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package inf112.fiasko.roborally.utility;
|
||||
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import inf112.fiasko.roborally.elementproperties.Action;
|
||||
import inf112.fiasko.roborally.elementproperties.RobotID;
|
||||
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
|
||||
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
|
||||
@ -29,5 +30,6 @@ public final class NetworkUtil {
|
||||
kryo.register(Player.class);
|
||||
kryo.register(RobotID.class);
|
||||
kryo.register(ProgrammingCardDeck.class);
|
||||
kryo.register(Action.class);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ public class RoboRallyGameTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false, "Player1");
|
||||
game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false, "Player1",
|
||||
null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user