From 8052ac97ff41de8241cefe1834cbc7d1525937e9 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 7 Dec 2021 09:08:10 +0100 Subject: [PATCH] Completed Java Doc in Siedler.java --- src/ch/zhaw/catan/Siedler.java | 71 +++++++++++++++++++++++------- src/ch/zhaw/catan/SiedlerGame.java | 2 +- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index 14411cf..a90d452 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -3,16 +3,25 @@ package ch.zhaw.catan; import java.util.HashMap; 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 { - + /** + * 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) { - - //Spiel erstellen Parser parser = new Parser(); SiedlerGame game = foundingPhase(parser); 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) { boolean running = true; 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.playerTurn(currentPlayerFaction); if(!diceThrown) { - throwDice(game, parser); + throwDice(parser, game); diceThrown = true; } - parser.displayPlayerInfo(game.getCurruntPlayerResource(), game.getCurrentPlayerWinpoints()); + parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinpoints()); switch (parser.getAction()) { case NEXTPLAYER: 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){ Config.Faction winner = game.getWinner(); 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) { Config.Resource offer = parser.trade(true); 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) { parser.giveCoordinatesForStructures(structure); 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(); - //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; - //todo check if 7 parser.thrownDices(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) { HashMap gameInfo = parser.gameStart(); 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++){ - buildStructuresInFoundingPhase(game, parser, false); + buildStructuresInFoundingPhase(parser, game, false); if(player < gameInfo.get("NumberOfPlayers")){ 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++){ - buildStructuresInFoundingPhase(game, parser, true); + buildStructuresInFoundingPhase(parser, game, true); game.switchToNextPlayer(); } 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.playerTurn(game.getCurrentPlayerFaction()); - //build Settlement parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT); boolean sucessful = false; @@ -149,6 +188,4 @@ public class Siedler { } } while(!sucessful); } - - } diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 1e5afc7..204f0a6 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -128,7 +128,7 @@ public class SiedlerGame { return allPlayers.get(activePlayer).getSpecificResource(resource); } - public HashMap getCurruntPlayerResource() { + public HashMap getCurrentPlayerResource() { return allPlayers.get(activePlayer).getResources(); }