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; import org.beryx.textio.TextIO;
public enum Command { 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; private String commandWord;

View File

@ -6,8 +6,7 @@ import org.beryx.textio.TextTerminal;
import java.awt.*; import java.awt.*;
import java.util.HashMap; import java.util.HashMap;
import static ch.zhaw.catan.Command.QUIT; import static ch.zhaw.catan.Command.*;
import static ch.zhaw.catan.Command.UNKNOWN;
public class Parser { public class Parser {
TextIO textIO = TextIoFactory.getTextIO(); TextIO textIO = TextIoFactory.getTextIO();
@ -16,8 +15,10 @@ public class Parser {
public Parser() { public Parser() {
textTerminal = textIO.getTextTerminal(); textTerminal = textIO.getTextTerminal();
} }
public Point getPoint() { 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) { public void displayGameboard(String gameboard) {
@ -25,39 +26,49 @@ public class Parser {
} }
public HashMap<String, Integer> gameStart(){ public HashMap<String, Integer> gameStart(){
return null; HashMap<String, Integer> gameStartValues = new HashMap<>();
//Anzahlspieler,int gameStartValues.put("NumberOfPlayers", textIO.newIntInputReader().withMinVal(2).withMaxVal(4).read("Number of players:"));
//Siegespunkte,int gameStartValues.put("NumberOfWinPoints", textIO.newIntInputReader().withMinVal(5).withMaxVal(15).read("Winpoint needed for Victory:"));
return gameStartValues;
} }
public void giveCoordinatesForStructures(Config.Structure structure) { public void giveCoordinatesForStructures(Config.Structure structure) {
textTerminal.println("Please insert coordinates for " + 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){ 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) { public void playerTurn(Config.Faction faction) {
textTerminal.println("It is" + faction + "'s turn.");
} }
public void errorMessage(){ public void errorMessage(){
textTerminal.print("The command was not excecuted successfully!");
} }
public Command getAction() { public Command getAction() {
switch (textIO.newEnumInputReader(Command.class).read("What would you like to do?")) { switch (textIO.newEnumInputReader(Command.class).read("What would you like to do?")) {
case QUIT: case NEXTPLAYER:
System.out.println("quit"); return NEXTPLAYER;
return QUIT; case BUILDSETTLEMENT:
return BUILDSETTLEMENT;
case UNKNOWN: case BUILDCITY:
return UNKNOWN; return BUILDCITY;
default: case BUILDROAD:
return null; return BUILDROAD;
case TRADEWITHBANK:
return TRADEWITHBANK;
case QUIT:
return QUIT;
default:
return null;
} }
} }
} }