Implemented the functionality of all methods in Parser.java and created missing Enum Instances in Command.java.

This commit is contained in:
Leonardo Brandenberger 2021-12-02 16:49:44 +01:00
parent 60d1c9a90b
commit a7a2085632
2 changed files with 31 additions and 19 deletions

View File

@ -3,7 +3,8 @@ package ch.zhaw.catan;
import org.beryx.textio.TextIO;
public enum Command {
NEXTPLAYER ("next Player"), QUIT("quit"), UNKNOWN ("unknown");
NEXTPLAYER ("next player"), BUILDSETTLEMENT ("build settlement"), BUILDCITY("build city"),
BUILDROAD("build road"), TRADEWITHBANK("trade with bank"),QUIT("quit");
private String commandWord;

View File

@ -6,8 +6,7 @@ import org.beryx.textio.TextTerminal;
import java.awt.*;
import java.util.HashMap;
import static ch.zhaw.catan.Command.QUIT;
import static ch.zhaw.catan.Command.UNKNOWN;
import static ch.zhaw.catan.Command.*;
public class Parser {
TextIO textIO = TextIoFactory.getTextIO();
@ -16,8 +15,10 @@ public class Parser {
public Parser() {
textTerminal = textIO.getTextTerminal();
}
public Point getPoint() {
return null;
return new Point(textIO.newIntInputReader().withMinVal(0).read("x coordinate:"),
textIO.newIntInputReader().withMinVal(0).read("y coordinate:"));
}
public void displayGameboard(String gameboard) {
@ -25,37 +26,47 @@ public class Parser {
}
public HashMap<String, Integer> gameStart(){
return null;
//Anzahlspieler,int
//Siegespunkte,int
HashMap<String, Integer> gameStartValues = new HashMap<>();
gameStartValues.put("NumberOfPlayers", textIO.newIntInputReader().withMinVal(2).withMaxVal(4).read("Number of players:"));
gameStartValues.put("NumberOfWinPoints", textIO.newIntInputReader().withMinVal(5).withMaxVal(15).read("Winpoint needed for Victory:"));
return gameStartValues;
}
public void giveCoordinatesForStructures(Config.Structure structure) {
textTerminal.println("Please insert coordinates for " + structure);
if(structure == Config.Structure.ROAD) {
textTerminal.println("You are building a road, please first insert the start coordinate and when prompted again the coordinate of the end of the road.");
}
}
public void thrownDices(int number){
textTerminal.println("Dices are being thrown ");
textTerminal.println ("Dices have been thrown, the combined value is: " + number);
}
public void playerTurn(Config.Faction faction) {
textTerminal.println("It is" + faction + "'s turn.");
}
public void errorMessage(){
textTerminal.print("The command was not excecuted successfully!");
}
public Command getAction() {
switch (textIO.newEnumInputReader(Command.class).read("What would you like to do?")) {
case NEXTPLAYER:
return NEXTPLAYER;
case BUILDSETTLEMENT:
return BUILDSETTLEMENT;
case BUILDCITY:
return BUILDCITY;
case BUILDROAD:
return BUILDROAD;
case TRADEWITHBANK:
return TRADEWITHBANK;
case QUIT:
System.out.println("quit");
return QUIT;
case UNKNOWN:
return UNKNOWN;
default:
return null;
}