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 ShapeRenderer shapeRenderer;
|
||||
private final Viewport viewport;
|
||||
private List<CardRectangle> chosenCards;
|
||||
private final List<CardRectangle> chosenCards;
|
||||
private final int maxCards;
|
||||
|
||||
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
|
@ -33,9 +33,10 @@ public class MainMenuScreen implements Screen {
|
||||
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Robo Rally", 0, 250,
|
||||
200, 0, false);
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click anywhere to run the demo", 70, 200);
|
||||
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()) {
|
||||
|
@ -17,7 +17,7 @@ public class RoboRallyWrapper extends Game {
|
||||
batch = new SpriteBatch();
|
||||
font = new BitmapFont(Gdx.files.internal("assets/Montserrat-Regular.fnt"));
|
||||
this.screenManager = new ScreenManager();
|
||||
this.setScreen(screenManager.getBoardActiveScreen(this));
|
||||
this.setScreen(screenManager.getMainMenuScreen(this));
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
@ -46,21 +46,6 @@ public class Board {
|
||||
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
|
||||
* @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
|
||||
* @param position The position to get a tile from
|
||||
@ -282,6 +282,15 @@ public class Board {
|
||||
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
|
||||
* @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
|
||||
* @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) &&
|
||||
hasWallFacing(newPosition, Direction.getReverseDirection(direction)));
|
||||
}
|
||||
@ -357,15 +366,6 @@ public class Board {
|
||||
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
|
||||
* @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
|
||||
* @param type Type of obj
|
||||
* @param grid Grid to search
|
||||
* @param <K> Type of type
|
||||
* @param <T> Type of grid
|
||||
* Finds all tiles/walls with a certain type
|
||||
* @param type The type of tile/wall to look for
|
||||
* @param grid The grid to look through
|
||||
* @param <K> Type of the type to look for
|
||||
* @param <T> Type of the grid
|
||||
* @return List of BoardElementContainers
|
||||
*/
|
||||
private <K,T> List<BoardElementContainer<T>> makeTileList(K type, IGrid<T> grid) {
|
||||
@ -437,9 +437,9 @@ 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()) {
|
||||
if (robot.getDamageTaken() >= 10) {
|
||||
killRobot(robot);
|
||||
@ -449,62 +449,57 @@ public class Board {
|
||||
|
||||
/**
|
||||
* 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){
|
||||
Position hitPosition = lineForTheLaser(Direction.getReverseDirection(laser.getElement().getDirection()),
|
||||
laser.getPosition());
|
||||
private void fireWallLaser(BoardElementContainer<Wall> wallLaser) {
|
||||
Position hitPosition = getLaserTarget(Direction.getReverseDirection(wallLaser.getElement().getDirection()),
|
||||
wallLaser.getPosition());
|
||||
if (getRobotOnPosition(hitPosition) != null) {
|
||||
laserDamage(laser.getElement().getWallType(),robots.get(getRobotOnPosition(hitPosition)));
|
||||
applyLaserDamage(wallLaser.getElement().getWallType(), robots.get(getRobotOnPosition(hitPosition)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fires on robot laser
|
||||
* @param robotPosition the position of the robot firing the laser
|
||||
* @param robotDirection the direction the robot is facing
|
||||
* Fires one robot laser
|
||||
* @param robotPosition The position of the robot firing the laser
|
||||
* @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);
|
||||
|
||||
if (!isValidPosition(positionInFront) || moveIsStoppedByWall(robotPosition, positionInFront, robotDirection)) {
|
||||
return;
|
||||
}
|
||||
Position hitPosition = lineForTheLaser(robotDirection,positionInFront);
|
||||
Position hitPosition = getLaserTarget(robotDirection, positionInFront);
|
||||
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
|
||||
* @param laserType the type of laser that hit the robot
|
||||
* @param robot the robot getting hit by the robot
|
||||
* @param laserType The type of laser that hit 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Position of where the laser hits something
|
||||
* @param direction the direction of the laser
|
||||
* @param startPosition the start positon of the laser
|
||||
* @return the position of the element that stopped the laser
|
||||
* Gets the position of the tile the laser stops at
|
||||
* @param direction The direction of the laser
|
||||
* @param startPosition The start position of 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);
|
||||
if (!isValidPosition(newPosition) || moveIsStoppedByWall(startPosition, newPosition, direction) ||
|
||||
getRobotOnPosition(startPosition) != null) {
|
||||
return startPosition;
|
||||
}
|
||||
else if(getRobotOnPosition(newPosition)!=null){
|
||||
} else if (getRobotOnPosition(newPosition) != null) {
|
||||
return newPosition;
|
||||
}
|
||||
else{
|
||||
return lineForTheLaser(direction,newPosition);
|
||||
} else {
|
||||
return getLaserTarget(direction, newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -154,7 +154,10 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
makeMove(RobotID.ROBOT_2, Action.U_TURN);
|
||||
makeMove(RobotID.ROBOT_2, Action.MOVE_1);
|
||||
moveAllConveyorBelts();
|
||||
checkAllFlags();
|
||||
rotateCogwheels();
|
||||
makeMove(RobotID.ROBOT_7, Action.MOVE_1);
|
||||
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.TileType;
|
||||
import inf112.fiasko.roborally.element_properties.WallType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -38,8 +37,6 @@ public class BoardTest {
|
||||
private Board boardWithDifferentAmountOfAllTypes;
|
||||
private final Map<WallType,Integer> wallTypeNumberMap = new HashMap<>();
|
||||
private final Map<TileType,Integer> tileTypeNumberMap = new HashMap<>();
|
||||
private Grid<Tile> tileGridforlaser;
|
||||
private Grid<Wall> wallGridforlaser;
|
||||
private List<Robot> robotListforlaser;
|
||||
private Board boardforlaser;
|
||||
|
||||
@ -59,8 +56,8 @@ public class BoardTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
tileGridforlaser = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH));
|
||||
wallGridforlaser = new Grid<>(8, 8);
|
||||
Grid<Tile> tileGridforlaser = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH));
|
||||
Grid<Wall> wallGridforlaser = new Grid<>(8, 8);
|
||||
robotListforlaser = new ArrayList<>();
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_1, new Position(2,1)));
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_2, new Position(4,0)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user