This commit is contained in:
Kristian Knarvik 2020-04-14 12:28:22 +02:00
commit db08c273ce
39 changed files with 1046 additions and 373 deletions

View File

@ -0,0 +1,13 @@
## Oppmøte
Tilstede: Steinar, Gabriel, Kristian, Torbjørn, Petter
Ikke tilstede:
## Agenda
- Hørre om det er noen utfordringer/spørmsål
- Fortsette arbeidet
## Møte
Starter møte med å gå igjennom mail som sier noe om endring av prosjekt. Prosjekteleder gir uttrykk for hvordan han
tenker vi burde gå frem. Enighet i gruppen.
Etter dette deler vi opp i grupper og jobber videre.

View File

@ -0,0 +1,15 @@
## Oppmøte
Tilstede: Steinar, Gabriel, Kristian, Torbjørn, Petter
Ikke tilstede:
## Agenda
- Få opp en fungerende server/client
- Diskutere designvalg og class layout angående server/client kommunikasjon
## Møte
Startet møte ved å ta valg anngående møtetid i ferien. Blir bestemt å fjerne faste møter, men istedenfor
holde arbeidet litt mer flytende, gjerne avtaler for møter 2 og 2.
Vi jobbet me å få startet en server og koble til den via LAN, og diskuterte hvordan koden skulle håndtere
kommunikasjon mellom hverandre og hvordan man skulle koble til hverandre.
Kodet i plenum.

View File

@ -1,48 +0,0 @@
package inf112.fiasko.roborally.game_wrapper;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
public class MainMenuScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
private final Viewport viewport;
public MainMenuScreen(final RoboRallyWrapper roboRallyWrapper) {
this.roboRallyWrapper = roboRallyWrapper;
camera = new OrthographicCamera();
camera.setToOrtho(false, 400, 400);
viewport = new ExtendViewport(400, 400, camera);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.2f, 1f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Robo Rally", 10, 250,
380, 1, true);
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click anywhere to run the demo", 10, 200,
380, 1, true);
roboRallyWrapper.batch.end();
if (Gdx.input.isTouched()) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper));
dispose();
}
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
}
}

View File

@ -1,13 +0,0 @@
package inf112.fiasko.roborally.game_wrapper;
import com.badlogic.gdx.Input;
public class MyTextInputListener implements Input.TextInputListener {
@Override
public void input (String text) {
}
@Override
public void canceled () {
}
}

View File

