diff --git a/.idea/misc.xml b/.idea/misc.xml index b573818..c3dfb30 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index de9da7a..14411cf 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -10,6 +10,10 @@ public class Siedler { //Spiel erstellen Parser parser = new Parser(); SiedlerGame game = foundingPhase(parser); + gamePhase(parser, game); + } + + private static void gamePhase(Parser parser, SiedlerGame game) { boolean running = true; boolean diceThrown = false; while (running){ @@ -23,39 +27,23 @@ public class Siedler { parser.displayPlayerInfo(game.getCurruntPlayerResource(), game.getCurrentPlayerWinpoints()); switch (parser.getAction()) { case NEXTPLAYER: - Config.Faction winner = game.getWinner(); - if(winner == null) { - game.switchToNextPlayer(); - diceThrown = false; - } else { - parser.displayWinnertext(winner); + if(caseNextPlayer(parser, game)){ running = false; + } else { + diceThrown = false; } break; case BUILDSETTLEMENT: - parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT); - if(!game.buildSettlement(parser.getPoint())){ - parser.errorMessage(); - } + caseBuildStructure(parser, game, Config.Structure.SETTLEMENT); break; case BUILDCITY: - parser.giveCoordinatesForStructures(Config.Structure.CITY); - if(!game.buildCity(parser.getPoint())){ - parser.errorMessage(); - } + caseBuildStructure(parser, game, Config.Structure.CITY); break; case BUILDROAD: - parser.giveCoordinatesForStructures(Config.Structure.ROAD); - if(game.buildRoad(parser.getPoint(), parser.getPoint())){ - parser.errorMessage(); - } + caseBuildStructure(parser, game, Config.Structure.ROAD); break; case TRADEWITHBANK: - Config.Resource offer = parser.trade(true); - Config.Resource want = parser.trade(false); - if(!game.tradeWithBankFourToOne(offer, want)){ - parser.errorMessage(); - } + caseTradeWithBank(parser, game); break; case QUIT: running = false; @@ -67,6 +55,40 @@ public class Siedler { } } + private static boolean caseNextPlayer(Parser parser, SiedlerGame game){ + Config.Faction winner = game.getWinner(); + if(winner == null) { + game.switchToNextPlayer(); + return false; + } else { + parser.displayWinnertext(winner); + return true; + } + } + + 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)){ + parser.errorMessage(); + } + } + + private static void caseBuildStructure(Parser parser, SiedlerGame game, Config.Structure structure) { + parser.giveCoordinatesForStructures(structure); + boolean successfully = false; + if(structure == Config.Structure.SETTLEMENT){ + successfully = game.buildSettlement(parser.getPoint()); + } else if(structure == Config.Structure.CITY) { + successfully = game.buildCity(parser.getPoint()); + } else if(structure == Config.Structure.ROAD){ + successfully = game.buildRoad(parser.getPoint(), parser.getPoint()); + } + if(!successfully){ + parser.errorMessage(); + } + } + private static void throwDice(SiedlerGame game, Parser parser) { Random random = new Random(); //sum of two integers from 0-5 + 2 --> sum of two integers from 1-6