mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-06-28 04:04:42 +02:00
Gjør den del nødvendige forandringer for å kunne tegne det nye brettet
Oppdaterer IDrawableObject og IDrawableGame og implementerende klasser Legger til en utility klasse for input og output Legger til manglende metoder i TextureConverterUtil Oppdaterer noen tester med nye datatyper
This commit is contained in:
@ -1,53 +1,77 @@
|
||||
package inf112.fiasko.roborally.game;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.GameTexture;
|
||||
import inf112.fiasko.roborally.element_properties.Direction;
|
||||
import inf112.fiasko.roborally.element_properties.Position;
|
||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||
import inf112.fiasko.roborally.objects.Board;
|
||||
import inf112.fiasko.roborally.objects.DrawableObject;
|
||||
import inf112.fiasko.roborally.objects.IDrawableObject;
|
||||
import inf112.fiasko.roborally.objects.Robot;
|
||||
import inf112.fiasko.roborally.objects.Tile;
|
||||
import inf112.fiasko.roborally.objects.Wall;
|
||||
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 Game implements IDrawableGame {
|
||||
private final int TILE_SIZE = 64;
|
||||
private Board gameBoard;
|
||||
|
||||
public Game() {
|
||||
try {
|
||||
List<Robot> robots = new ArrayList<>();
|
||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1)));
|
||||
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
runGameLoop();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void runGameLoop() throws InterruptedException {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.NORTH);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.EAST);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.NORTH);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.WEST);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.WEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return gameBoard.getBoardWidth() * TILE_SIZE;
|
||||
return gameBoard.getBoardWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return gameBoard.getBoardHeight() * TILE_SIZE;
|
||||
return gameBoard.getBoardHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDrawableObject> getObjectsToDraw() {
|
||||
List<IDrawableObject> list = new ArrayList<>();
|
||||
for (int i = 0; i < gameBoard.getBoardWidth(); i++) {
|
||||
for (int j = 0; j < gameBoard.getBoardHeight(); j++) {
|
||||
DrawableObject tile = new DrawableObject(GameTexture.TILE, i * TILE_SIZE, j * TILE_SIZE);
|
||||
list.add(tile);
|
||||
}
|
||||
}
|
||||
DrawableObject robot = new DrawableObject(GameTexture.ROBOT, TILE_SIZE, TILE_SIZE);
|
||||
list.add(robot);
|
||||
return list;
|
||||
public List<Tile> getTilesToDraw() {
|
||||
return gameBoard.getTiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Wall> getWallsToDraw() {
|
||||
return gameBoard.getWalls();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Robot> getRobotsToDraw() {
|
||||
return gameBoard.getAliveRobots();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package inf112.fiasko.roborally.game;
|
||||
|
||||
import inf112.fiasko.roborally.objects.IDrawableObject;
|
||||
import inf112.fiasko.roborally.objects.Robot;
|
||||
import inf112.fiasko.roborally.objects.Tile;
|
||||
import inf112.fiasko.roborally.objects.Wall;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -10,21 +12,41 @@ import java.util.List;
|
||||
public interface IDrawableGame {
|
||||
|
||||
/**
|
||||
* Gets the screen width of the game
|
||||
* Gets the number of tiles in the x direction
|
||||
* @return A positive integer
|
||||
*/
|
||||
int getWidth();
|
||||
|
||||
/**
|
||||
* Gets the screen height of the game
|
||||
* Gets the number of tiles in the y direction
|
||||
* @return A positive integer
|
||||
*/
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
* Gets a list of objects which are to be drawn
|
||||
* @return A list of drawable objects in the order they are to be drawn
|
||||
* 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<IDrawableObject> getObjectsToDraw();
|
||||
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();
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user