@ -6,16 +6,15 @@ 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.networking.SomeResponse;
import inf112.fiasko.roborally.objects.IDrawableGame;
import java.io.IOException;
public class RoboRallyWrapper extends Game {
public SpriteBatch batch;
public BitmapFont font;
public ScreenManager screenManager;
public IDrawableGame roboRallyGame;
public RoboRallyServer server;
public RoboRallyClient client;
@Override
public void create() {
@ -23,15 +22,6 @@ public class RoboRallyWrapper extends Game {
font = new BitmapFont(Gdx.files.internal("assets/Montserrat-Regular.fnt"));
this.screenManager = new ScreenManager();
this.setScreen(screenManager.getStartMenuScreen(this));
try {
RoboRallyServer server = new RoboRallyServer();
RoboRallyClient client = new RoboRallyClient();
SomeResponse response = new SomeResponse();
response.text = "ÆÆÆÆÆÆÆÆÆ";
server.sendToAllClients(response);
} catch (IOException e) {
e.printStackTrace();
}
}
public void dispose() {

View File

@ -1,20 +1,31 @@
package inf112.fiasko.roborally.game_wrapper;
import inf112.fiasko.roborally.game_wrapper.screens.BoardActiveScreen;
import inf112.fiasko.roborally.game_wrapper.screens.CardChoiceScreen;
import inf112.fiasko.roborally.game_wrapper.screens.LoadingScreen;
import inf112.fiasko.roborally.game_wrapper.screens.PowerDownScreen;
import inf112.fiasko.roborally.game_wrapper.screens.UsernameScreen;
import inf112.fiasko.roborally.game_wrapper.screens.IPAddressScreen;
import inf112.fiasko.roborally.game_wrapper.screens.LobbyScreen;
import inf112.fiasko.roborally.game_wrapper.screens.StartMenuScreen;
/**
* Keeps track of screen instances
*/
public class ScreenManager {
private MainMenuScreen mainMenuScreen;
private BoardActiveScreen boardActiveScreen;
private CardChoiceScreen cardChoiceScreen;
private PowerDownScreen powerDownScreen;
private LoadingScreen loadingScreen;
private StartMenuScreen startMenuScreen;
private UsernameScreen usernameScreen;
private IPAddressScreen ipAddressScreen;
private LobbyScreen lobbyScreen;
/**
* Gets an instance of the main menu screen
* @param roboRallyWrapper The robo rally launcher instance to use
* @return A main menu screen instance
* Gets an instance of the power down screen
* @param roboRallyWrapper The Robo Rally launcher instance to use
* @return A power down screen instance
*/
public synchronized PowerDownScreen getPowerDownScreen(RoboRallyWrapper roboRallyWrapper) {
if (this.powerDownScreen == null) {
@ -23,13 +34,56 @@ public class ScreenManager {
return powerDownScreen;
}
public synchronized StartMenuScreen getStartMenuScreen(RoboRallyWrapper roboRallyWrapper) {
if (this.startMenuScreen == null) {
this.startMenuScreen = new StartMenuScreen(roboRallyWrapper);
/**
* Gets an instance of the lobby screen
* @param roboRallyWrapper The Robo Rally launcher instance to use
* @return A lobby screen instance
*/
public synchronized LobbyScreen getLobbyScreen(RoboRallyWrapper roboRallyWrapper) {
if (this.lobbyScreen == null) {
this.lobbyScreen = new LobbyScreen(roboRallyWrapper);
}
return startMenuScreen;
return lobbyScreen;
}
/**
* Gets an instance of the ip address screen
* @param roboRallyWrapper The Robo Rally launcher instance to use
* @return An ip address screen instance
*/
public synchronized IPAddressScreen getIPAddressScreen(RoboRallyWrapper roboRallyWrapper) {
if (this.ipAddressScreen == null) {
this.ipAddressScreen = new IPAddressScreen(roboRallyWrapper);
}
return ipAddressScreen;
}
/**
* Gets an instance of the username screen
* @param roboRallyWrapper The Robo Rally launcher instance to use
* @return A username screen instance
*/
public synchronized UsernameScreen getUsernameScreen(RoboRallyWrapper roboRallyWrapper) {
if (this.usernameScreen == null) {
this.usernameScreen = new UsernameScreen(roboRallyWrapper);
}
return usernameScreen;
}
/**
* Gets an instance of the start menu screen
* @param roboRallyWrapper The Robo Rally launcher instance to use
* @return A start menu screen instance
*/
public synchronized StartMenuScreen getStartMenuScreen(RoboRallyWrapper roboRallyWrapper) {
return new StartMenuScreen(roboRallyWrapper);
}
/**
* Gets an instance of the loading screen
* @param roboRallyWrapper The Robo Rally launcher instance to use
* @return A loading screen instance
*/
public synchronized LoadingScreen getLoadingScreen(RoboRallyWrapper roboRallyWrapper) {
if (this.loadingScreen == null) {
this.loadingScreen = new LoadingScreen(roboRallyWrapper);
@ -37,21 +91,9 @@ public class ScreenManager {
return loadingScreen;
}
/**
* Gets an instance of the main menu screen
* @param roboRallyWrapper The robo rally launcher instance to use
* @return A main menu screen instance
*/
public synchronized MainMenuScreen getMainMenuScreen(RoboRallyWrapper roboRallyWrapper) {
if (this.mainMenuScreen == null) {
this.mainMenuScreen = new MainMenuScreen(roboRallyWrapper);
}
return mainMenuScreen;
}
/**
* Gets an instance of the board active screen
* @param roboRallyWrapper The robo rally launcher instance to use
* @param roboRallyWrapper The Robo Rally launcher instance to use
* @return A board active screen instance
*/
public synchronized BoardActiveScreen getBoardActiveScreen(RoboRallyWrapper roboRallyWrapper) {
@ -62,9 +104,9 @@ 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
* Gets an instance of the card choice screen
* @param roboRallyWrapper The Robo Rally launcher instance to use
* @return A card choice screen instance
*/
public synchronized CardChoiceScreen getCardChoiceScreen(RoboRallyWrapper roboRallyWrapper) {
if (this.cardChoiceScreen == null) {

View File

@ -1,8 +1,14 @@
package inf112.fiasko.roborally.game_wrapper;
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Screen;
/**
* This class overrides methods of screens which are often unused
*/
public abstract class AbstractScreen implements Screen {
protected final int applicationWidth = 600;
protected final int applicationHeight = 800;
@Override
public void show() {
//Nothing to do

View File

@ -1,9 +1,8 @@
package inf112.fiasko.roborally.game_wrapper;
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@ -13,14 +12,17 @@ import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.objects.IDrawableGame;
import inf112.fiasko.roborally.objects.IDrawableObject;
import inf112.fiasko.roborally.objects.RoboRallyGame;
import inf112.fiasko.roborally.utility.IOUtil;
import inf112.fiasko.roborally.utility.TextureConverterUtil;
import java.util.List;
/**
* This screen shows the game board in real time
*/
public class BoardActiveScreen extends AbstractScreen implements InputProcessor {
private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
@ -35,22 +37,24 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
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) {
this.roboRallyWrapper = roboRallyWrapper;
roboRallyWrapper.roboRallyGame = new RoboRallyGame();
debugGame = new RoboRallyGame(true);
camera = new OrthographicCamera();
camera.setToOrtho(false, viewPortWidth, viewPortHeight);
camera.position.set(viewPortWidth/2f, viewPortHeight/2f, 0);
camera.position.set(viewPortWidth / 2f, viewPortHeight / 2f, 0);
viewport = new ExtendViewport(viewPortWidth, viewPortHeight, camera);
Gdx.input.setInputProcessor(this);
lastTouch = new Vector2();
}
@Override
public void show() {
Gdx.input.setInputProcessor(this);
resetCamera();
}
@ -80,13 +84,13 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
}
@Override
public boolean keyDown(int keycode) {
public boolean keyDown(int keyCode) {
return false;
}
@Override
public boolean keyUp(int keycode) {
if (keycode == Input.Keys.HOME) {
public boolean keyUp(int keyCode) {
if (keyCode == Input.Keys.HOME) {
IDrawableGame temp = roboRallyWrapper.roboRallyGame;
roboRallyWrapper.roboRallyGame = debugGame;
this.debugGame = temp;
@ -100,7 +104,7 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
if (character == 'r') {
//camera.rotate(-90);
camera.rotateAround(
new Vector3(viewPortWidth/2f, viewPortHeight/2f, 0),
new Vector3(viewPortWidth / 2f, viewPortHeight / 2f, 0),
new Vector3(0, 0, 1), 90);
return true;
} else if (character == 'q') {
@ -152,7 +156,7 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
camera.up.x = 0;
camera.up.y = 1;
cameraZoom = 1;
camera.position.set(viewPortWidth/2f, viewPortHeight/2f, 0);
camera.position.set(viewPortWidth / 2f, viewPortHeight / 2f, 0);
}
/**
@ -165,7 +169,7 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
for (IDrawableObject 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(),

View File

@ -1,4 +1,4 @@
package inf112.fiasko.roborally.game_wrapper;
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
@ -9,13 +9,14 @@ import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.InputListener;
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.game_wrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.game_wrapper.SimpleButton;
import inf112.fiasko.roborally.objects.IDeck;
import inf112.fiasko.roborally.objects.ProgrammingCard;
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
@ -42,10 +43,11 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
private final List<CardRectangle> chosenCards;
private final int maxCards;
private final Stage stage;
private final InputMultiplexer inputMultiplexer;
/**
* Initializes a new card choice screen
* @param roboRallyWrapper The robo rally wrapper which is its parent
* Instantiates a new card choice screen
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
this.roboRallyWrapper = roboRallyWrapper;
@ -58,8 +60,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
shapeRenderer = new ShapeRenderer();
shapeRenderer.setAutoShapeType(true);
InputMultiplexer inputMultiplexer = new InputMultiplexer();
inputMultiplexer.addProcessor(this);
inputMultiplexer = new InputMultiplexer();
try {
generateCards();
@ -69,25 +70,25 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
this.chosenCards = new ArrayList<>();
this.maxCards = 5;
stage = new Stage();
inputMultiplexer.addProcessor(stage);
TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton();
stage.addActor(confirmCards);
confirmCards.setY(viewport.getWorldHeight() + 60);
confirmCards.setY(viewport.getWorldHeight() - confirmCards.getHeight());
confirmCards.setX(15);
confirmCards.setTouchable(Touchable.enabled);
confirmCards.addListener(new InputListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
System.out.println(chosenCards.size());
System.out.println(maxCards);
if (chosenCards.size() == maxCards) {
System.out.println("Lock cards!");
return true;
}
return false;
}
});
Gdx.input.setInputProcessor(inputMultiplexer);
stage.setViewport(viewport);
inputMultiplexer.addProcessor(this);
inputMultiplexer.addProcessor(stage);
}
/**
@ -117,7 +118,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
@Override
public void show() {
//Nothing to do
Gdx.input.setInputProcessor(inputMultiplexer);
}
@Override
@ -241,9 +242,14 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
*/
class CardRectangle {
protected final Rectangle rectangle;
protected boolean selected = false;
protected final ProgrammingCard card;
protected boolean selected = false;
/**
* Instantiates a new card rectangle
* @param rectangle The rectangle of this card rectangle
* @param card The card of this card rectangle
*/
CardRectangle(Rectangle rectangle, ProgrammingCard card) {
this.rectangle = rectangle;
this.card = card;

View File

@ -0,0 +1,98 @@
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.networking.RoboRallyClient;
import javax.swing.*;
import java.io.IOException;
/**
* This screen allows the user to enter the ip address to connect to
*/
public class IPAddressScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
private final Viewport viewport;
private final Stage stage;
private TextField txtinput;
/**
* Instantiates a new ip address screen
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/
public IPAddressScreen(final RoboRallyWrapper roboRallyWrapper) {
stage = new Stage();
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.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true;
}
@Override
public void touchUp(InputEvent e, float x, float y, int point, int button) {
try {
roboRallyWrapper.client = new RoboRallyClient(txtinput.getText(),roboRallyWrapper);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper));
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Could not connect to the server."
+ " Please make sure the ip address you typed is correct, and that the server is online.");
}
}
});
txtinput = new TextField("", skin);
txtinput.setPosition(applicationWidth/2f -txtinput.getWidth()/2f,250);
txtinput.setSize(150,40);
stage.addActor(txtinput);
stage.addActor(joinButton);
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
stage.setViewport(viewport);
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
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,
true);
roboRallyWrapper.batch.end();
stage.draw();
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
}
}

View File

@ -1,12 +1,15 @@
package inf112.fiasko.roborally.game_wrapper;
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
/**
* This screen is used to wait for something
*/
public class LoadingScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper;
@ -14,9 +17,11 @@ public class LoadingScreen extends AbstractScreen {
private final Viewport viewport;
private long startTime;
private final int applicationWidth = 600;
private final int applicationHeight = 800;
/**
* Instantiates a new loading screen
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/
public LoadingScreen(final RoboRallyWrapper roboRallyWrapper) {
this.roboRallyWrapper = roboRallyWrapper;
camera = new OrthographicCamera();
@ -35,12 +40,12 @@ 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();
long time = System.currentTimeMillis();
if (time-startTime>10000){
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getMainMenuScreen(this.roboRallyWrapper));
dispose();
//TODO: Allow to set any condition and next screen
if (time - startTime > 5000){
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper));
}
}
@ -49,4 +54,9 @@ public class LoadingScreen extends AbstractScreen {
viewport.update(width, height);
}
@Override
public void show(){
startTime = System.currentTimeMillis();
}
}

View File

@ -0,0 +1,87 @@
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
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.game_wrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.game_wrapper.SimpleButton;
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
import inf112.fiasko.roborally.objects.Player;
import inf112.fiasko.roborally.utility.IOUtil;
import java.util.List;
/**
* This screen allows the host to wait for players to join
*/
public class LobbyScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
private final Viewport viewport;
private final Stage stage;
/**
* 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();
stage.addActor(startGameButton);
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) {
List<Player> playerlist = IOUtil.playerGenerator(roboRallyWrapper.server.getPlayerNames(),
roboRallyWrapper.server.getRobotID());
roboRallyWrapper.server.sendToAllClients(new GameStartInfo("Checkmate.txt",playerlist));
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
return true;//her we do stuff
}
});
stage.setViewport(viewport);
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Joined players: " +
roboRallyWrapper.server.getPlayerNames().values().toString(),
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,
true);
roboRallyWrapper.batch.end();
stage.draw();
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
}
}

View File

@ -1,4 +1,4 @@
package inf112.fiasko.roborally.game_wrapper;
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
@ -9,7 +9,12 @@ 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.game_wrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.game_wrapper.SimpleButton;
/**
* This screen is used for asking players whether they want to power down
*/
public class PowerDownScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper;
@ -17,31 +22,32 @@ public class PowerDownScreen extends AbstractScreen {
private final Viewport viewport;
private final Stage stage;
private long startTime;
private final int applicationWidth = 600;
private final int applicationHeight = 800;
private Boolean buttonPressed = false;
/**
* Instantiates a new power down screen
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/
public PowerDownScreen(final RoboRallyWrapper roboRallyWrapper) {
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
stage = new Stage();
stage.setViewport(viewport);
TextButton powerDownButton = new SimpleButton("PowerDown", roboRallyWrapper.font).getButton();
stage.addActor(powerDownButton);
powerDownButton.setY(applicationHeight / 2f);
powerDownButton.setX(applicationWidth / 2f + powerDownButton.getWidth() / 4f);
powerDownButton.setY(applicationHeight / 2f-50);
powerDownButton.setX(applicationWidth / 2f - powerDownButton.getWidth() / 2f);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
Gdx.input.setInputProcessor(stage);
startTime = System.currentTimeMillis();
powerDownButton.addListener(new InputListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
buttonPressed = true;
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
return true;//her we do stuff
}
});
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.2f, 1f, 0.2f, 1);
@ -53,18 +59,16 @@ public class PowerDownScreen extends AbstractScreen {
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, true);
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, true);
applicationWidth / 2f - 40 / 2f,applicationHeight / 2f - 100,40, 1,
true);
roboRallyWrapper.batch.end();
stage.draw();
if (elapsedTime > 10) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getMainMenuScreen(this.roboRallyWrapper));
dispose();
} else if (buttonPressed) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
dispose();
}
}
@ -73,4 +77,10 @@ public class PowerDownScreen extends AbstractScreen {
viewport.update(width, height);
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
startTime = System.currentTimeMillis();
}
}

View File

@ -1,8 +1,6 @@
package inf112.fiasko.roborally.game_wrapper;
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
@ -11,92 +9,89 @@ 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.game_wrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.game_wrapper.SimpleButton;
import inf112.fiasko.roborally.networking.RoboRallyClient;
import inf112.fiasko.roborally.networking.RoboRallyServer;
import java.io.IOException;
/**
* This screen is the first screen shown to a player
*/
public class StartMenuScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
private final Viewport viewport;
private final Stage stage;
private final int applicationWidth = 600;
private final int applicationHeight = 800;
/**
* Instantiates a new start menu screen
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/
public StartMenuScreen(final RoboRallyWrapper roboRallyWrapper) {
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
stage = new Stage();
stage.setViewport(viewport);
TextButton serverButton = new SimpleButton("Create", roboRallyWrapper.font).getButton();
stage.addActor(serverButton);
serverButton.setY(applicationHeight/2f);
serverButton.setX(applicationWidth/2f);
serverButton.setY(applicationHeight / 2f);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
Gdx.input.setInputProcessor(stage);
Input.TextInputListener nameInputClient = new Input.TextInputListener() {
@Override
public void input(String name) {
//TODO: do something with the name
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getMainMenuScreen(roboRallyWrapper));
dispose();
}
@Override
public void canceled() {
}
};
Input.TextInputListener nameInputServer = new Input.TextInputListener() {
@Override
public void input(String name) {
//TODO: do something with the name
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
dispose();
}
@Override
public void canceled() {
}
};
serverButton.addListener(new InputListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
Gdx.input.getTextInput(nameInputServer, "Name input", "input name her", "");
return true; // Here do stuff
try {
roboRallyWrapper.server = new RoboRallyServer();
roboRallyWrapper.client = new RoboRallyClient("127.0.0.1", roboRallyWrapper);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper));
} catch (IOException e) {
e.printStackTrace();
//Hard fail
Gdx.app.error("Server error", "Server could not be started");
Gdx.app.exit();
}
return true;
}
});
TextButton clientButton = new SimpleButton("Join", roboRallyWrapper.font).getButton();
stage.addActor(clientButton);
clientButton.setY(applicationHeight/2f);
clientButton.setX(applicationWidth/2f+serverButton.getWidth()+20);
clientButton.setY(applicationHeight / 2f);
camera.setToOrtho(false, applicationWidth, applicationHeight);
Gdx.input.setInputProcessor(stage);
clientButton.addListener(new InputListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
Gdx.input.getTextInput(nameInputClient, "Name input", "input name her", "");
return true;// Here we do stuff
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper));
return true;
}
});
TextButton quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton();
stage.addActor(quitButton);
quitButton.setY(applicationHeight/2f);
quitButton.setX(applicationWidth/2f+serverButton.getWidth()+40+clientButton.getWidth());
quitButton.setY(applicationHeight / 2f);
camera.setToOrtho(false, applicationWidth, applicationHeight);
Gdx.input.setInputProcessor(stage);
quitButton.addListener(new InputListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
System.exit(0);
return true;//her we do stuff
Gdx.app.exit();
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);
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
@ -106,7 +101,8 @@ public class StartMenuScreen extends AbstractScreen {
roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "RoboRally",
applicationWidth/2f-380/2f,applicationHeight/2f +100,380, 1, true);
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
true);
roboRallyWrapper.batch.end();
stage.draw();
}
@ -115,5 +111,4 @@ public class StartMenuScreen extends AbstractScreen {
public void resize(int width, int height) {
viewport.update(width, height);
}
}

View File

@ -0,0 +1,107 @@
package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
/**
* This screen allows a user to choose their player name
*/
public class UsernameScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
private final Viewport viewport;
private final Stage stage;
private TextField textInput;
/**
* Instantiates a new username screen
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/
public UsernameScreen(final RoboRallyWrapper roboRallyWrapper) {
stage = new Stage();
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.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true;
}
@Override
public void touchUp(InputEvent e, float x, float y, int point, int button) {
String userName = textInput.getText();
if (nameInvalid(userName)) {
return;
}
roboRallyWrapper.client.sendElement(userName);
if (roboRallyWrapper.server == null) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
} else{
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLobbyScreen(roboRallyWrapper));
}
}
});
textInput = new TextField("",skin);
textInput.setPosition(applicationWidth/2f - textInput.getWidth()/2,250);
textInput.setSize(150,40);
stage.addActor(textInput);
stage.addActor(confirm);
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
stage.setViewport(viewport);
}
/**
* Checks whether the username is invalid
* @param userName The username the user wants
* @return False if the username can be used
*/
private boolean nameInvalid(String userName) {
//TODO: Find a way to ask the server if the name is taken
return "".equals(userName);
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to enter username",
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
true);
roboRallyWrapper.batch.end();
stage.draw();
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
}
}

View File

@ -3,34 +3,69 @@ package inf112.fiasko.roborally.networking;
import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
import inf112.fiasko.roborally.objects.RoboRallyGame;
import inf112.fiasko.roborally.utility.NetworkUtil;
import java.io.IOException;
/**
* This class represents a client capable of connecting to a Robo Rally server
*/
public class RoboRallyClient {
public RoboRallyClient() throws IOException {
Client client = new Client();
private final Client client;
/**
* Instantiates a new Robo Rally client
* @param ipAddress The ip address of the server to connect to
* @param wrapper The Robo Rally wrapper to be used
* @throws IOException If the server cannot be reached
*/
public RoboRallyClient(String ipAddress, RoboRallyWrapper wrapper) throws IOException {
client = new Client();
client.start();
NetworkUtil.registerClasses(client.getKryo());
client.connect(5000, "127.0.0.1", 54555, 54777);
client.connect(5000, ipAddress, 54555, 54777);
SomeRequest request = new SomeRequest();
request.text = "Here is the request";
client.sendTCP(request);
client.addListener(new RoboRallyClientListener(wrapper));
}
client.addListener(new RoboRallyClientListener());
/**
* Sends something to the server
* @param object The object to send to the server
*/
public void sendElement(Object object) {
client.sendTCP(object);
}
}
/**
* This listener handles all receiving from the server
*/
class RoboRallyClientListener extends Listener {
private final RoboRallyWrapper wrapper;
/**
* Instantiates a new Robo Rally client listener
* @param wrapper The Robo Rally wrapper to interact with
*/
RoboRallyClientListener(RoboRallyWrapper wrapper) {
super();
this.wrapper = wrapper;
}
@Override
public void received (Connection connection, Object object) {
if (object instanceof SomeResponse) {
SomeResponse response = (SomeResponse)object;
System.out.println("Client received: " + response.text);
} else if (object instanceof ErrorResponse) {
if (object instanceof ErrorResponse) {
ErrorResponse errorResponse = (ErrorResponse) object;
System.out.println(errorResponse.getErrorMessage());
} else if (object instanceof GameStartInfo) {
GameStartInfo info = (GameStartInfo) object;
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
wrapper.server != null);
}
}
}
}

View File

@ -4,22 +4,24 @@ import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;
import inf112.fiasko.roborally.element_properties.RobotID;
import inf112.fiasko.roborally.objects.IDeck;
import inf112.fiasko.roborally.objects.ProgrammingCard;
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
import inf112.fiasko.roborally.utility.NetworkUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* This class represents a Robo Rally Server
*/
public class RoboRallyServer {
private Server server;
private IDeck<ProgrammingCard> programmingCardDeck;
private final Server server;
private RoboRallyServerListener listener;
/**
* Instantiates a new Robo Rally server
* @throws IOException If the server cannot be started
*/
public RoboRallyServer() throws IOException {
server = new Server();
server.start();
@ -27,9 +29,23 @@ public class RoboRallyServer {
server.bind(54555, 54777);
listener = new RoboRallyServerListener();
server.addListener(listener);
programmingCardDeck = DeckLoaderUtil.loadProgrammingCardsDeck();
}
/**
* Gets a map between connections and their robot id
* @return A mapping between connections and robot ids
*/
public Map<Connection, RobotID> getRobotID() {
return listener.getRobotID();
}
/**
* Gets a map between connections and their player name
* @return A mapping between connections and robot ids
*/
public Map<Connection, String> getPlayerNames() {
return listener.getPlayerNames();
}
/**
* Sends an object to all clients
* @param object The object to send
@ -37,38 +53,51 @@ public class RoboRallyServer {
public void sendToAllClients(Object object) {
server.sendToAllTCP(object);
}
/**
* Deals cards to all players
*/
public void dealCards() {
programmingCardDeck.shuffle();
for (Connection connection : server.getConnections()) {
IDeck<ProgrammingCard> hand = new ProgrammingCardDeck(new ArrayList<>());
hand.draw(programmingCardDeck, 9);
connection.sendTCP(hand);
}
}
}
/**
* This listener handles all sending and responses for the server
*/
class RoboRallyServerListener extends Listener {
protected Connection host;
protected Map<Connection, RobotID> clients;
private Connection host;
private final Map<Connection, RobotID> clients;
private final Map<Connection, String> playerNames;
public RoboRallyServerListener() {
/**
* Instantiates a new Robo Rally server listener
*/
RoboRallyServerListener() {
super();
clients = new HashMap<>();
playerNames = new HashMap<>();
}
/**
* Gets a map between connections and their player name
* @return A mapping between connections and robot ids
*/
public Map<Connection, String> getPlayerNames() {
return playerNames;
}
/**
* Gets a map between connections and their robot id
* @return A mapping between connections and robot ids
*/
public Map<Connection, RobotID> getRobotID() {
return clients;
}
@Override
public void received (Connection connection, Object object) {
if (object instanceof SomeRequest) {
SomeRequest request = (SomeRequest)object;
System.out.println(request.text);
SomeResponse response = new SomeResponse();
response.text = "Thanks";
connection.sendTCP(response);
if (object instanceof String) {
String playerName = (String) object;
if (playerNames.values().contains(playerName)) {
String errorMessage = "The player name send is already taken.";
connection.sendTCP(new ErrorResponse(errorMessage, new IllegalArgumentException(errorMessage)));
} else {
playerNames.put(connection, playerName);
}
}
}

View File

@ -1,8 +0,0 @@
package inf112.fiasko.roborally.networking;
/**
* Represents a request to the server
*/
public class SomeRequest {
public String text;
}

View File

@ -1,8 +0,0 @@
package inf112.fiasko.roborally.networking;
/**
* Represents a response from a client
*/
public class SomeResponse {
public String text;
}

View File

@ -1,10 +1,10 @@
package inf112.fiasko.roborally.networking;
package inf112.fiasko.roborally.networking.containers;
/**
* This class represents a response saying that something went wrong with the request
*/
public class ErrorResponse {
private String errorMessage;
private final String errorMessage;
private Exception thrownException;
/**

View File

@ -0,0 +1,61 @@
package inf112.fiasko.roborally.networking.containers;
import inf112.fiasko.roborally.objects.Player;
import java.util.List;
/**
* This class contains information about the game board to be used and the game's players
*/
public class GameStartInfo {
private String boardName;
private List<Player> playerList;
/**
* Empty initialization method used by kryo
*/
public GameStartInfo() {}
/**
* Sets the name of the board to be used
* @param boardName The name of the board to be used, with extension
*/
public void setBoardName(String boardName) {
this.boardName = boardName;
}
/**
* Sets the list of players for the game
* @param playerList List of players for the game
*/
public void setPlayerList(List<Player> playerList) {
this.playerList = playerList;
}
/**
* Instantiates a new GameStartInfo object
* @param boardName The name of the board to be used, with extension
* @param playerList List of players for the game
*/
public GameStartInfo(String boardName, List<Player> playerList) {
this.boardName = boardName;
this.playerList = playerList;
}
/**
* Gets the list of players
* @return A list of players
*/
public List<Player> getPlayerList() {
return playerList;
}
/**
* Gets the board name
* @return The board name
*/
public String getBoardName() {
return boardName;
}
}

View File

@ -172,6 +172,16 @@ public class Board {
}
}
}
/**
* Get the damage of a specific robot
* @param robot The RobotID of a robot
* @return The amount of damage the robot has currently
*/
public int getRobotDamage(RobotID robot) {
return robots.get(robot).getDamageTaken();
}
/**
* Moves a robot one unit in a specified direction
* @param robotID ID of the robot to move

View File

@ -10,6 +10,9 @@ import java.util.Random;
public abstract class Deck<T> implements IDeck<T> {
private final List<T> cardList;
public Deck (){
this.cardList=new ArrayList<>();
}
/**
* Initializes the deck with cards
* @param cardList list of cards

View File

@ -6,14 +6,14 @@ import java.util.ArrayList;
import java.util.List;
/**
* This Class represents a player
* This class represents a player
*/
public class Player {
private final RobotID robotID;
private final String name;
private RobotID robotID;
private String name;
private boolean powerDownNextRound = false;
private ProgrammingCardDeck playerDeck;
private ProgrammingCardDeck lockedPlayerDeck;
private List <ProgrammingCard> program;
/**
@ -22,10 +22,32 @@ public class Player {
* @param name the unique name of the player
*/
public Player(RobotID robotID, String name) {
this.playerDeck = new ProgrammingCardDeck(new ArrayList<>());
this.robotID = robotID;
this.name = name;
}
/**
* Empty constructor required by kryo
*/
public Player(){}
/**
* Sets the robot id of the robot
* @param robotID The new id of the robot
*/
public void setRobotID(RobotID robotID) {
this.robotID = robotID;
}
/**
* Sets the name of the robot
* @param name The new name of the robot
*/
public void setName(String name) {
this.name = name;
}
/**
* Gives you the RobotID of a player
* @return A RobotID
@ -66,6 +88,22 @@ public class Player {
return playerDeck;
}
/**
* Gives you the player deck with locked cards
* @return a deck with locked cards
*/
public ProgrammingCardDeck getLockedPlayerDeck() {
return lockedPlayerDeck;
}
/**
* Set the players locked deck to the given deck
* @param lockedPlayerDeck A deck of locked cards kept by the player
*/
public void setLockedPlayerDeck(ProgrammingCardDeck lockedPlayerDeck) {
this.lockedPlayerDeck = lockedPlayerDeck;
}
/**
* Gives you the players power down status
* @return Whether the player is to power down

View File

@ -41,6 +41,15 @@ public class ProgrammingCard implements Comparable<ProgrammingCard> {
return this.getPriority() + " " + this.cardAction.toString();
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ProgrammingCard)) {
return false;
}
ProgrammingCard otherCard = (ProgrammingCard) other;
return otherCard.cardAction == this.cardAction && otherCard.cardPriority == this.cardPriority;
}
@Override
public int compareTo(ProgrammingCard programmingCard) {
return programmingCard.cardPriority - this.cardPriority;

View File

@ -14,4 +14,5 @@ public class ProgrammingCardDeck extends Deck<ProgrammingCard> {
public ProgrammingCardDeck(List<ProgrammingCard> cardList) {
super(cardList);
}
public ProgrammingCardDeck(){}
}

View File

@ -24,27 +24,32 @@ public class RoboRallyGame implements IDrawableGame {
private List<BoardElementContainer<Tile>> cogwheels;
private List<BoardElementContainer<Tile>> conveyorBelts;
private List<BoardElementContainer<Tile>> fastConveyorBelts;
private List<Player> playerList;
private List<BoardElementContainer<Tile>> repairTiles;
private final List<Player> playerList;
private final boolean host;
private Deck<ProgrammingCard> mainDeck;
/**
* Instantiates a new robo rally game
* @param debug Whether to start the game in debugging mode
*/
public RoboRallyGame(boolean debug) {
this.host=false;
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, boolean debug) {
this.host = host;
this.playerList = playerList;
if (debug) {
initializeDebugMode();
} else {
initializeGame();
initializeGame(boardName);
}
}
/**
* Instantiates a new robo rally game
*/
public RoboRallyGame() {
this.host=false;
initializeGame();
public RoboRallyGame(List<Player> playerList, String boardName,boolean host) {
this.host = host;
this.playerList = playerList;
initializeGame(boardName);
}
@Override
@ -85,6 +90,7 @@ public class RoboRallyGame implements IDrawableGame {
long cycleDelay = 600;
TimeUnit.MILLISECONDS.sleep(cycleDelay);
}
/**
* Initializes the game with a debugging board
*/
@ -108,25 +114,27 @@ public class RoboRallyGame implements IDrawableGame {
/**
* Initializes the game with a playable board
*/
private void initializeGame() {
private void initializeGame(String boardName) {
try {
List<Robot> robots = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1)));
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 2)));
robots.add(new Robot(RobotID.ROBOT_3, new Position(1, 3)));
robots.add(new Robot(RobotID.ROBOT_4, new Position(4, 8)));
robots.add(new Robot(RobotID.ROBOT_5, new Position(6, 6)));
robots.add(new Robot(RobotID.ROBOT_6, new Position(7, 7)));
robots.add(new Robot(RobotID.ROBOT_7, new Position(6, 7)));
robots.add(new Robot(RobotID.ROBOT_8, new Position(6, 8)));
//TODO: Find correct robot spawn positions
int posX = 1;
for (Player player : playerList) {
Position spawn = new Position(posX,1);
robots.add(new Robot(player.getRobotID(), spawn));
posX++;
}
initializePlayers();
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
gameBoard = BoardLoaderUtil.loadBoard("boards/" + boardName, robots);
generateTileLists();
if (host) {
mainDeck = DeckLoaderUtil.loadProgrammingCardsDeck();
}
new Thread(() -> {
try {
runGameLoop();
runTurn();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
@ -136,32 +144,6 @@ public class RoboRallyGame implements IDrawableGame {
}
}
/**
* Initializes all players
* @throws IOException If interrupted while trying to sleep
*/
private void initializePlayers() throws IOException {
playerList = new ArrayList<>();
playerList.add(new Player(RobotID.ROBOT_1, "Player1"));
playerList.add(new Player(RobotID.ROBOT_2, "Player2"));
playerList.add(new Player(RobotID.ROBOT_3, "Player3"));
playerList.add(new Player(RobotID.ROBOT_4, "Player4"));
playerList.add(new Player(RobotID.ROBOT_5, "Player5"));
playerList.add(new Player(RobotID.ROBOT_6, "Player6"));
playerList.add(new Player(RobotID.ROBOT_7, "Player7"));
playerList.add(new Player(RobotID.ROBOT_8, "Player8"));
Deck<ProgrammingCard> cards = DeckLoaderUtil.loadProgrammingCardsDeck();
for (Player player : playerList) {
cards.shuffle();
List<ProgrammingCard> testProgram = new ArrayList<>();
for (int i = 0; i < 5; i++) {
cards.shuffle();
testProgram.add(cards.peekTop());
}
player.setInProgram(testProgram);
}
}
/**
* Generates lists containing board element containers with all tiles of certain types
*/
@ -180,20 +162,145 @@ public class RoboRallyGame implements IDrawableGame {
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_RIGHT,
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_LEFT,
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
}
/**
* Does whatever the game wants to do
* Runs all the steps of one turn in the game
* @throws InterruptedException If interrupted while trying to sleep
*/
private void runGameLoop() throws InterruptedException {
TimeUnit.SECONDS.sleep(3);
private void runTurn() throws InterruptedException {
// The method should follow this sequence:
/*
Tilegne programeringskort
Programmer roboten
i power down
Kjør 5 faser
Flagg + reprasjonstiles reparerer
Fjerner ulåste programmeringskort
Spør om de i power down skal fortsette i power down
Respawn roboter
*/
// Sets the power down status to true on robots that have players who planned one this turn.
// Resets players power down for next turn to false.
updateRobotPowerDown();
// Set damage of robots in power down to 0
gameBoard.executePowerdown();
if (host) {
distributeProgrammingCardsToPlayers();
}
// TODO: Make program for this player, if not in power down
// TODO: Ask player for new power down
// Run the phases of the game
runPhase(1);
runPhase(2);
runPhase(3);
runPhase(4);
runPhase(5);
// Repair robots on repair tiles
repairAllRobotsOnRepairTiles();
if (host) {
updateLockedProgrammingCardsForAllPlayers();
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();
}
/**
* Resets the boolean for if the robot has touched a flag this turn, to set up the next turn.
*/
private void resetHasTouchedFlagThisTurnForAllRobots() {
for (Robot robot : gameBoard.getAliveRobots()) {
robot.setHasTouchedFlagThisTurn(false);
}
}
/**
* Locks the players programming cards in relation to the robots damage
*/
private void updateLockedProgrammingCardsForAllPlayers() {
for (Player player : playerList) {
List<ProgrammingCard> playerProgram = player.getProgram();
ProgrammingCardDeck playerDeck = player.getPlayerDeck();
ProgrammingCardDeck lockedPlayerDeck = player.getLockedPlayerDeck();
int robotDamage = gameBoard.getRobotDamage(player.getRobotID());
//The player has no locked cards. All previously locked cards should go into the free deck
if (robotDamage <= 4) {
lockedPlayerDeck.emptyInto(player.getPlayerDeck());
continue;
}
//Goes through locked cards and moves them to the locked player deck
for (int i = 1; i <= (robotDamage - 4); i++) {
ProgrammingCard card = playerProgram.get(playerProgram.size() - i);
moveProgrammingCardToLockedDeck(card, playerDeck, lockedPlayerDeck);
}
}
}
/**
* Moves a card from the player's deck to the player's locked deck if found
* @param card The card to move to the locked deck
* @param playerDeck The deck containing the player's cards
* @param lockedPlayerDeck The deck containing the player's locked cards
*/
private void moveProgrammingCardToLockedDeck(ProgrammingCard card, ProgrammingCardDeck playerDeck,
ProgrammingCardDeck lockedPlayerDeck) {
for (int i = 0; i < playerDeck.size(); i++) {
if (card.equals(playerDeck.peekTop())) {
//Found the card. Add to the locked deck
lockedPlayerDeck.draw(playerDeck);
break;
} else {
//Move the card to the bottom of the deck
playerDeck.draw(playerDeck);
}
}
}
/**
* Moves non-locked player programming cards from their hand back to the main deck
*/
private void removeNonLockedProgrammingCardsFromPlayers() {
for (Player player : playerList) {
player.getPlayerDeck().emptyInto(mainDeck);
}
}
/**
* Deals correct amount of cards to active players, based on their robots damage
*/
private void distributeProgrammingCardsToPlayers() {
mainDeck.shuffle();
for (Player player : playerList) {
RobotID robot = player.getRobotID();
ProgrammingCardDeck playerDeck = player.getPlayerDeck();
int robotDamage = gameBoard.getRobotDamage(robot);
//Powered down or heavily damaged robots don't get any cards
if (gameBoard.getPowerDown(robot) || robotDamage >= 9) {
continue;
}
if (!playerDeck.isEmpty()) {
throw new IllegalStateException("Player deck must be empty when dealing new cards!");
}
//Gives the player the correct amount of cards
playerDeck.draw(mainDeck,9 - robotDamage);
}
}
/**
@ -202,13 +309,14 @@ public class RoboRallyGame implements IDrawableGame {
* @throws InterruptedException If interrupted wile trying to sleep
*/
private void runPhase(int phaseNumber) throws InterruptedException {
runProgramCards(phaseNumber);
runProgrammingCards(phaseNumber);
moveAllConveyorBelts();
rotateCogwheels();
fireAllLasers();
checkAllFlags();
}
/**
@ -365,12 +473,31 @@ public class RoboRallyGame implements IDrawableGame {
for (BoardElementContainer<Tile> flag:listOfFlags) {
Position flagPosition = flag.getPosition();
if (gameBoard.hasRobotOnPosition(flagPosition)) {
RobotID robot = gameBoard.getRobotOnPosition(flagPosition);
gameBoard.updateFlagOnRobot(robot, flag.getElement().getTileType());
RobotID robotID = gameBoard.getRobotOnPosition(flagPosition);
for (Robot robot : gameBoard.getAliveRobots()) {
if (robot.getRobotId() != robotID || robot.isHasTouchedFlagThisTurn()) {
continue;
}
gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
robot.setHasTouchedFlagThisTurn(true);
if (victoryCheck(robot.getLastFlagVisited(), listOfFlags.size())) {
Player winningPlayer;
for (Player player : playerList) {
if (player.getRobotID() != robotID) {
continue;
}
winningPlayer = player;
}
//TODO: Make win screen announcing the winning player
}
}
}
}
}
private boolean victoryCheck(int lastFlagVisited, int lastFlag) {
return (lastFlagVisited == lastFlag);
}
/**
* Fires all lasers on the game board
*/
@ -385,7 +512,7 @@ public class RoboRallyGame implements IDrawableGame {
* @param phase The number of the phase to run cards for
* @throws InterruptedException If it gets interrupted while trying to sleep
*/
private void runProgramCards(int phase) throws InterruptedException {
private void runProgrammingCards(int phase) throws InterruptedException {
List<RobotID> robotsToDoAction = new ArrayList<>();
List<ProgrammingCard> programToBeRun = new ArrayList<>();
List<Integer> originalPriority = new ArrayList<>();
@ -409,19 +536,17 @@ public class RoboRallyGame implements IDrawableGame {
/**
* Respawn all the dead robots with more lives and places them on the game board
*/
private void respawnRobots(){
private void respawnRobots() {
gameBoard.respawnRobots();
}
/**
* repair all robots standing on a repair tile
*/
private void repairAllRobotsOnRepairTiles(){
List<BoardElementContainer<Tile>> listOfRepareTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
for (BoardElementContainer<Tile> repareTile:listOfRepareTiles) {
Position robotOnTilePosition = repareTile.getPosition();
if (!gameBoard.hasRobotOnPosition(robotOnTilePosition)){
private void repairAllRobotsOnRepairTiles() {
for (BoardElementContainer<Tile> repairTile : repairTiles) {
Position robotOnTilePosition = repairTile.getPosition();
if (!gameBoard.hasRobotOnPosition(robotOnTilePosition)) {
continue;
}
gameBoard.repairRobotOnTile(gameBoard.getRobotOnPosition(robotOnTilePosition));
@ -429,21 +554,21 @@ public class RoboRallyGame implements IDrawableGame {
}
/**
* sets the robots powerdown status too the players powerdown next round status and sets the players status to false
* Sets the robot's power down status to the player's "power down next round" status and sets the players status to false
*/
private void updateRobotPowerDown(){
for (Player player:playerList) {
gameBoard.setPowerDown(player.getRobotID(),player.getPowerDownNextRound());
private void updateRobotPowerDown() {
for (Player player : playerList) {
setRobotPowerDown(player, player.getPowerDownNextRound());
player.setPowerDownNextRound(false);
}
}
/**
* sets the powerdown status of a robots
* @param player the player that owns the robot
* @param powerdownStatus the powerdown status
* Sets the power down status of a robot
* @param player The player that owns the robot
* @param powerDownStatus The new power down status
*/
private void setRobotPowerDown(Player player,Boolean powerdownStatus){
gameBoard.setPowerDown(player.getRobotID(),powerdownStatus);
private void setRobotPowerDown(Player player, Boolean powerDownStatus) {
gameBoard.setPowerDown(player.getRobotID(), powerDownStatus);
}
}

View File

@ -16,6 +16,7 @@ public class Robot {
private Position backupPosition;
private Position currentPosition;
private Direction facingDirection;
private boolean hasTouchedFlagThisTurn = false;
/**
* Instantiates a new robot
@ -29,6 +30,23 @@ public class Robot {
this.facingDirection = Direction.NORTH;
}
/**
* True if the robot has touched a flag in the current turn
* @return a boolean
*/
public boolean isHasTouchedFlagThisTurn() {
return hasTouchedFlagThisTurn;
}
/**
* Sets the boolean value to true if the robot touches a flag during a turn,
* and false at the end of each turn.
* @param hasTouchedFlagThisTurn the boolean value to be set.
*/
public void setHasTouchedFlagThisTurn(boolean hasTouchedFlagThisTurn) {
this.hasTouchedFlagThisTurn = hasTouchedFlagThisTurn;
}
/**
* Gets the damage the robot has taken
* @return The amount of damage the robot has received
@ -73,7 +91,7 @@ public class Robot {
* Gets the robot's power-down status
* @return Whether the robot is currently in power-down
*/
public Boolean isInPowerDown(){
public Boolean isInPowerDown() {
return inPowerDown;
}
@ -144,7 +162,9 @@ public class Robot {
* Gets the amount of life a robot has left.
* @return amount of life left
*/
public int getAmountOfLives() { return this.amountOfLives; }
public int getAmountOfLives() {
return this.amountOfLives;
}
/**
* Makes a copy of this robot with the same properties as this robot

View File

@ -7,7 +7,6 @@ import inf112.fiasko.roborally.element_properties.WallType;
* This class represents a wall
*/
public class Wall {
private final WallType wallType;
private final Direction direction;
@ -36,7 +35,7 @@ public class Wall {
* Gets the direction of the wall
* @return The direction of the wall
*/
public Direction getDirection(){
public Direction getDirection() {
return direction;
}
}

View File

@ -14,7 +14,7 @@ import java.io.*;
import java.util.List;
/**
* Loads a board
* This class helps loading boards
*/
public final class BoardLoaderUtil {
private BoardLoaderUtil() {}

View File

@ -3,20 +3,41 @@ package inf112.fiasko.roborally.utility;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import inf112.fiasko.roborally.element_properties.Direction;
import inf112.fiasko.roborally.element_properties.Position;
import inf112.fiasko.roborally.objects.IDrawableGame;
import inf112.fiasko.roborally.objects.DrawableObject;
import inf112.fiasko.roborally.element_properties.RobotID;
import inf112.fiasko.roborally.objects.Player;
import inf112.fiasko.roborally.objects.IDrawableObject;
import inf112.fiasko.roborally.objects.Tile;
import inf112.fiasko.roborally.objects.IDrawableGame;
import inf112.fiasko.roborally.objects.Wall;
import inf112.fiasko.roborally.objects.Particle;
import inf112.fiasko.roborally.objects.Robot;
import inf112.fiasko.roborally.objects.Tile;
import inf112.fiasko.roborally.objects.Wall;
import inf112.fiasko.roborally.objects.DrawableObject;
import com.esotericsoftware.kryonet.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* This class helps with tasks which mix primitive classes and classes from external libraries
*/
public final class IOUtil {
private IOUtil() {}
/**
* Generates a list of players from a map of player names and a map of robot ids
* @param playerNames A map between connections and player names
* @param robotIDs A map between connections and robot ids
* @return A list of players
*/
public static List<Player> playerGenerator(Map<Connection, String> playerNames, Map<Connection, RobotID> robotIDs) {
List<Player> playerList = new ArrayList<>();
for (Connection connection: playerNames.keySet()) {
Player player = new Player(robotIDs.get(connection), playerNames.get(connection));
playerList.add(player);
}
return playerList;
}
/**
* Gets a list of all elements which should be drawn from the game provided
* @param game A game implementing IDrawableGame

View File

@ -1,12 +1,19 @@
package inf112.fiasko.roborally.utility;
import com.esotericsoftware.kryo.Kryo;
import inf112.fiasko.roborally.networking.ErrorResponse;
import inf112.fiasko.roborally.networking.SomeRequest;
import inf112.fiasko.roborally.networking.SomeResponse;
import inf112.fiasko.roborally.element_properties.RobotID;
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
import inf112.fiasko.roborally.networking.containers.GameStartInfo;
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;
/**
* This class helps with networking tasks
*/
public final class NetworkUtil {
/**
@ -14,10 +21,13 @@ public final class NetworkUtil {
* @param kryo The kryo object to register the classes to
*/
public static void registerClasses(Kryo kryo) {
kryo.register(SomeRequest.class);
kryo.register(SomeResponse.class);
kryo.register(ErrorResponse.class);
kryo.register(IDeck.class);
kryo.register(ProgrammingCard.class);
kryo.register(GameStartInfo.class);
kryo.register(ArrayList.class);
kryo.register(Player.class);
kryo.register(RobotID.class);
kryo.register(ProgrammingCardDeck.class);
}
}

View File

@ -2,6 +2,9 @@ package inf112.fiasko.roborally.utility;
import java.io.InputStream;
/**
* This class helps with tasks related to resource loading
*/
public final class ResourceUtil {
private ResourceUtil() {}

View File

@ -24,12 +24,12 @@ public class PositionTest {
testPosition6 = new Position(3, 3);
}
@Test
public void testGetXPosition(){
public void testGetXPosition() {
assertEquals(3,testPosition1.getXCoordinate());
}
@Test
public void testGetYPosition(){
public void testGetYPosition() {
assertEquals(4,testPosition1.getYCoordinate());
}

View File

@ -139,14 +139,14 @@ public class BoardTest {
}
@Test
public void setRobotPowerDownStatus(){
public void setRobotPowerDownStatus() {
Robot testrobot = robotListforpowerdown.get(0);
assertEquals(false , testrobot.isInPowerDown());
boardforpowerdown.setPowerDown(RobotID.ROBOT_1,true);
assertEquals(true , testrobot.isInPowerDown());
}
@Test
public void executRobotPowerDown(){
public void executRobotPowerDown() {
Robot testrobot = robotListforpowerdown.get(1);
boardforpowerdown.setPowerDown(RobotID.ROBOT_2,true);
testrobot.setDamageTaken(4);
@ -155,7 +155,7 @@ public class BoardTest {
assertEquals(0,testrobot.getDamageTaken());
}
@Test
public void repairRobotOnRepairTile(){
public void repairRobotOnRepairTile() {
Robot testrobot = robotListforpowerdown.get(2);
testrobot.setDamageTaken(4);
assertEquals(4,testrobot.getDamageTaken());
@ -164,21 +164,21 @@ public class BoardTest {
}
@Test
public void robotHitByLaserGetsDamaged(){
public void robotHitByLaserGetsDamaged() {
Robot testRobot = robotListforlaser.get(7);
assertEquals(0, testRobot.getDamageTaken());
boardforlaser.fireAllLasers();
assertNotEquals(0,testRobot.getDamageTaken());
}
@Test
public void laserBlockedByWallDoesNotDamageRobot(){
public void laserBlockedByWallDoesNotDamageRobot() {
Robot testRobot = robotListforlaser.get(0);
assertEquals(0, testRobot.getDamageTaken());
boardforlaser.fireAllLasers();
assertEquals(0,testRobot.getDamageTaken());
}
@Test
public void laserBlockedByRobotDoesNotDamageOtherRobot(){
public void laserBlockedByRobotDoesNotDamageOtherRobot() {
Robot testRobot1 = robotListforlaser.get(1);
Robot testRobot2 = robotListforlaser.get(2);
testRobot2.setFacingDirection(Direction.EAST);
@ -189,14 +189,14 @@ public class BoardTest {
assertNotEquals(0,testRobot2.getDamageTaken());
}
@Test
public void doubleLaserDamage(){
public void doubleLaserDamage() {
Robot testRobot = robotListforlaser.get(6);
assertEquals(0, testRobot.getDamageTaken());
boardforlaser.fireAllLasers();
assertEquals(2,testRobot.getDamageTaken());
}
@Test
public void robotGetsHitByTwoLasers(){
public void robotGetsHitByTwoLasers() {
Robot testRobot = robotListforlaser.get(3);
assertEquals(0, testRobot.getDamageTaken());
boardforlaser.fireAllLasers();
@ -397,12 +397,12 @@ public class BoardTest {
assertTrue(tileTypeList.containsAll(tileTypeListResult) && tileTypeListResult.containsAll(tileTypeList));
}
public <K> boolean checkIfAllElementsAreOfSpecificWallType(List<BoardElementContainer<Wall>> elemList, K WallType) {
private <K> boolean checkIfAllElementsAreOfSpecificWallType(List<BoardElementContainer<Wall>> elemList, K WallType) {
Predicate<BoardElementContainer<Wall>> pred = (element) -> element.getElement().getWallType() == WallType;
elemList.removeIf(pred);
return 0 == elemList.size();
}
public <K> boolean checkIfAllElementsAreOfSpecificTileType(List<BoardElementContainer<Tile>> elemList, K TileType) {
private <K> boolean checkIfAllElementsAreOfSpecificTileType(List<BoardElementContainer<Tile>> elemList, K TileType) {
Predicate<BoardElementContainer<Tile>> pred = (element) -> element.getElement().getTileType() == TileType;
elemList.removeIf(pred);
return 0 == elemList.size();

View File

@ -17,8 +17,10 @@ public class DrawableObjectTest {
private static final Texture textureSheet = new Texture(Gdx.files.internal("assets/tiles.png"));
private static final Texture robotsTexture = new Texture(Gdx.files.internal("assets/robots.png"));
public static final TextureRegion TEXTURE_MIN_ARG = new TextureRegion(textureSheet, 4*300, 0, 300, 300);
public static final TextureRegion TEXTURE_MAX_ARG = new TextureRegion(robotsTexture, 0, 0, 64, 64);
private static final TextureRegion TEXTURE_MIN_ARG = new TextureRegion(textureSheet, 4 * 300, 0,
300, 300);
public static final TextureRegion TEXTURE_MAX_ARG = new TextureRegion(robotsTexture, 0, 0,
64, 64);
public static final int X_POSITION_MIN_ARG = 5;
public static final int Y_POSITION_MIN_ARG = 8;
public static final int X_POSITION_MAX_ARG = 6;
@ -68,7 +70,6 @@ public class DrawableObjectTest {
assertEquals(Y_POSITION_MAX_ARG, drawableObjectMaximumArguments.getYPosition());
}
@Test
public void getWidthMinArg() {
assertEquals(64, drawableObjectMinimumArguments.getWidth());

View File

@ -5,12 +5,14 @@ import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
public class RoboRallyGameTest {
private IDrawableGame game;
@Before
public void setUp() {
game = new RoboRallyGame();
game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false);
}
@Test

View File

@ -19,17 +19,17 @@ public class RobotTest {
}
@Test
public void testRobotGetDamageOnInitializedRobot(){
public void testRobotGetDamageOnInitializedRobot() {
assertEquals(0, testRobot.getDamageTaken());
}
@Test
public void testRobotGetPlayerId(){
public void testRobotGetPlayerId() {
assertEquals(RobotID.ROBOT_6, testRobot.getRobotId());
}
@Test
public void testRobotGetBackupOnInitializedRobot(){
public void testRobotGetBackupOnInitializedRobot() {
assertEquals(robotPosition, testRobot.getBackupPosition());
}
@ -40,7 +40,7 @@ public class RobotTest {
}
@Test
public void testRobotGetPositionOnInitializedRobot(){
public void testRobotGetPositionOnInitializedRobot() {
assertEquals(robotPosition, testRobot.getPosition());
}
@ -52,7 +52,7 @@ public class RobotTest {
}
@Test
public void testRobotIsInPowerDownOnInitializedRobot(){
public void testRobotIsInPowerDownOnInitializedRobot() {
assertEquals(false, testRobot.isInPowerDown());
}

View File

@ -7,27 +7,27 @@ import org.junit.Test;
public class WallTest {
@Test
public void testWallGetWallTypeNormal(){
public void testWallGetWallTypeNormal() {
Wall testGetWall = new Wall(WallType.WALL_NORMAL, Direction.NORTH);
assertEquals(WallType.WALL_NORMAL, testGetWall.getWallType());
}
@Test
public void testWallGetWallTypeCorner(){
public void testWallGetWallTypeCorner() {
Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.NORTH);
assertEquals(WallType.WALL_CORNER, testGetWall.getWallType());
}
@Test
public void testWallGetWallTypeLaserSingle(){
public void testWallGetWallTypeLaserSingle() {
Wall testGetWall = new Wall(WallType.WALL_LASER_SINGLE, Direction.NORTH);
assertEquals(WallType.WALL_LASER_SINGLE, testGetWall.getWallType());
}
@Test
public void testWallGetDirectionNorth(){
public void testWallGetDirectionNorth() {
Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.NORTH);
assertEquals(Direction.NORTH, testGetWall.getDirection());
}
@Test
public void testWallGetDirectionEast(){
public void testWallGetDirectionEast() {
Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.EAST);
assertEquals(Direction.EAST, testGetWall.getDirection());
}