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:
Kristian Knarvik 2020-04-16 10:03:52 +02:00
parent fa0d53524c
commit f46d2f4e29
11 changed files with 59 additions and 71 deletions

View File

@ -6,13 +6,13 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import inf112.fiasko.roborally.networking.RoboRallyClient; import inf112.fiasko.roborally.networking.RoboRallyClient;
import inf112.fiasko.roborally.networking.RoboRallyServer; import inf112.fiasko.roborally.networking.RoboRallyServer;
import inf112.fiasko.roborally.objects.IDrawableGame; import inf112.fiasko.roborally.objects.IRoboRallyGame;
public class RoboRallyWrapper extends Game { public class RoboRallyWrapper extends Game {
public SpriteBatch batch; public SpriteBatch batch;
public BitmapFont font; public BitmapFont font;
public ScreenManager screenManager; public ScreenManager screenManager;
public IDrawableGame roboRallyGame; public IRoboRallyGame roboRallyGame;
public RoboRallyServer server; public RoboRallyServer server;
public RoboRallyClient client; public RoboRallyClient client;

View File

@ -14,8 +14,8 @@ 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.objects.IDrawableGame;
import inf112.fiasko.roborally.objects.IDrawableObject; import inf112.fiasko.roborally.objects.IDrawableObject;
import inf112.fiasko.roborally.objects.IRoboRallyGame;
import inf112.fiasko.roborally.utility.IOUtil; import inf112.fiasko.roborally.utility.IOUtil;
import inf112.fiasko.roborally.utility.TextureConverterUtil; import inf112.fiasko.roborally.utility.TextureConverterUtil;
@ -27,7 +27,7 @@ import java.util.List;
public class BoardActiveScreen extends AbstractScreen implements InputProcessor { public class BoardActiveScreen extends AbstractScreen implements InputProcessor {
private final RoboRallyWrapper roboRallyWrapper; private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera; private final OrthographicCamera camera;
private IDrawableGame debugGame; private IRoboRallyGame debugGame;
private final int tileDimensions = 64; private final int tileDimensions = 64;
private float cameraZoom = 1; private float cameraZoom = 1;
@ -97,7 +97,7 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
@Override @Override
public boolean keyUp(int keyCode) { public boolean keyUp(int keyCode) {
if (keyCode == Input.Keys.HOME) { if (keyCode == Input.Keys.HOME) {
IDrawableGame temp = roboRallyWrapper.roboRallyGame; IRoboRallyGame temp = roboRallyWrapper.roboRallyGame;
roboRallyWrapper.roboRallyGame = debugGame; roboRallyWrapper.roboRallyGame = debugGame;
this.debugGame = temp; this.debugGame = temp;
return true; return true;

View File

@ -45,19 +45,13 @@ 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 != null && roboRallyWrapper.roboRallyGame.getGameState() != initialGameState ) { if (roboRallyWrapper.roboRallyGame != null && roboRallyWrapper.roboRallyGame.getGameState() != initialGameState) {
handleScreenChange(); handleScreenChange();
} }
} }
private void handleScreenChange() { private void handleScreenChange() {
switch (initialGameState) { switch (initialGameState) {
case BEGINNING_OF_GAME:
if(roboRallyWrapper.roboRallyGame.getClient()==null){
roboRallyWrapper.roboRallyGame.setClient(roboRallyWrapper.client);
roboRallyWrapper.roboRallyGame.setServer(roboRallyWrapper.server);
}
case SENDING_CARDS: case SENDING_CARDS:
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper));
break; break;

View File

@ -32,7 +32,7 @@ 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,info.getPlayerName()); wrapper.server != null, info.getPlayerName(), wrapper.client, wrapper.server);
wrapper.setScreen(wrapper.screenManager.getLoadingScreen(wrapper)); wrapper.setScreen(wrapper.screenManager.getLoadingScreen(wrapper));
} }
else if(object instanceof ProgrammingCardDeck){ else if(object instanceof ProgrammingCardDeck){

View File

@ -19,7 +19,7 @@ class RoboRallyServerListener extends Listener {
private Connection host; private Connection host;
private final Map<Connection, RobotID> clients; private final Map<Connection, RobotID> clients;
private final Map<Connection, String> playerNames; private final Map<Connection, String> playerNames;
private List<Connection> deadPlayers; private final List<Connection> deadPlayers;
/** /**
* Instantiates a new Robo Rally server listener * Instantiates a new Robo Rally server listener

View File

@ -1,9 +1,5 @@
package inf112.fiasko.roborally.objects; 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; import java.util.List;
/** /**
@ -58,28 +54,4 @@ public interface IDrawableGame {
* @return A list of all robots to draw * @return A list of all robots to draw
*/ */
List<Robot> getRobotsToDraw(); 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);
} }

View File

@ -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();
}

View File

@ -0,0 +1,3 @@
package inf112.fiasko.roborally.objects;
public interface IRoboRallyGame extends IDrawableGame, IInteractableGame {}

View File

@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* This class represent a game which is drawable using libgdx * This class represent a game which is drawable using libgdx
*/ */
public class RoboRallyGame implements IDrawableGame { public class RoboRallyGame implements IRoboRallyGame {
private Board gameBoard; private Board gameBoard;
private List<BoardElementContainer<Tile>> cogwheels; private List<BoardElementContainer<Tile>> cogwheels;
private List<BoardElementContainer<Tile>> conveyorBelts; private List<BoardElementContainer<Tile>> conveyorBelts;
@ -33,19 +33,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.BEGINNING_OF_GAME; private GameState gameState = GameState.BEGINNING_OF_GAME;
private String nameOfPlayer; private String playerName;
private RoboRallyClient client; private final RoboRallyClient client;
private RoboRallyServer server; private RoboRallyServer server;
private String winningPlayerName; private String winningPlayerName;
public String getNameOfPlayer() { public String getPlayerName() {
return nameOfPlayer; return playerName;
} }
public void setNameOfPlayer(String nameOfPlayer) { public void setPlayerName(String playerName) {
this.nameOfPlayer = nameOfPlayer; this.playerName = playerName;
} }
@ -75,30 +75,17 @@ public class RoboRallyGame implements IDrawableGame {
this.gameState = gameState; 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 * 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, String name) { public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String name, RoboRallyClient client,
this.nameOfPlayer = name; RoboRallyServer server, boolean debug) {
this.playerName = name;
this.host = host; this.host = host;
this.playerList = playerList; this.playerList = playerList;
this.client = client;
this.server = server;
if (debug) { if (debug) {
initializeDebugMode(); initializeDebugMode();
} else { } else {
@ -109,10 +96,13 @@ public class RoboRallyGame implements IDrawableGame {
/** /**
* Instantiates a new robo rally game * Instantiates a new robo rally game
*/ */
public RoboRallyGame(List<Player> playerList, String boardName,boolean host,String nameOfPlayer) { public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName, RoboRallyClient client,
this.nameOfPlayer = nameOfPlayer; RoboRallyServer server) {
this.playerName = playerName;
this.host = host; this.host = host;
this.playerList = playerList; this.playerList = playerList;
this.client = client;
this.server = server;
initializeGame(boardName); initializeGame(boardName);
} }
@ -275,7 +265,7 @@ public class RoboRallyGame implements IDrawableGame {
for (Connection connection: server.getPlayerNames().keySet()) { for (Connection connection: server.getPlayerNames().keySet()) {
String playerName = server.getPlayerNames().get(connection); String playerName = server.getPlayerNames().get(connection);
Player player = getPlayerFromName(playerName); Player player = getPlayerFromName(playerName);
if(player.getPlayerDeck()!=null) { if (player != null && player.getPlayerDeck() != null) {
server.sendToClient(connection, player.getPlayerDeck()); server.sendToClient(connection, player.getPlayerDeck());
} }
} }

View File

@ -1,6 +1,7 @@
package inf112.fiasko.roborally.utility; package inf112.fiasko.roborally.utility;
import com.esotericsoftware.kryo.Kryo; import com.esotericsoftware.kryo.Kryo;
import inf112.fiasko.roborally.elementproperties.Action;
import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.elementproperties.RobotID;
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;
@ -29,5 +30,6 @@ public final class NetworkUtil {
kryo.register(Player.class); kryo.register(Player.class);
kryo.register(RobotID.class); kryo.register(RobotID.class);
kryo.register(ProgrammingCardDeck.class); kryo.register(ProgrammingCardDeck.class);
kryo.register(Action.class);
} }
} }

View File

@ -12,7 +12,8 @@ public class RoboRallyGameTest {
@Before @Before
public void setUp() { public void setUp() {
game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false, "Player1"); game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false, "Player1",
null, null);
} }
@Test @Test