2023-01-07 16:41:56 +01:00
|
|
|
package tpe.exceptions.roboter;
|
|
|
|
|
2023-01-07 18:48:00 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
2023-01-08 10:46:03 +01:00
|
|
|
import tpe.exceptions.RobotException;
|
|
|
|
|
2023-01-07 16:41:56 +01:00
|
|
|
public class RobotFactory {
|
2023-01-08 10:46:03 +01:00
|
|
|
private Robots nexus6=Nexus6.getInstance();
|
|
|
|
private String factoryName;
|
2023-01-07 18:48:00 +01:00
|
|
|
private HashMap<Integer,Robots> robotStock=new HashMap<>();
|
|
|
|
|
2023-01-08 10:46:03 +01:00
|
|
|
public RobotFactory(String factoryName) {
|
|
|
|
this.factoryName=factoryName;
|
|
|
|
robotStock.put(nexus6.getId(), nexus6);
|
|
|
|
}
|
|
|
|
|
2023-01-07 18:48:00 +01:00
|
|
|
public int constructRobot(RobotType robotType, String name) {
|
|
|
|
Robots robot;
|
2023-01-08 16:28:46 +01:00
|
|
|
|
2023-01-07 18:48:00 +01:00
|
|
|
if(RobotType.R2D2==robotType) {
|
2023-01-08 09:54:17 +01:00
|
|
|
robot=new R2D2(name, createIDR2D2(0,9999));
|
2023-01-07 18:48:00 +01:00
|
|
|
robotStock.put(robot.getId(), robot);
|
|
|
|
return robot.getId();
|
2023-01-08 16:28:46 +01:00
|
|
|
}
|
2023-01-08 19:02:39 +01:00
|
|
|
else {
|
2023-01-08 09:54:17 +01:00
|
|
|
robot=new C3PO(name, createIDC3PO(10000, 19999));
|
2023-01-07 18:48:00 +01:00
|
|
|
robotStock.put(robot.getId(), robot);
|
|
|
|
return robot.getId();
|
|
|
|
}
|
2023-01-08 19:02:39 +01:00
|
|
|
|
2023-01-07 18:48:00 +01:00
|
|
|
}
|
2023-01-07 16:41:56 +01:00
|
|
|
|
2023-01-08 09:54:17 +01:00
|
|
|
private int createIDR2D2(int minValue, int maxValue) {
|
2023-01-07 18:48:00 +01:00
|
|
|
|
2023-01-08 09:54:17 +01:00
|
|
|
int randomID = (int) (Math.random()*(maxValue)) ;
|
2023-01-07 18:48:00 +01:00
|
|
|
if(robotStock.containsKey(randomID))
|
|
|
|
{
|
2023-01-08 09:54:17 +01:00
|
|
|
createIDR2D2(minValue,maxValue);
|
|
|
|
}
|
|
|
|
return randomID;
|
|
|
|
}
|
|
|
|
private int createIDC3PO(int minValue, int maxValue) {
|
|
|
|
|
|
|
|
int randomID = (int) (Math.random()*(maxValue))+minValue ;
|
|
|
|
if(robotStock.containsKey(randomID))
|
|
|
|
{
|
|
|
|
createIDC3PO(minValue,maxValue);
|
2023-01-07 18:48:00 +01:00
|
|
|
}
|
|
|
|
return randomID;
|
|
|
|
}
|
2023-01-08 10:46:03 +01:00
|
|
|
|
|
|
|
public String getFactoryName() {
|
|
|
|
return factoryName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Robots getRobot(int id) {
|
|
|
|
return robotStock.get(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean triggerPower(int id) {
|
|
|
|
Robots robot=getRobot(id);
|
|
|
|
robot.triggerPowerSwitch();
|
|
|
|
return robot.powerStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean powerStatus(int id) {
|
|
|
|
Robots robot=getRobot(id);
|
|
|
|
return robot.powerStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String robotInfo(int id) {
|
|
|
|
Robots robot=getRobot(id);
|
|
|
|
return robot.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Robots dismantleRobot(int id) {
|
|
|
|
return robotStock.remove(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public RobotException robotBlackbox(int id) {
|
|
|
|
Robots robot=getRobot(id);
|
|
|
|
return robot.getLastException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String robotInstructions(int id, int[]zahlen) throws RobotException {
|
|
|
|
Robots robot=getRobot(id);
|
|
|
|
return robot.speak(robot.think(zahlen));
|
|
|
|
}
|
|
|
|
|
|
|
|
public int robotStockSize() {
|
|
|
|
return robotStock.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean containsRobot(int id) {
|
|
|
|
return robotStock.containsKey(id);
|
|
|
|
}
|
2023-01-07 16:41:56 +01:00
|
|
|
}
|