Added java doc in parser class.
This commit is contained in:
		
							parent
							
								
									ecc75e14c8
								
							
						
					
					
						commit
						7f19c5acce
					
				| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
package ch.zhaw.catan;
 | 
			
		||||
 | 
			
		||||
import org.beryx.textio.TextIO;
 | 
			
		||||
import org.beryx.textio.TextIoFactory;
 | 
			
		||||
import org.beryx.textio.TextTerminal;
 | 
			
		||||
| 
						 | 
				
			
			@ -8,81 +9,146 @@ import java.util.HashMap;
 | 
			
		|||
 | 
			
		||||
import static ch.zhaw.catan.Command.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class performs all communication with the player, includes asking for input and showing the map.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leonardo Brandenberger
 | 
			
		||||
 */
 | 
			
		||||
public class Parser {
 | 
			
		||||
    TextIO textIO = TextIoFactory.getTextIO();
 | 
			
		||||
    TextIO textIO;
 | 
			
		||||
    TextTerminal<?> textTerminal;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a parser Object, initializes the textIO components TextTerminal and textIO.
 | 
			
		||||
     */
 | 
			
		||||
    public Parser() {
 | 
			
		||||
        textIO = TextIoFactory.getTextIO();
 | 
			
		||||
        textTerminal = textIO.getTextTerminal();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Ask user to input two coordinates with have to be higher than 0 and returns them as a Point.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Point that the user specified with an input
 | 
			
		||||
     */
 | 
			
		||||
    public Point getPoint() {
 | 
			
		||||
        return new Point(textIO.newIntInputReader().withMinVal(0).read("x coordinate:"),
 | 
			
		||||
                textIO.newIntInputReader().withMinVal(0).read("y coordinate:"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Takes care of displaying the gameboard that it receives as parameter.
 | 
			
		||||
     *
 | 
			
		||||
     * @param gameboard that has to be displayed
 | 
			
		||||
     */
 | 
			
		||||
    public void displayGameboard(String gameboard) {
 | 
			
		||||
        textTerminal.println(gameboard);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void displayPlayerInfo(HashMap<Config.Resource, Integer> currentPlayerResource, int winpoints){
 | 
			
		||||
    /**
 | 
			
		||||
     * Displays Player info that includes his current resources and his winpoint he currently owns
 | 
			
		||||
     *
 | 
			
		||||
     * @param currentPlayerResource Hashmap of all Resources with corresponding number that a player currently owns.
 | 
			
		||||
     * @param winpoints             that the player is currently holding
 | 
			
		||||
     */
 | 
			
		||||
    public void displayPlayerInfo(HashMap<Config.Resource, Integer> currentPlayerResource, int winpoints) {
 | 
			
		||||
        textTerminal.println("You are currently holding " + winpoints + " winpoints.");
 | 
			
		||||
        textTerminal.println("You own the follwing resources:");
 | 
			
		||||
        for(Config.Resource resource : currentPlayerResource.keySet()){
 | 
			
		||||
        for (Config.Resource resource : currentPlayerResource.keySet()) {
 | 
			
		||||
            textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void displayWinnertext(Config.Faction winner){
 | 
			
		||||
    /**
 | 
			
		||||
     * Displays the winner of the game in the Console.
 | 
			
		||||
     *
 | 
			
		||||
     * @param winner the faction that has won
 | 
			
		||||
     */
 | 
			
		||||
    public void displayWinnertext(Config.Faction winner) {
 | 
			
		||||
        textTerminal.println(winner.name() + " won the game!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public HashMap<String, Integer> gameStart(){
 | 
			
		||||
    /**
 | 
			
		||||
     * Method that is used at the start of the game to get how many players will be playing and how many winpoints
 | 
			
		||||
     * should be set.
 | 
			
		||||
     *
 | 
			
		||||
     * @return HashMap that includes the number of players and how many winpoints the game should have.
 | 
			
		||||
     */
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Asks the player for coordinates to place a structure if the structure is a road the player will be notified
 | 
			
		||||
     * that he will need to input two coordinates a start and a finish one.
 | 
			
		||||
     *
 | 
			
		||||
     * @param structure the structure that should be asked for coordinates
 | 
			
		||||
     */
 | 
			
		||||
    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.");
 | 
			
		||||
        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);
 | 
			
		||||
    /**
 | 
			
		||||
     * Displays the dice number that has been thrown.
 | 
			
		||||
     *
 | 
			
		||||
     * @param number the thrown dice number
 | 
			
		||||
     */
 | 
			
		||||
    public void thrownDices(int number) {
 | 
			
		||||
        textTerminal.println("Dices have been thrown, the combined value is: " + number);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Outputs which player currently is at turn
 | 
			
		||||
     *
 | 
			
		||||
     * @param faction the faction which turn it is
 | 
			
		||||
     */
 | 
			
		||||
    public void playerTurn(Config.Faction faction) {
 | 
			
		||||
    textTerminal.println("It is " + faction.name() + "'s turn.");
 | 
			
		||||
        textTerminal.println("It is " + faction.name() + "'s turn.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void errorMessage(){
 | 
			
		||||
    textTerminal.println("The command was not excecuted successfully!");
 | 
			
		||||
    /**
 | 
			
		||||
     * Outputs error message.
 | 
			
		||||
     */
 | 
			
		||||
    public void errorMessage() {
 | 
			
		||||
        textTerminal.println("The command was not excecuted successfully!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Ask the player what action he would like to perform.
 | 
			
		||||
     * As possible possibilities the Enum Command is used.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Command which action has been choosen
 | 
			
		||||
     */
 | 
			
		||||
    public Command getAction() {
 | 
			
		||||
        return textIO.newEnumInputReader(Command.class).read("What would you like to do?");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Asks the player which resources he would like to trade.
 | 
			
		||||
     * As possibilites the Enum in Config.Resource.class is used.
 | 
			
		||||
     *
 | 
			
		||||
     * @param give if true ask for resource to give if false for resource to receive
 | 
			
		||||
     * @return
 | 
			
		||||
     * @return Config.Resource the resource the player would like to give or receive
 | 
			
		||||
     */
 | 
			
		||||
    public Config.Resource trade(boolean give) {
 | 
			
		||||
        String output = "give";
 | 
			
		||||
        if (!give){
 | 
			
		||||
        if (!give) {
 | 
			
		||||
            output = "receive";
 | 
			
		||||
        }
 | 
			
		||||
        return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + output );
 | 
			
		||||
        return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + output);
 | 
			
		||||
    }
 | 
			
		||||
    public void quit(){
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Clears the instances of textIO and textTerminal.
 | 
			
		||||
     */
 | 
			
		||||
    public void quit() {
 | 
			
		||||
        textTerminal.dispose();
 | 
			
		||||
        textIO.dispose();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue