Oppdaterer Robot til å bruke en RobotID i stedet for en playerId int

This commit is contained in:
Kristian Knarvik 2020-02-22 23:37:03 +01:00
parent 37f6e44220
commit 9c5a2b60e7
2 changed files with 16 additions and 14 deletions

View File

@ -1,13 +1,14 @@
package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.element_properties.Position;
import inf112.fiasko.roborally.element_properties.RobotID;
/**
* this class represents a robot
* This class represents a robot
*/
public class Robot {
private int robotDamageTaken = 0;
private final int playerId;
private final RobotID robotId;
private boolean inPowerDown = false;
private int lastFlagVisited = 0;
private Position backupPosition;
@ -15,11 +16,11 @@ public class Robot {
/**
* Instantiates a new robot
* @param playerId gives the robot a identifier that links it too the correct player
* @param robotId gives the robot a identifier that links it too the correct player
* @param spawnPosition gives the robot its starting position on the map
*/
public Robot (int playerId, Position spawnPosition){
this.playerId=playerId;
public Robot (RobotID robotId, Position spawnPosition) {
this.robotId = robotId;
this.backupPosition = spawnPosition;
this.currentPosition = spawnPosition;
}
@ -33,7 +34,7 @@ public class Robot {
}
/**
* Set the robot's damage too a given amount
* Sets the robot's damage to a given amount
* @param damage the amount of damage the robot has received
*/
public void setDamage (int damage){
@ -78,8 +79,8 @@ public class Robot {
* @param newBackupPosition the position of the flag
*/
public void setLastFlagVisitedAndBackupPosition(int currentFlag, Position newBackupPosition){
this.lastFlagVisited=currentFlag;
this.backupPosition=newBackupPosition;
this.lastFlagVisited = currentFlag;
this.backupPosition = newBackupPosition;
}
/**
@ -91,8 +92,8 @@ public class Robot {
}
/**
* Gets the robots backup position
* @return robots backup position
* Gets the robot's backup position
* @return The robot's backup position
*/
public Position getBackupPosition(){
return backupPosition;
@ -102,8 +103,8 @@ public class Robot {
* Gets the identifier of the players controlling the robot
* @return player identifier
*/
public int getPlayerId(){
return playerId;
public RobotID getRobotId(){
return robotId;
}
}

View File

@ -3,6 +3,7 @@ package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.element_properties.Position;
import static org.junit.Assert.assertEquals;
import inf112.fiasko.roborally.element_properties.RobotID;
import org.junit.Before;
import org.junit.Test;
@ -12,7 +13,7 @@ public class RobotTest {
@Before
public void setUp(){
robotPosition = new Position(3,6);
testRobot = new Robot(6, robotPosition);
testRobot = new Robot(RobotID.ROBOT_6, robotPosition);
}
@Test
public void testRobotGetDamageOnInitializedRobot(){
@ -20,7 +21,7 @@ public class RobotTest {
}
@Test
public void testRobotGetPlayerId(){
assertEquals(6, testRobot.getPlayerId());
assertEquals(RobotID.ROBOT_6, testRobot.getRobotId());
}
@Test
public void testRobotGetBackupOnInitializedRobot(){