mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-07-01 05:34:42 +02:00
Flytter noen klasser og tar ibruk RoboRallyLauncher. Closes #20
Flytter IDrawableGame og RoboRallyGame (tidligere Game) til Objects Korrigerer navn i RoboRallyGameTest (tidligere GameTest) Korrigerer pakkeendringer i IOUtil
This commit is contained in:
@ -0,0 +1,48 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This interface describes a game drawable using libgdx
|
||||
*/
|
||||
public interface IDrawableGame {
|
||||
|
||||
/**
|
||||
* Gets the number of tiles in the x direction
|
||||
* @return A positive integer
|
||||
*/
|
||||
int getWidth();
|
||||
|
||||
/**
|
||||
* Gets the number of tiles in the y direction
|
||||
* @return A positive integer
|
||||
*/
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
* Gets a list of all the tiles to be drawn
|
||||
*
|
||||
* Should return a list readable from top-left to top-right and so on. In other words, the first getWidth() tiles
|
||||
* should be drawn on the top row from left to right.
|
||||
*
|
||||
* @return A list of tiles
|
||||
*/
|
||||
List<Tile> getTilesToDraw();
|
||||
|
||||
/**
|
||||
* Gets a list of all the walls to be drawn
|
||||
*
|
||||
* Should return a list readable from top-left to top-right and so on. In other words, the first getWidth() walls
|
||||
* should be drawn on the top row from left to right.
|
||||
*
|
||||
* @return A list of walls
|
||||
*/
|
||||
List<Wall> getWallsToDraw();
|
||||
|
||||
/**
|
||||
* Gets a list of all robots to draw
|
||||
* @return A list of all robots to draw
|
||||
*/
|
||||
List<Robot> getRobotsToDraw();
|
||||
|
||||
}
|
141
src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
Normal file
141
src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
Normal file
@ -0,0 +1,141 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.Position;
|
||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* This class represent a game which is drawable using libgdx
|
||||
*/
|
||||
public class RoboRallyGame implements IDrawableGame {
|
||||
private Board gameBoard;
|
||||
|
||||
public RoboRallyGame(boolean debug) {
|
||||
if (debug) {
|
||||
initializeDebugMode();
|
||||
} else {
|
||||
initializeGame();
|
||||
}
|
||||
}
|
||||
|
||||
public RoboRallyGame() {
|
||||
initializeGame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return gameBoard.getBoardWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return gameBoard.getBoardHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tile> getTilesToDraw() {
|
||||
return gameBoard.getTiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Wall> getWallsToDraw() {
|
||||
return gameBoard.getWalls();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Robot> getRobotsToDraw() {
|
||||
return gameBoard.getAliveRobots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the game with a debugging board
|
||||
*/
|
||||
private void initializeDebugMode() {
|
||||
List<Robot> robots = new ArrayList<>();
|
||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(0, 16)));
|
||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 16)));
|
||||
robots.add(new Robot(RobotID.ROBOT_3, new Position(2, 16)));
|
||||
try {
|
||||
gameBoard = BoardLoaderUtil.loadBoard("boards/all_tiles_test_board.txt", robots);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the game with a playable board
|
||||
*/
|
||||
private void initializeGame() {
|
||||
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)));
|
||||
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
runGameLoop();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}).start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does whatever the game wants to do
|
||||
* @throws InterruptedException If interrupted while trying to sleep
|
||||
*/
|
||||
private void runGameLoop() throws InterruptedException {
|
||||
long cycleDelay = 600;
|
||||
TimeUnit.SECONDS.sleep(3);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_1);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_1);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_1);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotLeft(RobotID.ROBOT_1);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_1);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_1);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_1);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_1);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_2);
|
||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||
gameBoard.moveRobotForward(RobotID.ROBOT_2);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user