Minor Grammar and Cameltow fixes

This commit is contained in:
Leonardo Brandenberger
2021-12-09 17:19:40 +01:00
parent f3b9cd2771
commit ffc97a39ef
11 changed files with 254 additions and 250 deletions
+37 -31
View File
@@ -9,6 +9,7 @@ import java.util.Random;
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) {
@@ -19,24 +20,25 @@ public class Siedler {
/**
* 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 founding phase completed.
* @param game The Game object which is already created and has the founding phase completed.
*/
private static void gamePhase(Parser parser, SiedlerGame game) {
boolean running = true;
boolean diceThrown = false;
while (running){
while (running) {
Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
parser.displayGameboard(game.getBoard().getTextView()); //todo jedesmal ausgeben? oder nur wenn neuer Spieler oder separater Befehl?
parser.playerTurn(currentPlayerFaction);
if(!diceThrown) {
if (!diceThrown) {
throwDice(parser, game);
diceThrown = true;
}
parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinPoints());
switch (parser.getAction()) {
case NEXTPLAYER:
if(caseNextPlayer(parser, game)){
if (caseNextPlayer(parser, game)) {
running = false;
} else {
diceThrown = false;
@@ -66,13 +68,14 @@ 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.
* @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();
if(winner == null) {
if (winner == null) {
game.switchToNextPlayer();
return false;
} else {
@@ -83,42 +86,45 @@ 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.
* @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);
if(!game.tradeWithBankFourToOne(offer, want)){
if (!game.tradeWithBankFourToOne(offer, want)) {
parser.errorMessage();
}
}
/**
* 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 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;
if(structure == Config.Structure.SETTLEMENT){
if (structure == Config.Structure.SETTLEMENT) {
successfully = game.buildSettlement(parser.getPoint());
} else if(structure == Config.Structure.CITY) {
} else if (structure == Config.Structure.CITY) {
successfully = game.buildCity(parser.getPoint());
} else if(structure == Config.Structure.ROAD){
} else if (structure == Config.Structure.ROAD) {
successfully = game.buildRoad(parser.getPoint(), parser.getPoint());
}
if(!successfully){
if (!successfully) {
parser.errorMessage();
}
}
/**
* 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.
* @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();
@@ -130,6 +136,7 @@ public class Siedler {
/**
* 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.
*/
@@ -138,15 +145,15 @@ public class Siedler {
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(parser, game, false);
if(player < gameInfo.get("NumberOfPlayers")){
if (player < gameInfo.get("NumberOfPlayers")) {
game.switchToPreviousPlayer();
}
}
//each Player builds 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(parser, game, true);
game.switchToNextPlayer();
}
@@ -155,37 +162,36 @@ public class Siedler {
/**
* 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 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 settlement. false (for first Settlement in founding Phase): The Player gets no payout.
*/
private static void buildStructuresInFoundingPhase(Parser parser, SiedlerGame game, Boolean 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 successful = false;
do{
if(game.placeInitialSettlement(parser.getPoint(), payout)) {
do {
if (game.placeInitialSettlement(parser.getPoint(), payout)) {
successful = true;
}
else{
} else {
parser.errorMessage();
}
} while(!successful);
} while (!successful);
//build Road
parser.displayGameboard(game.getBoard().getTextView());
parser.giveCoordinatesForStructures(Config.Structure.ROAD);
successful = false;
do{
if(game.placeInitialRoad(parser.getPoint(), parser.getPoint())) {
do {
if (game.placeInitialRoad(parser.getPoint(), parser.getPoint())) {
successful = true;
}
else{
} else {
parser.errorMessage();
}
} while(!successful);
} while (!successful);
}
}