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
1dab8c6e1d
@ -22,5 +22,10 @@ public enum GameState {
|
||||
//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
|
||||
GAME_IS_WON,
|
||||
|
||||
JUST_BEFORE_CHOOSING_CARDS,
|
||||
|
||||
LOADING
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,15 @@ public class ScreenManager {
|
||||
private IPAddressScreen ipAddressScreen;
|
||||
private LobbyScreen lobbyScreen;
|
||||
private WinnerScreen winnerScreen;
|
||||
private CardChoiceScreen cardChoiceScreen;
|
||||
|
||||
|
||||
public synchronized CardChoiceScreen getCardChoiceScreen(RoboRallyWrapper roboRallyWrapper) {
|
||||
if (this.cardChoiceScreen == null) {
|
||||
this.cardChoiceScreen = new CardChoiceScreen(roboRallyWrapper);
|
||||
}
|
||||
return cardChoiceScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the winner screen
|
||||
|
@ -80,6 +80,9 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.GAME_IS_WON) {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getWinnerScreen(roboRallyWrapper));
|
||||
}
|
||||
else if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_STAY_IN_POWER_DOWN){
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
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.elementproperties.GameState;
|
||||
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
|
||||
import inf112.fiasko.roborally.gamewrapper.SimpleButton;
|
||||
import inf112.fiasko.roborally.objects.IDeck;
|
||||
@ -51,8 +52,8 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
* Instantiates a new card choice screen
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper, ProgrammingCardDeck deck) {
|
||||
this.deck = deck;
|
||||
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
this.deck = roboRallyWrapper.roboRallyGame.getPlayerHand();
|
||||
this.roboRallyWrapper = roboRallyWrapper;
|
||||
camera = new OrthographicCamera();
|
||||
int applicationWidth = 600;
|
||||
@ -66,12 +67,13 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
inputMultiplexer = new InputMultiplexer();
|
||||
|
||||
try {
|
||||
generateCards();
|
||||
generateCards(deck);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.chosenCards = new ArrayList<>();
|
||||
this.maxCards = 5;
|
||||
|
||||
this.maxCards = roboRallyWrapper.roboRallyGame.getProgramSize();
|
||||
stage = new Stage();
|
||||
|
||||
TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton();
|
||||
@ -83,7 +85,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
if (chosenCards.size() == maxCards) {
|
||||
System.out.println("Lock cards!");
|
||||
|
||||
roboRallyWrapper.roboRallyGame.setProgram(getCards());
|
||||
roboRallyWrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN);
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -93,16 +98,19 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
inputMultiplexer.addProcessor(this);
|
||||
inputMultiplexer.addProcessor(stage);
|
||||
}
|
||||
private List<ProgrammingCard> getCards(){
|
||||
List<ProgrammingCard> program = new ArrayList<>();
|
||||
chosenCards.forEach((cardRectangle -> program.add(cardRectangle.card)));
|
||||
return program;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates some placeholder cards for testing
|
||||
* @throws IOException If programming cards cannot be loaded
|
||||
*/
|
||||
private void generateCards() throws IOException {
|
||||
IDeck<ProgrammingCard> deck = DeckLoaderUtil.loadProgrammingCardsDeck();
|
||||
deck.shuffle();
|
||||
private void generateCards(ProgrammingCardDeck deck) throws IOException {
|
||||
//Get 9 programming cards
|
||||
List<ProgrammingCard> cardList = deck.getCards().subList(0, 9);
|
||||
List<ProgrammingCard> cardList = deck.getCards();
|
||||
float cardWidth = viewport.getWorldWidth() / 3;
|
||||
float cardHeight = (viewport.getWorldHeight() - 30) / 3;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
|
@ -43,19 +43,26 @@ public class LoadingScreen extends AbstractScreen {
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Loading...", applicationWidth/2f-380/2f,
|
||||
applicationHeight / 2f,380, 1, true);
|
||||
roboRallyWrapper.batch.end();
|
||||
long time = System.currentTimeMillis();
|
||||
//TODO: Allow to set any condition and next screen
|
||||
if (roboRallyWrapper.roboRallyGame != null && roboRallyWrapper.roboRallyGame.getGameState() != initialGameState) {
|
||||
|
||||
//if (roboRallyWrapper.roboRallyGame != null){
|
||||
// System.out.println(roboRallyWrapper.roboRallyGame.getGameState());
|
||||
//}
|
||||
if (roboRallyWrapper.roboRallyGame != null && roboRallyWrapper.roboRallyGame.getGameState() != GameState.LOADING) {
|
||||
handleScreenChange();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleScreenChange() {
|
||||
switch (initialGameState) {
|
||||
case SENDING_CARDS:
|
||||
switch (roboRallyWrapper.roboRallyGame.getGameState()) {
|
||||
case RUNNING_PROGRAMS:
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper));
|
||||
break;
|
||||
}
|
||||
case INITIAL_SETUP:
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
||||
break;
|
||||
case CHOOSING_CARDS:
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getCardChoiceScreen(this.roboRallyWrapper));
|
||||
break; }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,8 +9,15 @@ 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.elementproperties.Action;
|
||||
import inf112.fiasko.roborally.elementproperties.GameState;
|
||||
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
|
||||
import inf112.fiasko.roborally.gamewrapper.SimpleButton;
|
||||
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This screen is used for asking players whether they want to power down
|
||||
@ -42,8 +49,8 @@ public class PowerDownScreen extends AbstractScreen {
|
||||
powerDownButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
|
||||
return true;//her we do stuff
|
||||
sendPowerdownStatus(true);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -68,10 +75,29 @@ public class PowerDownScreen extends AbstractScreen {
|
||||
stage.draw();
|
||||
|
||||
if (elapsedTime > 10) {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
||||
sendPowerdownStatus( false);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPowerdownStatus (boolean bool){
|
||||
if(roboRallyWrapper.roboRallyGame.getGameState()== GameState.CHOOSING_STAY_IN_POWER_DOWN){
|
||||
roboRallyWrapper.roboRallyGame.setGameState(GameState.TURN_CLEANUP);
|
||||
roboRallyWrapper.client.sendElement(bool);
|
||||
}
|
||||
else if (roboRallyWrapper.roboRallyGame.getGameState()==GameState.CHOOSING_POWER_DOWN){
|
||||
|
||||
roboRallyWrapper.roboRallyGame.setGameState(GameState.LOADING);
|
||||
|
||||
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(bool,
|
||||
roboRallyWrapper.roboRallyGame.getProgram()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
viewport.update(width, height);
|
||||
|
@ -30,8 +30,9 @@ public class RoboRallyClient {
|
||||
* Sends something to the server
|
||||
* @param object The object to send to the server
|
||||
*/
|
||||
public void sendElement(Object object) {
|
||||
client.sendTCP(object);
|
||||
public void sendElement(Object object) {try{
|
||||
client.sendTCP(object);}
|
||||
catch(Exception e){e.printStackTrace();}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,18 @@ package inf112.fiasko.roborally.networking;
|
||||
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
import com.esotericsoftware.kryonet.Listener;
|
||||
import inf112.fiasko.roborally.elementproperties.GameState;
|
||||
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.CardChoiceScreen;
|
||||
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
|
||||
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
|
||||
import inf112.fiasko.roborally.networking.containers.PowerdownContainer;
|
||||
import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
||||
import inf112.fiasko.roborally.objects.RoboRallyGame;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* This listener handles all receiving from the server
|
||||
*/
|
||||
@ -33,11 +38,22 @@ class RoboRallyClientListener extends Listener {
|
||||
GameStartInfo info = (GameStartInfo) object;
|
||||
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
|
||||
wrapper.server != null, info.getPlayerName(), wrapper.client, wrapper.server);
|
||||
wrapper.setScreen(wrapper.screenManager.getLoadingScreen(wrapper));
|
||||
}
|
||||
else if(object instanceof ProgrammingCardDeck){
|
||||
wrapper.setScreen(new CardChoiceScreen(wrapper,(ProgrammingCardDeck) object));
|
||||
wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS);
|
||||
wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object);
|
||||
}
|
||||
else if(object instanceof ProgamsContainer){
|
||||
try {
|
||||
wrapper.roboRallyGame.reciveAllProgrammes((ProgamsContainer) object);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if (object instanceof PowerdownContainer){
|
||||
wrapper.roboRallyGame.recivedStayInPowerdown((PowerdownContainer) object);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class RoboRallyServer {
|
||||
server.start();
|
||||
NetworkUtil.registerClasses(server.getKryo());
|
||||
server.bind(54555, 54777);
|
||||
listener = new RoboRallyServerListener();
|
||||
listener = new RoboRallyServerListener(this);
|
||||
server.addListener(listener);
|
||||
}
|
||||
|
||||
|
@ -5,12 +5,17 @@ import com.esotericsoftware.kryonet.Connection;
|
||||
import com.esotericsoftware.kryonet.Listener;
|
||||
import inf112.fiasko.roborally.elementproperties.RobotID;
|
||||
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
|
||||
import inf112.fiasko.roborally.networking.containers.PowerdownContainer;
|
||||
import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
|
||||
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This listener handles all sending and responses for the server
|
||||
@ -20,15 +25,19 @@ class RoboRallyServerListener extends Listener {
|
||||
private final Map<Connection, RobotID> clients;
|
||||
private final Map<Connection, String> playerNames;
|
||||
private final List<Connection> deadPlayers;
|
||||
private Map<Connection,Boolean> StayInPowerdown = new HashMap<>();
|
||||
private Map<Connection,ProgramAndPowerdownRequest> programs = new HashMap<>();
|
||||
private RoboRallyServer server;
|
||||
|
||||
/**
|
||||
* Instantiates a new Robo Rally server listener
|
||||
*/
|
||||
RoboRallyServerListener() {
|
||||
RoboRallyServerListener(RoboRallyServer server) {
|
||||
super();
|
||||
clients = new HashMap<>();
|
||||
playerNames = new HashMap<>();
|
||||
deadPlayers = new ArrayList<>();
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,16 +73,64 @@ class RoboRallyServerListener extends Listener {
|
||||
@Override
|
||||
public void received (Connection connection, Object object) {
|
||||
if (object instanceof String) {
|
||||
String playerName = (String) object;
|
||||
System.out.println((String) object);
|
||||
recivedString(connection,(String) object);
|
||||
}
|
||||
else if(object instanceof Boolean){
|
||||
recivedContinuePowerdown(connection,(Boolean) object);
|
||||
}
|
||||
else if(object instanceof ProgramAndPowerdownRequest){
|
||||
reciveProgamAndPowerdownRequest(connection,(ProgramAndPowerdownRequest) object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void recivedString(Connection connection,String name){
|
||||
String playerName = name;
|
||||
if (playerNames.containsValue(playerName)) {
|
||||
String errorMessage = "The player name send is already taken.";
|
||||
connection.sendTCP(new ErrorResponse(errorMessage, new IllegalArgumentException(errorMessage)));
|
||||
} else {
|
||||
playerNames.put(connection, playerName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void recivedContinuePowerdown(Connection connection,Boolean bool){
|
||||
StayInPowerdown.put(connection,bool);
|
||||
if(recivedDataFromAllConnections(StayInPowerdown)){
|
||||
Map<String,Boolean> powerdowns = new HashMap<>();
|
||||
for (Connection connected:StayInPowerdown.keySet()) {
|
||||
powerdowns.put(playerNames.get(connected),StayInPowerdown.get(connected));
|
||||
}
|
||||
server.sendToAllClients(new PowerdownContainer(powerdowns));
|
||||
StayInPowerdown = new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
private void reciveProgamAndPowerdownRequest(Connection connection,ProgramAndPowerdownRequest request){
|
||||
programs.put(connection,request);
|
||||
if(recivedDataFromAllConnections(programs)){
|
||||
Map<String,Boolean> powerdown = new HashMap<>();
|
||||
Map<String,List<ProgrammingCard>> program = new HashMap<>();
|
||||
|
||||
for (Connection connected:programs.keySet()) {
|
||||
powerdown.put(playerNames.get(connected),programs.get(connected).getPowerdown());
|
||||
program.put(playerNames.get(connected),programs.get(connected).getProgram());
|
||||
|
||||
}
|
||||
server.sendToAllClients(new ProgamsContainer(program,powerdown));
|
||||
programs = new HashMap<>();
|
||||
|
||||
}
|
||||
}
|
||||
private<K> boolean recivedDataFromAllConnections(Map<Connection,K> data){
|
||||
Set<Connection> connections = clients.keySet();
|
||||
connections.removeAll(deadPlayers);
|
||||
return connections.containsAll(data.keySet()) && data.keySet().containsAll(connections);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void connected(Connection connection) {
|
||||
//The first client to connect is assumed to be the host
|
||||
|
@ -0,0 +1,15 @@
|
||||
package inf112.fiasko.roborally.networking.containers;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PowerdownContainer {
|
||||
private Map<String,Boolean> powerdown;
|
||||
|
||||
public PowerdownContainer(Map<String, Boolean> powerdown) {
|
||||
this.powerdown = powerdown;
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getPowerdown() {
|
||||
return powerdown;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package inf112.fiasko.roborally.networking.containers;
|
||||
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProgamsContainer {
|
||||
private Map<String, List<ProgrammingCard>> program;
|
||||
private Map<String, Boolean> powerdown;
|
||||
|
||||
public ProgamsContainer(){}
|
||||
public ProgamsContainer(Map<String, List<ProgrammingCard>> program, Map<String, Boolean> powerdown) {
|
||||
this.program = program;
|
||||
this.powerdown = powerdown;
|
||||
}
|
||||
|
||||
public Map<String, List<ProgrammingCard>> getProgram() {
|
||||
return program;
|
||||
}
|
||||
public Map<String, Boolean> getPowerdown() {
|
||||
return powerdown;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package inf112.fiasko.roborally.networking.containers;
|
||||
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProgramAndPowerdownRequest {
|
||||
private Boolean powerdown;
|
||||
private List<ProgrammingCard> program;
|
||||
|
||||
public ProgramAndPowerdownRequest(){}
|
||||
public ProgramAndPowerdownRequest(Boolean powerdown, List<ProgrammingCard> program) {
|
||||
this.program=program;
|
||||
this.powerdown = powerdown;
|
||||
}
|
||||
|
||||
public List<ProgrammingCard> getProgram() {
|
||||
return program;
|
||||
}
|
||||
|
||||
public Boolean getPowerdown() {
|
||||
return powerdown;
|
||||
}
|
||||
}
|
@ -756,4 +756,31 @@ public class Board {
|
||||
particles.setElement(positionX, positionY, new Particle(type, laserDirection));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the int corresponding to the flag a robot has last visited
|
||||
* @param robotID The robot to be checked
|
||||
* @return The flag last visited in a number
|
||||
*/
|
||||
public int getLastFlagVisitedFromRobotID(RobotID robotID) {
|
||||
return robots.get(robotID).getLastFlagVisited();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a boolean for if the robot has touched a flag this turn
|
||||
* @param robotID The robot to be checked
|
||||
* @param hasTouched If the robot has touched a flag this turn
|
||||
*/
|
||||
public void setHasTouchedFlagThisTurnFromRobotID(RobotID robotID, boolean hasTouched) {
|
||||
robots.get(robotID).setHasTouchedFlagThisTurn(hasTouched);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a boolean for if the robot has touched a flag this turn
|
||||
* @param robotID The robot to be checked
|
||||
* @return If the robot has touched a flag this turn
|
||||
*/
|
||||
public boolean isHasTouchedFlagThisTurnFromRobotID(RobotID robotID) {
|
||||
return robots.get(robotID).isHasTouchedFlagThisTurn();
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.elementproperties.GameState;
|
||||
import inf112.fiasko.roborally.networking.containers.PowerdownContainer;
|
||||
import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This interface describes
|
||||
@ -23,4 +27,21 @@ public interface IInteractableGame {
|
||||
* @return A string of the player name
|
||||
*/
|
||||
String getWinningPlayerName();
|
||||
|
||||
void reciveAllProgrammes(ProgamsContainer programs) throws InterruptedException;
|
||||
|
||||
void recivedStayInPowerdown(PowerdownContainer powerdowns);
|
||||
|
||||
List<ProgrammingCard> getProgram();
|
||||
|
||||
int getProgramSize();
|
||||
|
||||
void setPlayerHand(ProgrammingCardDeck playerHand);
|
||||
|
||||
ProgrammingCardDeck getPlayerHand();
|
||||
|
||||
void setProgram(List<ProgrammingCard> program);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import inf112.fiasko.roborally.elementproperties.Action;
|
||||
*/
|
||||
public class ProgrammingCard implements Comparable<ProgrammingCard> {
|
||||
|
||||
private final int cardPriority;
|
||||
private final Action cardAction;
|
||||
private int cardPriority;
|
||||
private Action cardAction;
|
||||
|
||||
/**
|
||||
* Initializes the priority and the action of the card
|
||||
@ -20,6 +20,10 @@ public class ProgrammingCard implements Comparable<ProgrammingCard> {
|
||||
this.cardAction = cardAction;
|
||||
}
|
||||
|
||||
public ProgrammingCard(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the priority of the programming card
|
||||
* @return The programming card priority
|
||||
|
@ -9,6 +9,8 @@ import inf112.fiasko.roborally.elementproperties.RobotID;
|
||||
import inf112.fiasko.roborally.elementproperties.TileType;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyClient;
|
||||
import inf112.fiasko.roborally.networking.RoboRallyServer;
|
||||
import inf112.fiasko.roborally.networking.containers.PowerdownContainer;
|
||||
import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
|
||||
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
||||
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
|
||||
|
||||
@ -38,6 +40,24 @@ public class RoboRallyGame implements IRoboRallyGame {
|
||||
private final RoboRallyClient client;
|
||||
private RoboRallyServer server;
|
||||
private String winningPlayerName;
|
||||
private List<ProgrammingCard> program;
|
||||
private ProgrammingCardDeck playerHand;
|
||||
|
||||
public ProgrammingCardDeck getPlayerHand() {
|
||||
return playerHand;
|
||||
}
|
||||
|
||||
public void setPlayerHand(ProgrammingCardDeck playerHand) {
|
||||
this.playerHand = playerHand;
|
||||
}
|
||||
|
||||
public List<ProgrammingCard> getProgram() {
|
||||
return program;
|
||||
}
|
||||
|
||||
public void setProgram(List<ProgrammingCard> program) {
|
||||
this.program = program;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Robo Rally game
|
||||
@ -63,6 +83,9 @@ public class RoboRallyGame implements IRoboRallyGame {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new Robo Rally game
|
||||
* @param playerList A list of all the players participating in the game
|
||||
@ -247,6 +270,14 @@ public class RoboRallyGame implements IRoboRallyGame {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getProgramSize(){
|
||||
Player player = getPlayerFromName(playerName);
|
||||
if (player != null) {
|
||||
return Math.min(5, 5 - gameBoard.getRobotDamage(player.getRobotID()) + 4);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all the steps of one turn in the game
|
||||
* @throws InterruptedException If interrupted while trying to sleep
|
||||
@ -289,13 +320,35 @@ public class RoboRallyGame implements IRoboRallyGame {
|
||||
}
|
||||
}
|
||||
}
|
||||
setGameState(GameState.CHOOSING_CARDS);
|
||||
setGameState(GameState.JUST_BEFORE_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
|
||||
while (getGameState()==GameState.CHOOSING_CARDS) {
|
||||
//loops waiting for the player to be done choosing their cards
|
||||
|
||||
|
||||
// TODO: If this player is in power down, ask if it shall continue
|
||||
// Respawn dead robots, as long as they have more lives left
|
||||
}
|
||||
|
||||
public void recivedStayInPowerdown(PowerdownContainer powerdowns){
|
||||
for (Player player:playerList) {
|
||||
player.setPowerDownNextRound(powerdowns.getPowerdown().get(player.getName()));
|
||||
}
|
||||
respawnRobots();
|
||||
resetHasTouchedFlagThisTurnForAllRobots();
|
||||
}
|
||||
|
||||
public void reciveAllProgrammes(ProgamsContainer programs) throws InterruptedException {
|
||||
Map<String,List<ProgrammingCard>> progs = programs.getProgram();
|
||||
Map<String,Boolean> powerdown = programs.getPowerdown();
|
||||
String playername;
|
||||
for (Player player:playerList) {
|
||||
playername = player.getName();
|
||||
player.setInProgram(progs.get(playername));
|
||||
player.setPowerDownNextRound(powerdown.get(playername));
|
||||
}
|
||||
setGameState(GameState.RUNNING_PROGRAMS);
|
||||
runPhase(1);
|
||||
runPhase(2);
|
||||
runPhase(3);
|
||||
@ -309,9 +362,8 @@ public class RoboRallyGame implements IRoboRallyGame {
|
||||
removeNonLockedProgrammingCardsFromPlayers();
|
||||
}
|
||||
// TODO: If this player is in power down, ask if it shall continue
|
||||
// Respawn dead robots, as long as they have more lives left
|
||||
respawnRobots();
|
||||
resetHasTouchedFlagThisTurnForAllRobots();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -582,15 +634,26 @@ public class RoboRallyGame implements IRoboRallyGame {
|
||||
private void checkAllFlags() {
|
||||
for (BoardElementContainer<Tile> flag : flags) {
|
||||
Position flagPosition = flag.getPosition();
|
||||
if (gameBoard.hasRobotOnPosition(flagPosition)) {
|
||||
if (!gameBoard.hasRobotOnPosition(flagPosition)) {
|
||||
continue;
|
||||
}
|
||||
RobotID robotID = gameBoard.getRobotOnPosition(flagPosition);
|
||||
for (Robot robot : gameBoard.getAliveRobots()) {
|
||||
if (robot.getRobotId() != robotID || robot.isHasTouchedFlagThisTurn()) {
|
||||
if (gameBoard.isHasTouchedFlagThisTurnFromRobotID(robotID)) {
|
||||
continue;
|
||||
}
|
||||
gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
|
||||
robot.setHasTouchedFlagThisTurn(true);
|
||||
if (victoryCheck(robot.getLastFlagVisited(), flags.size())) {
|
||||
gameBoard.setHasTouchedFlagThisTurnFromRobotID(robotID,true);
|
||||
checkIfPlayerWon(robotID, flags.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player won, and shows the victory screen
|
||||
* @param robotID The robot to be checked
|
||||
* @param numberOfFlags The number of flags on the map
|
||||
*/
|
||||
private void checkIfPlayerWon(RobotID robotID, int numberOfFlags) {
|
||||
if (victoryCheck(gameBoard.getLastFlagVisitedFromRobotID(robotID), numberOfFlags)) {
|
||||
for (Player player : playerList) {
|
||||
if (player.getRobotID() != robotID) {
|
||||
continue;
|
||||
@ -600,9 +663,6 @@ public class RoboRallyGame implements IRoboRallyGame {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player has won
|
||||
@ -614,7 +674,6 @@ public class RoboRallyGame implements IRoboRallyGame {
|
||||
return (lastFlagVisited == lastFlag);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fires all lasers on the game board
|
||||
*/
|
||||
|
@ -5,12 +5,16 @@ 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;
|
||||
import inf112.fiasko.roborally.networking.containers.PowerdownContainer;
|
||||
import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
|
||||
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
|
||||
import inf112.fiasko.roborally.objects.IDeck;
|
||||
import inf112.fiasko.roborally.objects.Player;
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
||||
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This class helps with networking tasks
|
||||
@ -31,5 +35,11 @@ public final class NetworkUtil {
|
||||
kryo.register(RobotID.class);
|
||||
kryo.register(ProgrammingCardDeck.class);
|
||||
kryo.register(Action.class);
|
||||
kryo.register(ProgramAndPowerdownRequest.class);
|
||||
kryo.register(ProgamsContainer.class);
|
||||
kryo.register(PowerdownContainer.class);
|
||||
kryo.register(HashMap.class);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user