2020-02-20 13:12:18 +01:00
|
|
|
package inf112.fiasko.roborally.objects;
|
|
|
|
|
2020-02-23 20:10:28 +01:00
|
|
|
import inf112.fiasko.roborally.element_properties.Direction;
|
2020-02-20 13:12:18 +01:00
|
|
|
import inf112.fiasko.roborally.element_properties.Position;
|
2020-02-22 23:37:03 +01:00
|
|
|
import inf112.fiasko.roborally.element_properties.RobotID;
|
2020-02-20 11:56:20 +01:00
|
|
|
|
|
|
|
/**
|
2020-02-22 23:37:03 +01:00
|
|
|
* This class represents a robot
|
2020-02-20 11:56:20 +01:00
|
|
|
*/
|
|
|
|
public class Robot {
|
|
|
|
private int robotDamageTaken = 0;
|
2020-02-22 23:37:03 +01:00
|
|
|
private final RobotID robotId;
|
2020-02-20 11:56:20 +01:00
|
|
|
private boolean inPowerDown = false;
|
|
|
|
private int lastFlagVisited = 0;
|
|
|
|
private Position backupPosition;
|
|
|
|
private Position currentPosition;
|
2020-02-23 20:10:28 +01:00
|
|
|
private Direction facingDirection;
|
2020-02-20 12:05:49 +01:00
|
|
|
|
2020-02-22 13:18:30 +01:00
|
|
|
/**
|
2020-02-22 13:42:43 +01:00
|
|
|
* Instantiates a new robot
|
2020-02-22 23:37:03 +01:00
|
|
|
* @param robotId gives the robot a identifier that links it too the correct player
|
2020-02-22 13:42:43 +01:00
|
|
|
* @param spawnPosition gives the robot its starting position on the map
|
2020-02-22 13:18:30 +01:00
|
|
|
*/
|
2020-02-22 23:37:03 +01:00
|
|
|
public Robot (RobotID robotId, Position spawnPosition) {
|
|
|
|
this.robotId = robotId;
|
2020-02-20 11:56:20 +01:00
|
|
|
this.backupPosition = spawnPosition;
|
|
|
|
this.currentPosition = spawnPosition;
|
2020-02-23 20:10:28 +01:00
|
|
|
this.facingDirection = Direction.NORTH;
|
2020-02-20 11:56:20 +01:00
|
|
|
}
|
|
|
|
|
2020-02-22 13:42:43 +01:00
|
|
|
/**
|
|
|
|
* Gets the damage the robot has taken
|
|
|
|
* @return the amount of damage the robot has received
|
|
|
|
*/
|
2020-02-20 11:56:20 +01:00
|
|
|
public int getDamage(){
|
|
|
|
return robotDamageTaken;
|
|
|
|
}
|
2020-02-22 13:42:43 +01:00
|
|
|
|
|
|
|
/**
|
2020-02-22 23:37:03 +01:00
|
|
|
* Sets the robot's damage to a given amount
|
2020-02-22 13:42:43 +01:00
|
|
|
* @param damage the amount of damage the robot has received
|
|
|
|
*/
|
2020-02-20 11:56:20 +01:00
|
|
|
public void setDamage (int damage){
|
|
|
|
this.robotDamageTaken = damage;
|
|
|
|
}
|
2020-02-22 13:42:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the robot's current position on the map
|
|
|
|
* @return the robot's current position
|
|
|
|
*/
|
2020-02-20 11:56:20 +01:00
|
|
|
public Position getPosition(){
|
|
|
|
return currentPosition;
|
|
|
|
}
|
2020-02-22 13:42:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* places the robot on a new position
|
|
|
|
* @param newPosition the new position for the robot
|
|
|
|
*/
|
2020-02-20 11:56:20 +01:00
|
|
|
public void setPosition( Position newPosition ){
|
|
|
|
this.currentPosition = newPosition;
|
|
|
|
}
|
2020-02-22 13:42:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Places the status of the powerdown field
|
|
|
|
* @param powerDownStatus True if robot is going to go to powerdown. False otherwise
|
|
|
|
*/
|
2020-02-20 11:56:20 +01:00
|
|
|
public void setPowerDown(Boolean powerDownStatus){
|
|
|
|
this.inPowerDown = powerDownStatus;
|
|
|
|
}
|
2020-02-22 13:42:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the status of the robot's powerdown field
|
|
|
|
* @return robot's powerdown status
|
|
|
|
*/
|
2020-02-20 11:56:20 +01:00
|
|
|
public Boolean isInPowerDown(){
|
|
|
|
return inPowerDown;
|
|
|
|
}
|
|
|
|
|
2020-02-22 13:42:43 +01:00
|
|
|
/**
|
|
|
|
* Set the robot's last visited flag too the new flag and places its backup on the flags position
|
|
|
|
* @param currentFlag the flag the robot is standing on
|
|
|
|
* @param newBackupPosition the position of the flag
|
|
|
|
*/
|
|
|
|
public void setLastFlagVisitedAndBackupPosition(int currentFlag, Position newBackupPosition){
|
2020-02-22 23:37:03 +01:00
|
|
|
this.lastFlagVisited = currentFlag;
|
|
|
|
this.backupPosition = newBackupPosition;
|
2020-02-22 13:42:43 +01:00
|
|
|
}
|
|
|
|
|
2020-02-22 14:10:50 +01:00
|
|
|
/**
|
|
|
|
* Gets the correct flag the robot visited
|
|
|
|
* @return last visited flag
|
|
|
|
*/
|
|
|
|
public int getLastFlagVisited(){
|
|
|
|
return lastFlagVisited;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-22 23:37:03 +01:00
|
|
|
* Gets the robot's backup position
|
|
|
|
* @return The robot's backup position
|
2020-02-22 14:10:50 +01:00
|
|
|
*/
|
|
|
|
public Position getBackupPosition(){
|
|
|
|
return backupPosition;
|
|
|
|
}
|
|
|
|
|
2020-02-22 14:23:38 +01:00
|
|
|
/**
|
|
|
|
* Gets the identifier of the players controlling the robot
|
|
|
|
* @return player identifier
|
|
|
|
*/
|
2020-02-22 23:37:03 +01:00
|
|
|
public RobotID getRobotId(){
|
|
|
|
return robotId;
|
2020-02-22 14:23:38 +01:00
|
|
|
}
|
|
|
|
|
2020-02-23 20:10:28 +01:00
|
|
|
/**
|
|
|
|
* Gets the direction the robot is currently facing
|
|
|
|
* @return The direction the robot is facing
|
|
|
|
*/
|
|
|
|
public Direction getFacingDirection() {
|
|
|
|
return this.facingDirection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the direction the robot is currently facing
|
|
|
|
* @param newFacingDirection The new direction the robot should be facing
|
|
|
|
*/
|
|
|
|
public void setFacingDirection(Direction newFacingDirection) {
|
|
|
|
if (newFacingDirection.getDirectionID() % 2 == 0) {
|
|
|
|
throw new IllegalArgumentException("A robot is unable to face that direction.");
|
|
|
|
}
|
|
|
|
this.facingDirection = newFacingDirection;
|
|
|
|
}
|
2020-02-20 11:56:20 +01:00
|
|
|
}
|