2022-12-08 14:58:44 +01:00
|
|
|
package ui;
|
|
|
|
|
2023-01-09 23:32:30 +01:00
|
|
|
|
|
|
|
|
2023-01-06 22:55:33 +01:00
|
|
|
import domain.Robot;
|
2023-01-03 01:18:57 +01:00
|
|
|
import facade.FactorySystem;
|
2023-01-02 19:51:04 +01:00
|
|
|
import infrastructure.Persistenz;
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
2022-12-08 14:58:44 +01:00
|
|
|
public class UI {
|
2022-12-14 09:54:18 +01:00
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
private FactorySystem fs;
|
2023-01-02 19:51:04 +01:00
|
|
|
private String name;
|
|
|
|
|
|
|
|
Scanner sc = new Scanner(System.in);
|
2023-01-03 01:18:57 +01:00
|
|
|
public UI (FactorySystem fs){
|
|
|
|
this.fs = fs;
|
2023-01-02 19:51:04 +01:00
|
|
|
hauptmenü();
|
|
|
|
|
|
|
|
}
|
|
|
|
public UI (String name){
|
|
|
|
this.name = name;
|
|
|
|
if(Persistenz.existsSavedData(name)){
|
|
|
|
try{
|
2023-01-03 01:18:57 +01:00
|
|
|
this.fs = (FactorySystem) Persistenz.loadFactoryData(name);
|
2023-01-07 18:35:00 +01:00
|
|
|
}catch(Exception ignored){
|
2023-01-02 19:51:04 +01:00
|
|
|
}
|
|
|
|
}else{
|
2023-01-03 01:18:57 +01:00
|
|
|
this.fs = new FactorySystem(name);
|
2023-01-02 19:51:04 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-07 18:35:00 +01:00
|
|
|
//starting screen
|
2023-01-03 01:18:57 +01:00
|
|
|
private void hauptmenü() {
|
|
|
|
mainloop:
|
|
|
|
while(true){
|
|
|
|
System.out.println();
|
2023-01-06 22:55:33 +01:00
|
|
|
System.out.println("____________________________");
|
2023-01-03 01:18:57 +01:00
|
|
|
System.out.println("Sie haben folgende optionen:");
|
2023-01-06 22:55:33 +01:00
|
|
|
System.out.println("-1- --- show all robots ----");
|
|
|
|
System.out.println("-2- --- build new robot ----");
|
|
|
|
System.out.println("-3- ------- use robot ------");
|
|
|
|
System.out.println("-4- --------- Exit ---------");
|
2023-01-03 01:18:57 +01:00
|
|
|
System.out.print(" > ");
|
2023-01-07 18:35:00 +01:00
|
|
|
//User options
|
2023-01-03 01:18:57 +01:00
|
|
|
try{
|
|
|
|
int input = Integer.parseInt(sc.nextLine());
|
|
|
|
switch(input){
|
|
|
|
case 1:
|
|
|
|
listAllRobots();break;
|
|
|
|
case 2: buildNewRobot();break;
|
2023-01-06 22:55:33 +01:00
|
|
|
case 3: useRobot();break;
|
2023-01-03 01:18:57 +01:00
|
|
|
case 4: break mainloop;
|
|
|
|
default:
|
|
|
|
System.out.println("this is an invalid option"); break;
|
|
|
|
}
|
|
|
|
}catch(NumberFormatException e){
|
|
|
|
System.out.println("invalid input");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("Good Bye");
|
|
|
|
}
|
2023-01-07 18:35:00 +01:00
|
|
|
//display all existing robots
|
2023-01-03 01:18:57 +01:00
|
|
|
private void listAllRobots(){
|
|
|
|
String[] listOfAll = fs.getAllRobots();
|
|
|
|
if(listOfAll.length > 0){
|
|
|
|
System.out.println("These robtos exist right now:");
|
|
|
|
for (String s: listOfAll) {
|
|
|
|
System.out.println(s);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
System.out.println("There are no robots yet.");
|
|
|
|
}
|
|
|
|
}
|
2023-01-07 18:35:00 +01:00
|
|
|
//create a new robot
|
2023-01-03 01:18:57 +01:00
|
|
|
private void buildNewRobot(){
|
|
|
|
System.out.println("What shall the name of the robot be?");
|
|
|
|
System.out.print(" > ");
|
|
|
|
String name = sc.nextLine();
|
|
|
|
System.out.println("Which type of robot do u want?");
|
|
|
|
System.out.println(" [0] for R2D2 and [1] for C3PO");
|
|
|
|
System.out.print(" > ");
|
2023-01-07 18:35:00 +01:00
|
|
|
//user enters which type of robot he wants
|
2023-01-03 01:18:57 +01:00
|
|
|
int type = Integer.parseInt(sc.nextLine());
|
|
|
|
if(fs.buildNewRobot(name, type)){
|
2023-01-07 18:35:00 +01:00
|
|
|
switch (type) {
|
|
|
|
case 0 -> System.out.println("Created new Robot of type R2D2 with the name " + name);
|
|
|
|
case 1 -> System.out.println("Created new Robot of type C3PO with the name " + name);
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
System.out.println("Anlegen des Roboters fehlgeschlagen");
|
|
|
|
}
|
2023-01-02 19:51:04 +01:00
|
|
|
}
|
2023-01-07 18:35:00 +01:00
|
|
|
//let the robots sort
|
2023-01-06 22:55:33 +01:00
|
|
|
private void useRobot(){
|
|
|
|
System.out.println("Which robot do you want to use?");
|
|
|
|
listAllRobots();
|
|
|
|
System.out.print(" ID > ");
|
|
|
|
int input = Integer.parseInt(sc.nextLine());
|
2023-01-07 18:35:00 +01:00
|
|
|
// Change the searchForRobot Methode (safety)
|
2023-01-06 22:55:33 +01:00
|
|
|
Robot r = fs.searchForRobot(input);
|
|
|
|
System.out.println("You choose " + r.getName() + " of type " + r.getType());
|
|
|
|
System.out.println("Yout have following options");
|
|
|
|
mainloop:
|
|
|
|
while(true){
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2022-12-08 14:58:44 +01:00
|
|
|
}
|