mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-07-31 12:15:27 +02:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user