Implemented the functionality of all methods in Parser.java and created missing Enum Instances in Command.java.
This commit is contained in:
parent
60d1c9a90b
commit
a7a2085632
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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,37 +26,47 @@ 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 NEXTPLAYER:
|
||||||
|
return NEXTPLAYER;
|
||||||
|
case BUILDSETTLEMENT:
|
||||||
|
return BUILDSETTLEMENT;
|
||||||
|
case BUILDCITY:
|
||||||
|
return BUILDCITY;
|
||||||
|
case BUILDROAD:
|
||||||
|
return BUILDROAD;
|
||||||
|
case TRADEWITHBANK:
|
||||||
|
return TRADEWITHBANK;
|
||||||
case QUIT:
|
case QUIT:
|
||||||
System.out.println("quit");
|
|
||||||
return QUIT;
|
return QUIT;
|
||||||
|
|
||||||
case UNKNOWN:
|
|
||||||
return UNKNOWN;
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue