Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/ch/zhaw/catan/SiedlerGame.java
This commit is contained in:
Andrin Fassbind 2021-12-03 09:47:04 +01:00
commit 40dcfaa304
3 changed files with 33 additions and 26 deletions

View File

@ -1,4 +0,0 @@
package ch.zhaw.catan;
public class CommandWords {
}

View File

@ -25,15 +25,16 @@ public class Parser {
textTerminal.println(gameboard); textTerminal.println(gameboard);
} }
public void displayPlayerResourceStock(HashMap<Config.Resource, Integer> curruntPlayerResource){ public void displayPlayerInfo(HashMap<Config.Resource, Integer> currentPlayerResource, int winpoints){
textTerminal.println("You own the follwing Resources"); textTerminal.println("You are currently holding" + winpoints + " winpoints.");
for(Config.Resource resource : curruntPlayerResource.keySet()){ textTerminal.println("You own the follwing resources:");
textTerminal.println(resource.name() + ":" + curruntPlayerResource.get(resource)); for(Config.Resource resource : currentPlayerResource.keySet()){
textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource));
} }
} }
public void displayWinnertext(Config.Faction winner){ public void displayWinnertext(Config.Faction winner){
textTerminal.println(winner.name() + "won the game!"); textTerminal.println(winner.name() + " won the game!");
} }
public HashMap<String, Integer> gameStart(){ public HashMap<String, Integer> gameStart(){
@ -52,8 +53,6 @@ public class Parser {
public void thrownDices(int number){ public void thrownDices(int number){
textTerminal.println ("Dices have been thrown, the combined value is: " + number); textTerminal.println ("Dices have been thrown, the combined value is: " + number);
} }
public void playerTurn(Config.Faction faction) { public void playerTurn(Config.Faction faction) {
@ -68,12 +67,22 @@ public class Parser {
return textIO.newEnumInputReader(Command.class).read("What would you like to do?"); return textIO.newEnumInputReader(Command.class).read("What would you like to do?");
} }
/**
*
* @param give if true ask for resource to give if false for resource to receive
* @return
*/
public Config.Resource trade(boolean give) { public Config.Resource trade(boolean give) {
String output = "give"; String output = "give";
if (!give){ if (!give){
output = "receive"; output = "receive";
} }
return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + give ); return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + output );
} }
public void quit(){
textTerminal.dispose();
textIO.dispose();
}
} }

View File

@ -1,15 +1,8 @@
package ch.zhaw.catan; package ch.zhaw.catan;
import org.beryx.textio.TextIO;
import org.beryx.textio.TextIoFactory;
import org.beryx.textio.TextTerminal;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random; import java.util.Random;
import static ch.zhaw.catan.Command.*;
import static ch.zhaw.catan.Command.QUIT;
public class Siedler { public class Siedler {
public static void main(String[] args) { public static void main(String[] args) {
@ -20,35 +13,43 @@ public class Siedler {
boolean running = true; boolean running = true;
boolean diceThrown = false; boolean diceThrown = false;
while (running){ while (running){
Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
parser.displayGameboard(game.getBoard().getTextView()); parser.displayGameboard(game.getBoard().getTextView());
parser.playerTurn(game.getCurrentPlayerFaction()); parser.playerTurn(currentPlayerFaction);
if(!diceThrown) { if(!diceThrown) {
throwDice(game, parser); throwDice(game, parser);
diceThrown = true; diceThrown = true;
} }
parser.displayPlayerResourceStock(game.getCurruntPlayerResource());
parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinpoints());
switch (parser.getAction()) { switch (parser.getAction()) {
case NEXTPLAYER: case NEXTPLAYER:
Config.Faction winner = game.getWinner(); Config.Faction winner = game.getWinner();
if(winner == null) { if(winner == null) {
game.switchToNextPlayer(); game.switchToNextPlayer();
diceThrown = false; diceThrown = false;
break;
} else { } else {
parser.displayWinnertext(winner); parser.displayWinnertext(winner);
running = false; running = false;
} }
break;
case BUILDSETTLEMENT: case BUILDSETTLEMENT:
parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT); parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
game.buildSettlement(parser.getPoint()); if(!game.buildSettlement(parser.getPoint())){
parser.errorMessage();
}
break; break;
case BUILDCITY: case BUILDCITY:
parser.giveCoordinatesForStructures(Config.Structure.CITY); parser.giveCoordinatesForStructures(Config.Structure.CITY);
game.buildCity(parser.getPoint()); if(!game.buildCity(parser.getPoint())){
parser.errorMessage();
}
break; break;
case BUILDROAD: case BUILDROAD:
parser.giveCoordinatesForStructures(Config.Structure.ROAD); parser.giveCoordinatesForStructures(Config.Structure.ROAD);
game.buildRoad(parser.getPoint(), parser.getPoint()); if(game.buildRoad(parser.getPoint(), parser.getPoint())){
parser.errorMessage();
}
break; break;
case TRADEWITHBANK: case TRADEWITHBANK:
Config.Resource offer = parser.trade(true); Config.Resource offer = parser.trade(true);
@ -59,7 +60,7 @@ public class Siedler {
break; break;
case QUIT: case QUIT:
running = false; running = false;
//todo close window parser.quit();
break; break;
default: default:
parser.errorMessage(); parser.errorMessage();
@ -71,6 +72,7 @@ public class Siedler {
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 integers from 0-5 + 2 --> sum of two 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);
} }