mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Rydder opp i en del kommentarer og kode
This commit is contained in:
parent
17926196a5
commit
8df3a8a9ab
@ -30,7 +30,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
|||||||
private final List<CardRectangle> cardRectangles;
|
private final List<CardRectangle> cardRectangles;
|
||||||
private final ShapeRenderer shapeRenderer;
|
private final ShapeRenderer shapeRenderer;
|
||||||
private final Viewport viewport;
|
private final Viewport viewport;
|
||||||
private List<CardRectangle> chosenCards;
|
private final List<CardRectangle> chosenCards;
|
||||||
private final int maxCards;
|
private final int maxCards;
|
||||||
|
|
||||||
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
|
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||||
|
@ -33,9 +33,10 @@ public class MainMenuScreen implements Screen {
|
|||||||
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
||||||
|
|
||||||
roboRallyWrapper.batch.begin();
|
roboRallyWrapper.batch.begin();
|
||||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Robo Rally", 0, 250,
|
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Robo Rally", 10, 250,
|
||||||
200, 0, false);
|
380, 1, true);
|
||||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click anywhere to run the demo", 70, 200);
|
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click anywhere to run the demo", 10, 200,
|
||||||
|
380, 1, true);
|
||||||
roboRallyWrapper.batch.end();
|
roboRallyWrapper.batch.end();
|
||||||
|
|
||||||
if (Gdx.input.isTouched()) {
|
if (Gdx.input.isTouched()) {
|
||||||
|
@ -17,7 +17,7 @@ public class RoboRallyWrapper extends Game {
|
|||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
font = new BitmapFont(Gdx.files.internal("assets/Montserrat-Regular.fnt"));
|
font = new BitmapFont(Gdx.files.internal("assets/Montserrat-Regular.fnt"));
|
||||||
this.screenManager = new ScreenManager();
|
this.screenManager = new ScreenManager();
|
||||||
this.setScreen(screenManager.getBoardActiveScreen(this));
|
this.setScreen(screenManager.getMainMenuScreen(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
@ -46,21 +46,6 @@ public class Board {
|
|||||||
this.deadRobots = new ArrayList<>();
|
this.deadRobots = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fires all lasers on the board and kills any robot that has taken to much damage after all lasers have fired.
|
|
||||||
*/
|
|
||||||
public void fireAllLasers(){
|
|
||||||
List<BoardElementContainer<Wall>> listOfWallLasers = getPositionsOfWallOnBoard(WallType.WALL_LASER_SINGLE,
|
|
||||||
WallType.WALL_LASER_DOUBLE);
|
|
||||||
for (Robot robot:robots.values()) {
|
|
||||||
fireOneRobotLaser(robot.getPosition(),robot.getFacingDirection());
|
|
||||||
}
|
|
||||||
for (BoardElementContainer<Wall> laser:listOfWallLasers) {
|
|
||||||
fireOneWallLaser(laser);
|
|
||||||
}
|
|
||||||
killAllDeadRobot();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the height of the board
|
* Gets the height of the board
|
||||||
* @return The height of the board
|
* @return The height of the board
|
||||||
@ -244,6 +229,21 @@ public class Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fires all lasers on the board and kills any robot that has taken to much damage after all lasers have fired.
|
||||||
|
*/
|
||||||
|
public void fireAllLasers() {
|
||||||
|
List<BoardElementContainer<Wall>> listOfWallLasers = getPositionsOfWallOnBoard(WallType.WALL_LASER_SINGLE,
|
||||||
|
WallType.WALL_LASER_DOUBLE);
|
||||||
|
for (Robot robot:robots.values()) {
|
||||||
|
fireRobotLaser(robot.getPosition(),robot.getFacingDirection());
|
||||||
|
}
|
||||||
|
for (BoardElementContainer<Wall> laser : listOfWallLasers) {
|
||||||
|
fireWallLaser(laser);
|
||||||
|
}
|
||||||
|
killAllHeavilyDamagedRobots();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the tile on a specific position
|
* Gets the tile on a specific position
|
||||||
* @param position The position to get a tile from
|
* @param position The position to get a tile from
|
||||||
@ -282,6 +282,15 @@ public class Board {
|
|||||||
return combinedList;
|
return combinedList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether there exists a robot on a specific position
|
||||||
|
* @param position The position to check
|
||||||
|
* @return True if there is a robot on the specified position
|
||||||
|
*/
|
||||||
|
public boolean hasRobotOnPosition(Position position) {
|
||||||
|
return getRobotOnPosition(position) != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a potential move would be blocked by a wall
|
* Checks if a potential move would be blocked by a wall
|
||||||
* @param robotPosition The current position of whatever is trying to move
|
* @param robotPosition The current position of whatever is trying to move
|
||||||
@ -289,7 +298,7 @@ public class Board {
|
|||||||
* @param direction The direction something is going
|
* @param direction The direction something is going
|
||||||
* @return True if a wall would stop its path
|
* @return True if a wall would stop its path
|
||||||
*/
|
*/
|
||||||
public boolean moveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) {
|
private boolean moveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) {
|
||||||
return hasWallFacing(robotPosition, direction) || (isValidPosition(newPosition) &&
|
return hasWallFacing(robotPosition, direction) || (isValidPosition(newPosition) &&
|
||||||
hasWallFacing(newPosition, Direction.getReverseDirection(direction)));
|
hasWallFacing(newPosition, Direction.getReverseDirection(direction)));
|
||||||
}
|
}
|
||||||
@ -357,15 +366,6 @@ public class Board {
|
|||||||
deadRobots.add(robot);
|
deadRobots.add(robot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether there exists a robot on a specific position
|
|
||||||
* @param position The position to check
|
|
||||||
* @return True if there is a robot on the specified position
|
|
||||||
*/
|
|
||||||
public boolean hasRobotOnPosition(Position position) {
|
|
||||||
return getRobotOnPosition(position) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a position has a wall facing a specific direction
|
* Checks whether a position has a wall facing a specific direction
|
||||||
* @param position The position to check
|
* @param position The position to check
|
||||||
@ -403,11 +403,11 @@ public class Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds all position of an obj and makes a list of BoardElementContainers
|
* Finds all tiles/walls with a certain type
|
||||||
* @param type Type of obj
|
* @param type The type of tile/wall to look for
|
||||||
* @param grid Grid to search
|
* @param grid The grid to look through
|
||||||
* @param <K> Type of type
|
* @param <K> Type of the type to look for
|
||||||
* @param <T> Type of grid
|
* @param <T> Type of the grid
|
||||||
* @return List of BoardElementContainers
|
* @return List of BoardElementContainers
|
||||||
*/
|
*/
|
||||||
private <K,T> List<BoardElementContainer<T>> makeTileList(K type, IGrid<T> grid) {
|
private <K,T> List<BoardElementContainer<T>> makeTileList(K type, IGrid<T> grid) {
|
||||||
@ -420,12 +420,12 @@ public class Board {
|
|||||||
if (gridElement.getClass().isAssignableFrom(Tile.class)) {
|
if (gridElement.getClass().isAssignableFrom(Tile.class)) {
|
||||||
Tile tile = (Tile) gridElement;
|
Tile tile = (Tile) gridElement;
|
||||||
if (tile.getTileType() == type) {
|
if (tile.getTileType() == type) {
|
||||||
objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
|
objList.add(new BoardElementContainer<>(gridElement, new Position(x, y)));
|
||||||
}
|
}
|
||||||
} else if (gridElement.getClass().isAssignableFrom(Wall.class)) {
|
} else if (gridElement.getClass().isAssignableFrom(Wall.class)) {
|
||||||
Wall wall = (Wall) gridElement;
|
Wall wall = (Wall) gridElement;
|
||||||
if (wall.getWallType() == type) {
|
if (wall.getWallType() == type) {
|
||||||
objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
|
objList.add(new BoardElementContainer<>(gridElement, new Position(x, y)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Grid has unknown type.");
|
throw new IllegalArgumentException("Grid has unknown type.");
|
||||||
@ -437,11 +437,11 @@ public class Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kills all robots that has taken too much damage
|
* Kills all robots that have taken too much damage
|
||||||
*/
|
*/
|
||||||
private void killAllDeadRobot(){
|
private void killAllHeavilyDamagedRobots() {
|
||||||
for (Robot robot:robots.values()) {
|
for (Robot robot:robots.values()) {
|
||||||
if(robot.getDamageTaken()>=10){
|
if (robot.getDamageTaken() >= 10) {
|
||||||
killRobot(robot);
|
killRobot(robot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,62 +449,57 @@ public class Board {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires one wall laser
|
* Fires one wall laser
|
||||||
* @param laser the wall laser that is being fired
|
* @param wallLaser The wall laser being fired
|
||||||
*/
|
*/
|
||||||
private void fireOneWallLaser(BoardElementContainer<Wall> laser){
|
private void fireWallLaser(BoardElementContainer<Wall> wallLaser) {
|
||||||
Position hitPosition = lineForTheLaser(Direction.getReverseDirection(laser.getElement().getDirection()),
|
Position hitPosition = getLaserTarget(Direction.getReverseDirection(wallLaser.getElement().getDirection()),
|
||||||
laser.getPosition());
|
wallLaser.getPosition());
|
||||||
if(getRobotOnPosition(hitPosition)!=null){
|
if (getRobotOnPosition(hitPosition) != null) {
|
||||||
laserDamage(laser.getElement().getWallType(),robots.get(getRobotOnPosition(hitPosition)));
|
applyLaserDamage(wallLaser.getElement().getWallType(), robots.get(getRobotOnPosition(hitPosition)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fires on robot laser
|
* Fires one robot laser
|
||||||
* @param robotPosition the position of the robot firing the laser
|
* @param robotPosition The position of the robot firing the laser
|
||||||
* @param robotDirection the direction the robot is facing
|
* @param robotDirection The direction the robot is facing
|
||||||
*/
|
*/
|
||||||
private void fireOneRobotLaser(Position robotPosition, Direction robotDirection){
|
private void fireRobotLaser(Position robotPosition, Direction robotDirection){
|
||||||
Position positionInFront = getNewPosition(robotPosition,robotDirection);
|
Position positionInFront = getNewPosition(robotPosition,robotDirection);
|
||||||
|
if (!isValidPosition(positionInFront) || moveIsStoppedByWall(robotPosition, positionInFront, robotDirection)) {
|
||||||
if(!isValidPosition(positionInFront)||moveIsStoppedByWall(robotPosition,positionInFront,robotDirection)){
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Position hitPosition = lineForTheLaser(robotDirection,positionInFront);
|
Position hitPosition = getLaserTarget(robotDirection, positionInFront);
|
||||||
if(getRobotOnPosition(hitPosition)!=null){
|
if (getRobotOnPosition(hitPosition) != null) {
|
||||||
laserDamage(WallType.WALL_LASER_SINGLE,robots.get(getRobotOnPosition(hitPosition)));
|
applyLaserDamage(WallType.WALL_LASER_SINGLE, robots.get(getRobotOnPosition(hitPosition)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the damage form the laser to the robot the laser hit
|
* Applies the damage form the laser to the robot the laser hit
|
||||||
* @param laserType the type of laser that hit the robot
|
* @param laserType The type of laser that hit the robot
|
||||||
* @param robot the robot getting hit by the robot
|
* @param robot The robot getting hit by the robot
|
||||||
*/
|
*/
|
||||||
private void laserDamage(WallType laserType, Robot robot){
|
private void applyLaserDamage(WallType laserType, Robot robot) {
|
||||||
robot.setDamageTaken(robot.getDamageTaken()+laserType.getWallTypeID()-2);
|
robot.setDamageTaken(robot.getDamageTaken() + laserType.getWallTypeID() - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Position of where the laser hits something
|
* Gets the position of the tile the laser stops at
|
||||||
* @param direction the direction of the laser
|
* @param direction The direction of the laser
|
||||||
* @param startPosition the start positon of the laser
|
* @param startPosition The start position of the laser
|
||||||
* @return the position of the element that stopped the laser
|
* @return The position the laser stopped at
|
||||||
*/
|
*/
|
||||||
private Position lineForTheLaser(Direction direction, Position startPosition){
|
private Position getLaserTarget(Direction direction, Position startPosition) {
|
||||||
Position newPosition = getNewPosition(startPosition,direction);
|
Position newPosition = getNewPosition(startPosition, direction);
|
||||||
if(!isValidPosition(newPosition) || moveIsStoppedByWall(startPosition,newPosition,direction) ||
|
if (!isValidPosition(newPosition) || moveIsStoppedByWall(startPosition, newPosition, direction) ||
|
||||||
getRobotOnPosition(startPosition)!= null){
|
getRobotOnPosition(startPosition) != null) {
|
||||||
return startPosition;
|
return startPosition;
|
||||||
}
|
} else if (getRobotOnPosition(newPosition) != null) {
|
||||||
else if(getRobotOnPosition(newPosition)!=null){
|
|
||||||
return newPosition;
|
return newPosition;
|
||||||
}
|
} else {
|
||||||
else{
|
return getLaserTarget(direction, newPosition);
|
||||||
return lineForTheLaser(direction,newPosition);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -154,7 +154,10 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
makeMove(RobotID.ROBOT_2, Action.U_TURN);
|
makeMove(RobotID.ROBOT_2, Action.U_TURN);
|
||||||
makeMove(RobotID.ROBOT_2, Action.MOVE_1);
|
makeMove(RobotID.ROBOT_2, Action.MOVE_1);
|
||||||
moveAllConveyorBelts();
|
moveAllConveyorBelts();
|
||||||
|
checkAllFlags();
|
||||||
|
rotateCogwheels();
|
||||||
makeMove(RobotID.ROBOT_7, Action.MOVE_1);
|
makeMove(RobotID.ROBOT_7, Action.MOVE_1);
|
||||||
|
fireAllLasers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -362,7 +365,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireAllLasers(){
|
private void fireAllLasers() {
|
||||||
gameBoard.fireAllLasers();
|
gameBoard.fireAllLasers();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,7 +5,6 @@ import inf112.fiasko.roborally.element_properties.Position;
|
|||||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||||
import inf112.fiasko.roborally.element_properties.TileType;
|
import inf112.fiasko.roborally.element_properties.TileType;
|
||||||
import inf112.fiasko.roborally.element_properties.WallType;
|
import inf112.fiasko.roborally.element_properties.WallType;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -38,8 +37,6 @@ public class BoardTest {
|
|||||||
private Board boardWithDifferentAmountOfAllTypes;
|
private Board boardWithDifferentAmountOfAllTypes;
|
||||||
private final Map<WallType,Integer> wallTypeNumberMap = new HashMap<>();
|
private final Map<WallType,Integer> wallTypeNumberMap = new HashMap<>();
|
||||||
private final Map<TileType,Integer> tileTypeNumberMap = new HashMap<>();
|
private final Map<TileType,Integer> tileTypeNumberMap = new HashMap<>();
|
||||||
private Grid<Tile> tileGridforlaser;
|
|
||||||
private Grid<Wall> wallGridforlaser;
|
|
||||||
private List<Robot> robotListforlaser;
|
private List<Robot> robotListforlaser;
|
||||||
private Board boardforlaser;
|
private Board boardforlaser;
|
||||||
|
|
||||||
@ -59,8 +56,8 @@ public class BoardTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
tileGridforlaser = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH));
|
Grid<Tile> tileGridforlaser = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH));
|
||||||
wallGridforlaser = new Grid<>(8, 8);
|
Grid<Wall> wallGridforlaser = new Grid<>(8, 8);
|
||||||
robotListforlaser = new ArrayList<>();
|
robotListforlaser = new ArrayList<>();
|
||||||
robotListforlaser.add(new Robot(RobotID.ROBOT_1, new Position(2,1)));
|
robotListforlaser.add(new Robot(RobotID.ROBOT_1, new Position(2,1)));
|
||||||
robotListforlaser.add(new Robot(RobotID.ROBOT_2, new Position(4,0)));
|
robotListforlaser.add(new Robot(RobotID.ROBOT_2, new Position(4,0)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user