mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Kombinerer kortvelging og powerdown. Closes #78
This commit is contained in:
parent
ee4c15c999
commit
cc71a50370
@ -15,6 +15,7 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
|
|||||||
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.gamewrapper.SimpleButton;
|
import inf112.fiasko.roborally.gamewrapper.SimpleButton;
|
||||||
|
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
|
||||||
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
import inf112.fiasko.roborally.objects.ProgrammingCard;
|
||||||
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
|
||||||
|
|
||||||
@ -63,9 +64,17 @@ public class CardChoiceScreen extends InteractiveScreen implements Screen {
|
|||||||
TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton();
|
TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton();
|
||||||
stage.addActor(confirmCards);
|
stage.addActor(confirmCards);
|
||||||
confirmCards.setY(viewport.getWorldHeight() - confirmCards.getHeight());
|
confirmCards.setY(viewport.getWorldHeight() - confirmCards.getHeight());
|
||||||
confirmCards.setX(15);
|
confirmCards.setX(0);
|
||||||
|
|
||||||
confirmCards.addListener(getConfirmListener());
|
confirmCards.addListener(getConfirmListener());
|
||||||
|
|
||||||
|
TextButton confirmCardsAndPowerDown = new SimpleButton("Confirm + PowerDown",
|
||||||
|
roboRallyWrapper.font).getButton();
|
||||||
|
stage.addActor(confirmCardsAndPowerDown);
|
||||||
|
confirmCardsAndPowerDown.setY(viewport.getWorldHeight() - confirmCardsAndPowerDown.getHeight());
|
||||||
|
confirmCardsAndPowerDown.setX(confirmCards.getWidth());
|
||||||
|
|
||||||
|
confirmCardsAndPowerDown.addListener(getConfirmAndPowerDownListener());
|
||||||
stage.setViewport(viewport);
|
stage.setViewport(viewport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +92,34 @@ public class CardChoiceScreen extends InteractiveScreen implements Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
|
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
|
||||||
|
confirmCards(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a listener for confirming cards and entering power down
|
||||||
|
*
|
||||||
|
* @return An input listener
|
||||||
|
*/
|
||||||
|
private ClickListener getConfirmAndPowerDownListener() {
|
||||||
|
return new ClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
|
||||||
|
confirmCards(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirm cards and send to server if all are chosen
|
||||||
|
*/
|
||||||
|
private void confirmCards(Boolean requestPowerDown) {
|
||||||
if (chosenCards.size() == maxCards) {
|
if (chosenCards.size() == maxCards) {
|
||||||
List<ProgrammingCard> oldProgram = roboRallyWrapper.roboRallyGame.getProgram();
|
List<ProgrammingCard> oldProgram = roboRallyWrapper.roboRallyGame.getProgram();
|
||||||
int lockedCardsInt = 5 - maxCards;
|
int lockedCardsInt = 5 - maxCards;
|
||||||
@ -90,17 +127,16 @@ public class CardChoiceScreen extends InteractiveScreen implements Screen {
|
|||||||
for (int i = 4; i > (4 - lockedCardsInt); i--) {
|
for (int i = 4; i > (4 - lockedCardsInt); i--) {
|
||||||
newProgram.add(oldProgram.get(i));
|
newProgram.add(oldProgram.get(i));
|
||||||
}
|
}
|
||||||
|
//Save the program to get locked cards later
|
||||||
roboRallyWrapper.roboRallyGame.setProgram(newProgram);
|
roboRallyWrapper.roboRallyGame.setProgram(newProgram);
|
||||||
roboRallyWrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN);
|
roboRallyWrapper.roboRallyGame.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS);
|
||||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper));
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
||||||
|
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(requestPowerDown, newProgram));
|
||||||
} else {
|
} else {
|
||||||
JOptionPane.showMessageDialog(null, "You need to choose all your cards"
|
JOptionPane.showMessageDialog(null, "You need to choose all your cards"
|
||||||
+ " before confirming.");
|
+ " before confirming.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of programming cards from the player's chosen cards
|
* Gets a list of programming cards from the player's chosen cards
|
||||||
|
@ -7,7 +7,6 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
|
|||||||
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.gamewrapper.SimpleButton;
|
import inf112.fiasko.roborally.gamewrapper.SimpleButton;
|
||||||
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This screen is used for asking players whether they want to power down
|
* This screen is used for asking players whether they want to power down
|
||||||
@ -54,17 +53,12 @@ public class PowerDownScreen extends AbstractScreen {
|
|||||||
public void render(float delta) {
|
public void render(float delta) {
|
||||||
super.render(delta);
|
super.render(delta);
|
||||||
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
||||||
String descriptionText;
|
|
||||||
if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_POWER_DOWN) {
|
|
||||||
descriptionText = "Click the button to enter power down next turn";
|
|
||||||
} else {
|
|
||||||
descriptionText = "Click the button to continue your power down the next turn";
|
|
||||||
}
|
|
||||||
int elapsedTime = (int) Math.floor((System.currentTimeMillis() - startTime) / 1000f);
|
int elapsedTime = (int) Math.floor((System.currentTimeMillis() - startTime) / 1000f);
|
||||||
|
|
||||||
roboRallyWrapper.batch.begin();
|
roboRallyWrapper.batch.begin();
|
||||||
|
|
||||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, descriptionText,
|
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to continue your power down the" +
|
||||||
|
" next turn",
|
||||||
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
|
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
|
||||||
true);
|
true);
|
||||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(5 - elapsedTime),
|
roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(5 - elapsedTime),
|
||||||
@ -89,13 +83,8 @@ public class PowerDownScreen extends AbstractScreen {
|
|||||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
||||||
roboRallyWrapper.client.sendElement(bool);
|
roboRallyWrapper.client.sendElement(bool);
|
||||||
break;
|
break;
|
||||||
case CHOOSING_POWER_DOWN:
|
|
||||||
roboRallyWrapper.roboRallyGame.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS);
|
|
||||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
|
||||||
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(bool,
|
|
||||||
roboRallyWrapper.roboRallyGame.getProgram()));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
|
roboRallyWrapper.quit("The game is in an unexpected state. Cannot continue.");
|
||||||
throw new IllegalStateException("The game is in an unexpected state. Cannot continue.");
|
throw new IllegalStateException("The game is in an unexpected state. Cannot continue.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user