Completed Java Doc in Siedler.java
This commit is contained in:
		
							parent
							
								
									d35c7299ae
								
							
						
					
					
						commit
						8052ac97ff
					
				| 
						 | 
					@ -3,16 +3,25 @@ package ch.zhaw.catan;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Random;
 | 
					import java.util.Random;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This Class manages the game process and contains the Main Method wich creates and starts a new Parser and a new Game.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
public class Siedler {
 | 
					public class Siedler {
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The main Method of the game. It creates a Parser Object and calls the Methods foundingPhase (to create a new Game) and gamePhase
 | 
				
			||||||
 | 
					     * @param args There are no arguments needed.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public static void main(String[] args) {
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        //Spiel erstellen
 | 
					 | 
				
			||||||
        Parser parser = new Parser();
 | 
					        Parser parser = new Parser();
 | 
				
			||||||
        SiedlerGame game = foundingPhase(parser);
 | 
					        SiedlerGame game = foundingPhase(parser);
 | 
				
			||||||
        gamePhase(parser, game);
 | 
					        gamePhase(parser, game);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The Method for the usual game Process. It contains the Main loop to get new commands from the players and calls the associated methods.
 | 
				
			||||||
 | 
					     * @param parser The Parser Object which will interact with the player.
 | 
				
			||||||
 | 
					     * @param game The Game object which is already created and has the foundig phase completed.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private static void gamePhase(Parser parser, SiedlerGame game) {
 | 
					    private static void gamePhase(Parser parser, SiedlerGame game) {
 | 
				
			||||||
        boolean running = true;
 | 
					        boolean running = true;
 | 
				
			||||||
        boolean diceThrown = false;
 | 
					        boolean diceThrown = false;
 | 
				
			||||||
| 
						 | 
					@ -21,10 +30,10 @@ public class Siedler {
 | 
				
			||||||
            parser.displayGameboard(game.getBoard().getTextView()); //todo jedesmal ausgeben? oder nur wenn neuer Spieler oder separater Befehl?
 | 
					            parser.displayGameboard(game.getBoard().getTextView()); //todo jedesmal ausgeben? oder nur wenn neuer Spieler oder separater Befehl?
 | 
				
			||||||
            parser.playerTurn(currentPlayerFaction);
 | 
					            parser.playerTurn(currentPlayerFaction);
 | 
				
			||||||
            if(!diceThrown) {
 | 
					            if(!diceThrown) {
 | 
				
			||||||
                throwDice(game, parser);
 | 
					                throwDice(parser, game);
 | 
				
			||||||
                diceThrown = true;
 | 
					                diceThrown = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            parser.displayPlayerInfo(game.getCurruntPlayerResource(), game.getCurrentPlayerWinpoints());
 | 
					            parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinpoints());
 | 
				
			||||||
            switch (parser.getAction()) {
 | 
					            switch (parser.getAction()) {
 | 
				
			||||||
                case NEXTPLAYER:
 | 
					                case NEXTPLAYER:
 | 
				
			||||||
                    if(caseNextPlayer(parser, game)){
 | 
					                    if(caseNextPlayer(parser, game)){
 | 
				
			||||||
| 
						 | 
					@ -55,6 +64,12 @@ public class Siedler {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The Method which is called if the player chooses the command "next Player".
 | 
				
			||||||
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
 | 
					     * @param game The game Object which will be used to execute the Method.
 | 
				
			||||||
 | 
					     * @return true: if there is a winner and game is finished. false: if there is no winner (yet).
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private static boolean caseNextPlayer(Parser parser, SiedlerGame game){
 | 
					    private static boolean caseNextPlayer(Parser parser, SiedlerGame game){
 | 
				
			||||||
        Config.Faction winner = game.getWinner();
 | 
					        Config.Faction winner = game.getWinner();
 | 
				
			||||||
        if(winner == null) {
 | 
					        if(winner == null) {
 | 
				
			||||||
| 
						 | 
					@ -66,6 +81,11 @@ public class Siedler {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The Method which is called if the player chooses the command "Trade with bank".
 | 
				
			||||||
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
 | 
					     * @param game The game Object which will be used to execute the Method.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private static void caseTradeWithBank(Parser parser, SiedlerGame game) {
 | 
					    private static void caseTradeWithBank(Parser parser, SiedlerGame game) {
 | 
				
			||||||
        Config.Resource offer = parser.trade(true);
 | 
					        Config.Resource offer = parser.trade(true);
 | 
				
			||||||
        Config.Resource want = parser.trade(false);
 | 
					        Config.Resource want = parser.trade(false);
 | 
				
			||||||
| 
						 | 
					@ -74,6 +94,12 @@ public class Siedler {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The Method which is called if the player chooses a command to build any structure.
 | 
				
			||||||
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
 | 
					     * @param game The game Object which will be used to execute the Method.
 | 
				
			||||||
 | 
					     * @param structure The kind of Structure the player selected to build.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private static void caseBuildStructure(Parser parser, SiedlerGame game, Config.Structure structure) {
 | 
					    private static void caseBuildStructure(Parser parser, SiedlerGame game, Config.Structure structure) {
 | 
				
			||||||
        parser.giveCoordinatesForStructures(structure);
 | 
					        parser.giveCoordinatesForStructures(structure);
 | 
				
			||||||
        boolean successfully = false;
 | 
					        boolean successfully = false;
 | 
				
			||||||
| 
						 | 
					@ -89,41 +115,54 @@ public class Siedler {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static void throwDice(SiedlerGame game, Parser parser) {
 | 
					    /**
 | 
				
			||||||
 | 
					     * The method which calculates a random dice number and calls the method throwDice in the game Object.
 | 
				
			||||||
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
 | 
					     * @param game The game Object which will be used to execute the Method.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private static void throwDice(Parser parser, SiedlerGame game) {
 | 
				
			||||||
        Random random = new Random();
 | 
					        Random random = new Random();
 | 
				
			||||||
        //sum of two integers from 0-5 + 2 --> sum of two integers from 1-6
 | 
					        //(sum of two random integers from 0-5) + 2 => (sum of two random integers from 1-6)
 | 
				
			||||||
        int thrownDices = random.nextInt(6) + random.nextInt(6) + 2;
 | 
					        int thrownDices = random.nextInt(6) + random.nextInt(6) + 2;
 | 
				
			||||||
        //todo check if 7
 | 
					 | 
				
			||||||
        parser.thrownDices(thrownDices);
 | 
					        parser.thrownDices(thrownDices);
 | 
				
			||||||
        game.throwDice(thrownDices);
 | 
					        game.throwDice(thrownDices);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The Method which executes the whole founding phase. It Creates a new SiedlerGame Object and prompts the players to build their first structures.
 | 
				
			||||||
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
 | 
					     * @return The new SiedlerGame Object which is created.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private static SiedlerGame foundingPhase(Parser parser) {
 | 
					    private static SiedlerGame foundingPhase(Parser parser) {
 | 
				
			||||||
        HashMap<String, Integer> gameInfo = parser.gameStart();
 | 
					        HashMap<String, Integer> gameInfo = parser.gameStart();
 | 
				
			||||||
        SiedlerGame game = new SiedlerGame(gameInfo.get("NumberOfWinPoints"), gameInfo.get("NumberOfPlayers"));
 | 
					        SiedlerGame game = new SiedlerGame(gameInfo.get("NumberOfWinPoints"), gameInfo.get("NumberOfPlayers"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //each Player builds their first Settlement and first Road in reverse order than in the rest of the game
 | 
				
			||||||
        for(int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++){
 | 
					        for(int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++){
 | 
				
			||||||
            buildStructuresInFoundingPhase(game, parser, false);
 | 
					            buildStructuresInFoundingPhase(parser, game, false);
 | 
				
			||||||
            if(player < gameInfo.get("NumberOfPlayers")){
 | 
					            if(player < gameInfo.get("NumberOfPlayers")){
 | 
				
			||||||
                game.switchToPreviousPlayer();
 | 
					                game.switchToPreviousPlayer();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //each Player bilds their second Settlement and second Road and gets a Payout for these Structures in usual order.
 | 
				
			||||||
        for(int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++){
 | 
					        for(int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++){
 | 
				
			||||||
            buildStructuresInFoundingPhase(game, parser, true);
 | 
					            buildStructuresInFoundingPhase(parser, game, true);
 | 
				
			||||||
            game.switchToNextPlayer();
 | 
					            game.switchToNextPlayer();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return game;
 | 
					        return game;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
    private static void buildStructuresInFoundingPhase(SiedlerGame game, Parser parser, Boolean payout){
 | 
					     * The Method is called by foundingPhase. It prompts the Player to build a Settlement and a Road.
 | 
				
			||||||
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
 | 
					     * @param game The game Object which will be used to execute the Method.
 | 
				
			||||||
 | 
					     * @param payout true (for second Settlement in founding Phase): the Player gets a payout for the settlment. false (for first Settlement in founding Phase): The Player gets no payout.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private static void buildStructuresInFoundingPhase(Parser parser, SiedlerGame game, Boolean payout){
 | 
				
			||||||
        parser.displayGameboard(game.getBoard().getTextView());
 | 
					        parser.displayGameboard(game.getBoard().getTextView());
 | 
				
			||||||
        parser.playerTurn(game.getCurrentPlayerFaction());
 | 
					        parser.playerTurn(game.getCurrentPlayerFaction());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        //build Settlement
 | 
					        //build Settlement
 | 
				
			||||||
        parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
 | 
					        parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
 | 
				
			||||||
        boolean sucessful = false;
 | 
					        boolean sucessful = false;
 | 
				
			||||||
| 
						 | 
					@ -149,6 +188,4 @@ public class Siedler {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }  while(!sucessful);
 | 
					        }  while(!sucessful);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -128,7 +128,7 @@ public class SiedlerGame {
 | 
				
			||||||
        return allPlayers.get(activePlayer).getSpecificResource(resource);
 | 
					        return allPlayers.get(activePlayer).getSpecificResource(resource);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public HashMap<Resource, Integer> getCurruntPlayerResource() {
 | 
					    public HashMap<Resource, Integer> getCurrentPlayerResource() {
 | 
				
			||||||
        return allPlayers.get(activePlayer).getResources();
 | 
					        return allPlayers.get(activePlayer).getResources();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue