78 lines
2.7 KiB
Java
78 lines
2.7 KiB
Java
package ch.zhaw.catan;
|
|
import org.beryx.textio.TextIO;
|
|
import org.beryx.textio.TextIoFactory;
|
|
import org.beryx.textio.TextTerminal;
|
|
|
|
import java.awt.*;
|
|
import java.util.HashMap;
|
|
|
|
import static ch.zhaw.catan.Command.*;
|
|
|
|
public class Parser {
|
|
TextIO textIO = TextIoFactory.getTextIO();
|
|
TextTerminal<?> textTerminal;
|
|
|
|
public Parser() {
|
|
textTerminal = textIO.getTextTerminal();
|
|
}
|
|
|
|
public Point getPoint() {
|
|
return new Point(textIO.newIntInputReader().withMinVal(0).read("x coordinate:"),
|
|
textIO.newIntInputReader().withMinVal(0).read("y coordinate:"));
|
|
}
|
|
|
|
public void displayGameboard(String gameboard) {
|
|
textTerminal.println(gameboard);
|
|
}
|
|
|
|
public void displayPlayerResourceStock(HashMap<Config.Resource, Integer> currentPlayerResource){
|
|
textTerminal.println("You own the follwing Resources");
|
|
for(Config.Resource resource : currentPlayerResource.keySet()){
|
|
textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource));
|
|
}
|
|
}
|
|
|
|
public void displayWinnertext(Config.Faction winner){
|
|
textTerminal.println(winner.name() + "won the game!");
|
|
}
|
|
|
|
public HashMap<String, Integer> gameStart(){
|
|
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("Winpoints 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("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 have been thrown, the combined value is: " + number);
|
|
}
|
|
|
|
public void playerTurn(Config.Faction faction) {
|
|
textTerminal.println("It is " + faction.name() + "'s turn.");
|
|
}
|
|
|
|
public void errorMessage(){
|
|
textTerminal.println("The command was not excecuted successfully!");
|
|
}
|
|
|
|
public Command getAction() {
|
|
return textIO.newEnumInputReader(Command.class).read("What would you like to do?");
|
|
}
|
|
|
|
public Config.Resource trade(boolean give) {
|
|
String output = "give";
|
|
if (!give){
|
|
output = "receive";
|
|
}
|
|
return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + output );
|
|
}
|
|
}
|
|
|