mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 15:19:35 +01:00
Auto reformaterer alle klasser og tester for visuelt grensesnitt
This commit is contained in:
parent
afe9e67969
commit
a19e616257
@ -6,7 +6,7 @@ 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.IRoboRallyGame;
|
||||
import inf112.fiasko.roborally.objects.RoboRallyGame;
|
||||
|
||||
/**
|
||||
* This class acts as a wrapper around the different screens of the game
|
||||
@ -15,7 +15,7 @@ public class RoboRallyWrapper extends Game {
|
||||
public SpriteBatch batch;
|
||||
public BitmapFont font;
|
||||
public ScreenManager screenManager;
|
||||
public IRoboRallyGame roboRallyGame;
|
||||
public RoboRallyGame roboRallyGame;
|
||||
public RoboRallyServer server;
|
||||
public RoboRallyClient client;
|
||||
|
||||
@ -35,6 +35,7 @@ public class RoboRallyWrapper extends Game {
|
||||
|
||||
/**
|
||||
* Quits the game after logging the input as an error
|
||||
*
|
||||
* @param string The error causing the game to quit
|
||||
*/
|
||||
public void quit(String string) {
|
||||
|
@ -1,7 +1,14 @@
|
||||
package inf112.fiasko.roborally.gamewrapper;
|
||||
|
||||
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.*;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.BoardActiveScreen;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.CardChoiceScreen;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.IPAddressScreen;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.LoadingScreen;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.LobbyScreen;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.PowerDownScreen;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.StartMenuScreen;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.UsernameScreen;
|
||||
import inf112.fiasko.roborally.gamewrapper.screens.WinnerScreen;
|
||||
|
||||
/**
|
||||
* Keeps track of screen instances
|
||||
@ -26,6 +33,7 @@ public class ScreenManager {
|
||||
|
||||
/**
|
||||
* Gets an instance of the winner screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A winner screen instance
|
||||
*/
|
||||
@ -38,6 +46,7 @@ public class ScreenManager {
|
||||
|
||||
/**
|
||||
* Gets an instance of the power down screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A power down screen instance
|
||||
*/
|
||||
@ -50,6 +59,7 @@ public class ScreenManager {
|
||||
|
||||
/**
|
||||
* Gets an instance of the lobby screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A lobby screen instance
|
||||
*/
|
||||
@ -62,6 +72,7 @@ public class ScreenManager {
|
||||
|
||||
/**
|
||||
* Gets an instance of the ip address screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return An ip address screen instance
|
||||
*/
|
||||
@ -74,6 +85,7 @@ public class ScreenManager {
|
||||
|
||||
/**
|
||||
* Gets an instance of the username screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A username screen instance
|
||||
*/
|
||||
@ -86,6 +98,7 @@ public class ScreenManager {
|
||||
|
||||
/**
|
||||
* Gets an instance of the start menu screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A start menu screen instance
|
||||
*/
|
||||
@ -95,6 +108,7 @@ public class ScreenManager {
|
||||
|
||||
/**
|
||||
* Gets an instance of the loading screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A loading screen instance
|
||||
*/
|
||||
@ -107,6 +121,7 @@ public class ScreenManager {
|
||||
|
||||
/**
|
||||
* Gets an instance of the board active screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally launcher instance to use
|
||||
* @return A board active screen instance
|
||||
*/
|
||||
|
@ -14,6 +14,7 @@ public class SimpleButton {
|
||||
|
||||
/**
|
||||
* Instantiates a new simple button
|
||||
*
|
||||
* @param text The text to display on the button
|
||||
* @param font The font to use to draw button text
|
||||
*/
|
||||
@ -29,6 +30,7 @@ public class SimpleButton {
|
||||
|
||||
/**
|
||||
* Gets the button generated
|
||||
*
|
||||
* @return A button
|
||||
*/
|
||||
public TextButton getButton() {
|
||||
|
@ -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.IDrawableObject;
|
||||
import inf112.fiasko.roborally.objects.IRoboRallyGame;
|
||||
import inf112.fiasko.roborally.objects.DrawableObject;
|
||||
import inf112.fiasko.roborally.objects.RoboRallyGame;
|
||||
import inf112.fiasko.roborally.utility.IOUtil;
|
||||
import inf112.fiasko.roborally.utility.TextureConverterUtil;
|
||||
|
||||
@ -27,19 +27,19 @@ import java.util.List;
|
||||
public class BoardActiveScreen extends AbstractScreen implements InputProcessor {
|
||||
private final RoboRallyWrapper roboRallyWrapper;
|
||||
private final OrthographicCamera camera;
|
||||
private IRoboRallyGame debugGame;
|
||||
|
||||
private final int tileDimensions = 64;
|
||||
private final int viewPortWidth = 12 * tileDimensions;
|
||||
private final int viewPortHeight = 12 * tileDimensions;
|
||||
private final Viewport viewport;
|
||||
private RoboRallyGame debugGame;
|
||||
private float cameraZoom = 1;
|
||||
private int cameraX = 0;
|
||||
private int cameraY = 0;
|
||||
private Vector2 lastTouch;
|
||||
private final int viewPortWidth = 12 * tileDimensions;
|
||||
private final int viewPortHeight = 12 * tileDimensions;
|
||||
private final Viewport viewport;
|
||||
|
||||
/**
|
||||
* Instantiates a new board active screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public BoardActiveScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
@ -67,9 +67,9 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(0,0,0,1);
|
||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT |
|
||||
(Gdx.graphics.getBufferFormat().coverageSampling?GL20.GL_COVERAGE_BUFFER_BIT_NV:0));
|
||||
(Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0));
|
||||
updateCamera();
|
||||
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
||||
roboRallyWrapper.batch.begin();
|
||||
@ -79,8 +79,7 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
// Checks if there has been found a winning player and then changes the screen to display the winning screen
|
||||
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){
|
||||
} else if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_STAY_IN_POWER_DOWN) {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper));
|
||||
}
|
||||
}
|
||||
@ -100,7 +99,7 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
@Override
|
||||
public boolean keyUp(int keyCode) {
|
||||
if (keyCode == Input.Keys.HOME) {
|
||||
IRoboRallyGame temp = roboRallyWrapper.roboRallyGame;
|
||||
RoboRallyGame temp = roboRallyWrapper.roboRallyGame;
|
||||
roboRallyWrapper.roboRallyGame = debugGame;
|
||||
this.debugGame = temp;
|
||||
return true;
|
||||
@ -140,8 +139,8 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
Vector2 diff = newTouch.cpy().sub(lastTouch);
|
||||
lastTouch = newTouch;
|
||||
int[] positionChange = translateCoordinateAccountingForCameraRotation(diff.x, diff.y);
|
||||
cameraX = (int)(positionChange[0] * cameraZoom);
|
||||
cameraY = (int)(positionChange[1] * cameraZoom);
|
||||
cameraX = (int) (positionChange[0] * cameraZoom);
|
||||
cameraY = (int) (positionChange[1] * cameraZoom);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -170,15 +169,16 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
|
||||
/**
|
||||
* Renders all drawable objects on the board
|
||||
*
|
||||
* @param batch The sprite batch to use for drawing
|
||||
*/
|
||||
private void drawBoard(SpriteBatch batch) {
|
||||
List<IDrawableObject> elementsToDraw =
|
||||
List<DrawableObject> elementsToDraw =
|
||||
IOUtil.getDrawableObjectsFromGame(roboRallyWrapper.roboRallyGame, tileDimensions, tileDimensions);
|
||||
for (IDrawableObject object : elementsToDraw) {
|
||||
for (DrawableObject object : elementsToDraw) {
|
||||
TextureRegion objectTextureRegion = object.getTexture();
|
||||
batch.draw(objectTextureRegion.getTexture(), object.getXPosition(), object.getYPosition(),
|
||||
(float)object.getWidth() / 2, (float)object.getHeight() / 2,
|
||||
(float) object.getWidth() / 2, (float) object.getHeight() / 2,
|
||||
object.getWidth(), object.getHeight(), 1, 1, object.getRotation(),
|
||||
objectTextureRegion.getRegionX(), objectTextureRegion.getRegionY(),
|
||||
objectTextureRegion.getRegionWidth(), objectTextureRegion.getRegionHeight(),
|
||||
@ -199,6 +199,7 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
|
||||
|
||||
/**
|
||||
* Translates x and y coordinates according to the camera's direction
|
||||
*
|
||||
* @param x The x coordinate to translate
|
||||
* @param y The y coordinate to translate
|
||||
* @return A list containing the translated coordinates of x and y
|
||||
|
@ -47,6 +47,7 @@ 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) {
|
||||
@ -82,12 +83,13 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
|
||||
/**
|
||||
* Generates a listener for confirming cards
|
||||
*
|
||||
* @return An input listener
|
||||
*/
|
||||
private InputListener getConfirmListener() {
|
||||
return new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
if (chosenCards.size() == maxCards) {
|
||||
roboRallyWrapper.roboRallyGame.setProgram(getCards());
|
||||
roboRallyWrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN);
|
||||
@ -104,6 +106,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
|
||||
/**
|
||||
* Gets a list of programming cards from the player's chosen cards
|
||||
*
|
||||
* @return A list of programming cards
|
||||
*/
|
||||
private List<ProgrammingCard> getCards() {
|
||||
@ -114,6 +117,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
|
||||
/**
|
||||
* Calculates positions for cards in the given deck
|
||||
*
|
||||
* @param deck A deck containing cards which can be chosen
|
||||
*/
|
||||
private void generateCards(ProgrammingCardDeck deck) {
|
||||
@ -121,13 +125,13 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
float cardWidth = viewport.getWorldWidth() / 3;
|
||||
float cardHeight = (viewport.getWorldHeight() - 30) / 3;
|
||||
for (int i = 0; i < cardList.size(); i++) {
|
||||
int x = (int)(((i % 3) * cardWidth) + 10);
|
||||
int y = (int)(((i / 3) * cardHeight + 10));
|
||||
int x = (int) (((i % 3) * cardWidth) + 10);
|
||||
int y = (int) (((i / 3) * cardHeight + 10));
|
||||
Rectangle card = new Rectangle();
|
||||
card.x = x;
|
||||
card.y = y;
|
||||
card.width = (int)cardWidth - 20;
|
||||
card.height = (int)cardHeight - 20;
|
||||
card.width = (int) cardWidth - 20;
|
||||
card.height = (int) cardHeight - 20;
|
||||
ProgrammingCard programmingCard = cardList.get(i);
|
||||
CardRectangle cardRectangle = new CardRectangle(card, programmingCard);
|
||||
cardRectangles.add(cardRectangle);
|
||||
@ -179,7 +183,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
for (CardRectangle cardRectangle : cardRectangles) {
|
||||
GlyphLayout layout = new GlyphLayout(roboRallyWrapper.font,
|
||||
Integer.toString(cardRectangle.card.getPriority()));
|
||||
float fontX = (int)(cardRectangle.rectangle.x + (cardRectangle.rectangle.width - layout.width) / 2.0);
|
||||
float fontX = (int) (cardRectangle.rectangle.x + (cardRectangle.rectangle.width - layout.width) / 2.0);
|
||||
float fontY = cardRectangle.rectangle.y + cardRectangle.rectangle.height - 30;
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, layout, fontX, fontY);
|
||||
drawCardSymbol(cardRectangle);
|
||||
@ -188,6 +192,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
||||
|
||||
/**
|
||||
* Draws the symbol on a card
|
||||
*
|
||||
* @param cardRectangle The card rectangle to draw
|
||||
*/
|
||||
private void drawCardSymbol(CardRectangle cardRectangle) {
|
||||
|
@ -13,8 +13,9 @@ public class CardRectangle {
|
||||
|
||||
/**
|
||||
* Instantiates a new card rectangle
|
||||
*
|
||||
* @param rectangle The rectangle of this card rectangle
|
||||
* @param card The card of this card rectangle
|
||||
* @param card The card of this card rectangle
|
||||
*/
|
||||
CardRectangle(Rectangle rectangle, ProgrammingCard card) {
|
||||
this.rectangle = rectangle;
|
||||
|
@ -31,6 +31,7 @@ public class IPAddressScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Instantiates a new ip address screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public IPAddressScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
@ -38,8 +39,8 @@ public class IPAddressScreen extends AbstractScreen {
|
||||
|
||||
Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
|
||||
TextButton joinButton = new TextButton("Join", skin);
|
||||
joinButton.setSize(300,60);
|
||||
joinButton.setPosition(applicationWidth/2f -joinButton.getWidth()/2f,300);
|
||||
joinButton.setSize(300, 60);
|
||||
joinButton.setPosition(applicationWidth / 2f - joinButton.getWidth() / 2f, 300);
|
||||
joinButton.addListener(new ClickListener() {
|
||||
@Override
|
||||
public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
|
||||
@ -49,7 +50,7 @@ public class IPAddressScreen extends AbstractScreen {
|
||||
@Override
|
||||
public void touchUp(InputEvent e, float x, float y, int point, int button) {
|
||||
try {
|
||||
roboRallyWrapper.client = new RoboRallyClient(txtinput.getText(),roboRallyWrapper);
|
||||
roboRallyWrapper.client = new RoboRallyClient(txtinput.getText(), roboRallyWrapper);
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
@ -59,8 +60,8 @@ public class IPAddressScreen extends AbstractScreen {
|
||||
}
|
||||
});
|
||||
txtinput = new TextField("", skin);
|
||||
txtinput.setPosition(applicationWidth/2f -txtinput.getWidth()/2f,250);
|
||||
txtinput.setSize(150,40);
|
||||
txtinput.setPosition(applicationWidth / 2f - txtinput.getWidth() / 2f, 250);
|
||||
txtinput.setSize(150, 40);
|
||||
stage.addActor(txtinput);
|
||||
stage.addActor(joinButton);
|
||||
|
||||
@ -85,7 +86,7 @@ public class IPAddressScreen extends AbstractScreen {
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Enter IP address and click the button to join a server",
|
||||
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
|
||||
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
|
||||
true);
|
||||
roboRallyWrapper.batch.end();
|
||||
stage.draw();
|
||||
|
@ -19,6 +19,7 @@ public class LoadingScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Instantiates a new loading screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public LoadingScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
@ -37,7 +38,7 @@ public class LoadingScreen extends AbstractScreen {
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Loading...", applicationWidth / 2f - 380 / 2f,
|
||||
applicationHeight / 2f,380, 1, true);
|
||||
applicationHeight / 2f, 380, 1, true);
|
||||
roboRallyWrapper.batch.end();
|
||||
|
||||
if (roboRallyWrapper.roboRallyGame != null) {
|
||||
@ -50,6 +51,7 @@ public class LoadingScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Changes to another screen depending on which state the game is in
|
||||
*
|
||||
* @param gameState The current state of the game
|
||||
*/
|
||||
private void handleScreenChange(GameState gameState) {
|
||||
@ -62,7 +64,12 @@ public class LoadingScreen extends AbstractScreen {
|
||||
break;
|
||||
case CHOOSING_CARDS:
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getCardChoiceScreen(this.roboRallyWrapper));
|
||||
break; }
|
||||
break;
|
||||
default:
|
||||
if (gameState != GameState.LOADING) {
|
||||
System.out.println("Don't know what to do with " + gameState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,27 +31,28 @@ public class LobbyScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Instantiates a new lobby screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public LobbyScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
camera = new OrthographicCamera();
|
||||
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
|
||||
stage = new Stage();
|
||||
TextButton startGameButton= new SimpleButton("Start", roboRallyWrapper.font).getButton();
|
||||
TextButton startGameButton = new SimpleButton("Start", roboRallyWrapper.font).getButton();
|
||||
stage.addActor(startGameButton);
|
||||
startGameButton.setY(applicationHeight / 2f-50 );
|
||||
startGameButton.setY(applicationHeight / 2f - 50);
|
||||
startGameButton.setX(applicationWidth / 2f - startGameButton.getWidth() / 2f);
|
||||
this.roboRallyWrapper = roboRallyWrapper;
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
startGameButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
Map<Connection,String> playernames = roboRallyWrapper.server.getPlayerNames();
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
Map<Connection, String> playernames = roboRallyWrapper.server.getPlayerNames();
|
||||
List<Player> playerlist = IOUtil.playerGenerator(playernames,
|
||||
roboRallyWrapper.server.getRobotID());
|
||||
for (Connection connection:playernames.keySet()) {
|
||||
roboRallyWrapper.server.sendToClient(connection,new GameStartInfo("Checkmate.txt"
|
||||
,playerlist,playernames.get(connection)));
|
||||
for (Connection connection : playernames.keySet()) {
|
||||
roboRallyWrapper.server.sendToClient(connection, new GameStartInfo("Checkmate.txt"
|
||||
, playerlist, playernames.get(connection)));
|
||||
}
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
|
||||
return true;
|
||||
@ -75,10 +76,10 @@ public class LobbyScreen extends AbstractScreen {
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Joined players: " +
|
||||
roboRallyWrapper.server.getPlayerNames().values().toString(),
|
||||
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 350,380, 1,
|
||||
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 350, 380, 1,
|
||||
true);
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to start game",
|
||||
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
|
||||
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
|
||||
true);
|
||||
roboRallyWrapper.batch.end();
|
||||
stage.draw();
|
||||
|
@ -27,6 +27,7 @@ public class PowerDownScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Instantiates a new power down screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public PowerDownScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
@ -36,14 +37,14 @@ public class PowerDownScreen extends AbstractScreen {
|
||||
stage.setViewport(viewport);
|
||||
TextButton powerDownButton = new SimpleButton("PowerDown", roboRallyWrapper.font).getButton();
|
||||
stage.addActor(powerDownButton);
|
||||
powerDownButton.setY(applicationHeight / 2f-50);
|
||||
powerDownButton.setY(applicationHeight / 2f - 50);
|
||||
powerDownButton.setX(applicationWidth / 2f - powerDownButton.getWidth() / 2f);
|
||||
this.roboRallyWrapper = roboRallyWrapper;
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
startTime = System.currentTimeMillis();
|
||||
powerDownButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
sendPowerDownStatus(true);
|
||||
return true;
|
||||
}
|
||||
@ -57,25 +58,26 @@ public class PowerDownScreen extends AbstractScreen {
|
||||
camera.update();
|
||||
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
int elapsedTime = (int)Math.floor((System.currentTimeMillis() - startTime) / 1000f);
|
||||
int elapsedTime = (int) Math.floor((System.currentTimeMillis() - startTime) / 1000f);
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to enter Power Down next round",
|
||||
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
|
||||
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
|
||||
true);
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(10 - elapsedTime),
|
||||
applicationWidth / 2f - 40 / 2f,applicationHeight / 2f - 100,40, 1,
|
||||
applicationWidth / 2f - 40 / 2f, applicationHeight / 2f - 100, 40, 1,
|
||||
true);
|
||||
roboRallyWrapper.batch.end();
|
||||
stage.draw();
|
||||
|
||||
if (elapsedTime > 10) {
|
||||
sendPowerDownStatus( false);
|
||||
sendPowerDownStatus(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends power down status to the server
|
||||
*
|
||||
* @param bool Whether the player wants to go/stay in power down
|
||||
*/
|
||||
private void sendPowerDownStatus(boolean bool) {
|
||||
|
@ -28,6 +28,7 @@ public class StartMenuScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Instantiates a new start menu screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public StartMenuScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
@ -42,7 +43,7 @@ public class StartMenuScreen extends AbstractScreen {
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
serverButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
try {
|
||||
roboRallyWrapper.server = new RoboRallyServer();
|
||||
roboRallyWrapper.client = new RoboRallyClient("127.0.0.1", roboRallyWrapper);
|
||||
@ -63,7 +64,7 @@ public class StartMenuScreen extends AbstractScreen {
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
clientButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper));
|
||||
return true;
|
||||
}
|
||||
@ -75,14 +76,14 @@ public class StartMenuScreen extends AbstractScreen {
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
quitButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
roboRallyWrapper.quit();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
serverButton.setX(applicationWidth / 2f-serverButton.getWidth()-clientButton.getWidth()/2 - 10);
|
||||
clientButton.setX(applicationWidth / 2f - clientButton.getWidth()/2);
|
||||
quitButton.setX(applicationWidth / 2f + clientButton.getWidth()/2+10);
|
||||
serverButton.setX(applicationWidth / 2f - serverButton.getWidth() - clientButton.getWidth() / 2 - 10);
|
||||
clientButton.setX(applicationWidth / 2f - clientButton.getWidth() / 2);
|
||||
quitButton.setX(applicationWidth / 2f + clientButton.getWidth() / 2 + 10);
|
||||
|
||||
}
|
||||
|
||||
@ -100,7 +101,7 @@ public class StartMenuScreen extends AbstractScreen {
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "RoboRally",
|
||||
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
|
||||
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
|
||||
true);
|
||||
roboRallyWrapper.batch.end();
|
||||
stage.draw();
|
||||
|
@ -26,6 +26,7 @@ public class UsernameScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Instantiates a new username screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public UsernameScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
@ -33,8 +34,8 @@ public class UsernameScreen extends AbstractScreen {
|
||||
|
||||
Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
|
||||
TextButton confirm = new TextButton("Confirm", skin);
|
||||
confirm.setSize(300,60);
|
||||
confirm.setPosition(applicationWidth/2f - confirm.getWidth()/2,300);
|
||||
confirm.setSize(300, 60);
|
||||
confirm.setPosition(applicationWidth / 2f - confirm.getWidth() / 2, 300);
|
||||
confirm.addListener(new ClickListener() {
|
||||
@Override
|
||||
public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
|
||||
@ -50,14 +51,14 @@ public class UsernameScreen extends AbstractScreen {
|
||||
roboRallyWrapper.client.sendElement(userName);
|
||||
if (roboRallyWrapper.server == null) {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
|
||||
} else{
|
||||
} else {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLobbyScreen(roboRallyWrapper));
|
||||
}
|
||||
}
|
||||
});
|
||||
textInput = new TextField("",skin);
|
||||
textInput.setPosition(applicationWidth/2f - textInput.getWidth()/2,250);
|
||||
textInput.setSize(150,40);
|
||||
textInput = new TextField("", skin);
|
||||
textInput.setPosition(applicationWidth / 2f - textInput.getWidth() / 2, 250);
|
||||
textInput.setSize(150, 40);
|
||||
stage.addActor(textInput);
|
||||
stage.addActor(confirm);
|
||||
|
||||
@ -70,6 +71,7 @@ public class UsernameScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Checks whether the username is invalid
|
||||
*
|
||||
* @param userName The username the user wants
|
||||
* @return False if the username can be used
|
||||
*/
|
||||
@ -92,7 +94,7 @@ public class UsernameScreen extends AbstractScreen {
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to enter username",
|
||||
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
|
||||
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
|
||||
true);
|
||||
roboRallyWrapper.batch.end();
|
||||
stage.draw();
|
||||
|
@ -22,6 +22,7 @@ public class WinnerScreen extends AbstractScreen {
|
||||
|
||||
/**
|
||||
* Instantiates a new winner screen
|
||||
*
|
||||
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||
*/
|
||||
public WinnerScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
@ -35,12 +36,12 @@ public class WinnerScreen extends AbstractScreen {
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
quitButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
Gdx.app.exit();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
quitButton.setX(applicationWidth / 2f + quitButton.getWidth()/2);
|
||||
quitButton.setX(applicationWidth / 2f + quitButton.getWidth() / 2);
|
||||
this.roboRallyWrapper = roboRallyWrapper;
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
}
|
||||
@ -54,11 +55,11 @@ public class WinnerScreen extends AbstractScreen {
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "The winner is: " +
|
||||
roboRallyWrapper.roboRallyGame.getWinningPlayerName(),applicationWidth / 2f - 380 / 2f,
|
||||
applicationHeight / 2f + 100,380, 1,
|
||||
roboRallyWrapper.roboRallyGame.getWinningPlayerName(), applicationWidth / 2f - 380 / 2f,
|
||||
applicationHeight / 2f + 100, 380, 1,
|
||||
true);
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to exit the game",
|
||||
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
|
||||
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
|
||||
true);
|
||||
roboRallyWrapper.batch.end();
|
||||
stage.draw();
|
||||
|
Loading…
x
Reference in New Issue
Block a user