Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
86d998ddd7
|
@ -1,4 +0,0 @@
|
|||
package ch.zhaw.catan;
|
||||
|
||||
public class CommandWords {
|
||||
}
|
|
@ -25,8 +25,9 @@ public class Parser {
|
|||
textTerminal.println(gameboard);
|
||||
}
|
||||
|
||||
public void displayPlayerResourceStock(HashMap<Config.Resource, Integer> currentPlayerResource){
|
||||
textTerminal.println("You own the follwing Resources");
|
||||
public void displayPlayerInfo(HashMap<Config.Resource, Integer> currentPlayerResource, int winpoints){
|
||||
textTerminal.println("You are currently holding" + winpoints + " winpoints.");
|
||||
textTerminal.println("You own the follwing resources:");
|
||||
for(Config.Resource resource : currentPlayerResource.keySet()){
|
||||
textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource));
|
||||
}
|
||||
|
@ -66,6 +67,11 @@ public class Parser {
|
|||
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) {
|
||||
String output = "give";
|
||||
if (!give){
|
||||
|
@ -73,5 +79,10 @@ public class Parser {
|
|||
}
|
||||
return textIO.newEnumInputReader(Config.Resource.class).read("Which Resource would you like to " + output );
|
||||
}
|
||||
public void quit(){
|
||||
textTerminal.dispose();
|
||||
textIO.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
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.Random;
|
||||
|
||||
import static ch.zhaw.catan.Command.*;
|
||||
import static ch.zhaw.catan.Command.QUIT;
|
||||
|
||||
public class Siedler {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -20,13 +13,15 @@ public class Siedler {
|
|||
boolean running = true;
|
||||
boolean diceThrown = false;
|
||||
while (running){
|
||||
Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
|
||||
parser.displayGameboard(game.getBoard().getTextView());
|
||||
parser.playerTurn(game.getCurrentPlayerFaction());
|
||||
parser.playerTurn(currentPlayerFaction);
|
||||
if(!diceThrown) {
|
||||
throwDice(game, parser);
|
||||
diceThrown = true;
|
||||
}
|
||||
parser.displayPlayerResourceStock(game.getCurruntPlayerResource());
|
||||
|
||||
parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinpoints());
|
||||
switch (parser.getAction()) {
|
||||
case NEXTPLAYER:
|
||||
Config.Faction winner = game.getWinner();
|
||||
|
@ -40,15 +35,21 @@ public class Siedler {
|
|||
break;
|
||||
case BUILDSETTLEMENT:
|
||||
parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
|
||||
game.buildSettlement(parser.getPoint());
|
||||
if(!game.buildSettlement(parser.getPoint())){
|
||||
parser.errorMessage();
|
||||
}
|
||||
break;
|
||||
case BUILDCITY:
|
||||
parser.giveCoordinatesForStructures(Config.Structure.CITY);
|
||||
game.buildCity(parser.getPoint());
|
||||
if(!game.buildCity(parser.getPoint())){
|
||||
parser.errorMessage();
|
||||
}
|
||||
break;
|
||||
case BUILDROAD:
|
||||
parser.giveCoordinatesForStructures(Config.Structure.ROAD);
|
||||
game.buildRoad(parser.getPoint(), parser.getPoint());
|
||||
if(game.buildRoad(parser.getPoint(), parser.getPoint())){
|
||||
parser.errorMessage();
|
||||
}
|
||||
break;
|
||||
case TRADEWITHBANK:
|
||||
Config.Resource offer = parser.trade(true);
|
||||
|
@ -59,7 +60,7 @@ public class Siedler {
|
|||
break;
|
||||
case QUIT:
|
||||
running = false;
|
||||
//todo close window
|
||||
parser.quit();
|
||||
break;
|
||||
default:
|
||||
parser.errorMessage();
|
||||
|
@ -71,6 +72,7 @@ public class Siedler {
|
|||
Random random = new Random();
|
||||
//sum of two integers from 0-5 + 2 --> sum of two integers from 1-6
|
||||
int thrownDices = random.nextInt(6) + random.nextInt(6) + 2;
|
||||
//todo check if 7
|
||||
parser.thrownDices(thrownDices);
|
||||
game.throwDice(thrownDices);
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ public class SiedlerGame {
|
|||
return allPlayers.get(activePlayer).getSpecificResource(resource);
|
||||
}
|
||||
|
||||
public HashMap<Resource, Integer> getCurruntPlayerResource() {
|
||||
public HashMap<Resource, Integer> getCurrentPlayerResource() {
|
||||
return allPlayers.get(activePlayer).getResources();
|
||||
}
|
||||
|
||||
|
@ -329,17 +329,14 @@ public class SiedlerGame {
|
|||
* @return the winner of the game or null, if there is no winner (yet)
|
||||
*/
|
||||
public Faction getWinner() {
|
||||
HashMap<Faction, Integer> winPoints = getWinPoints();
|
||||
for(Faction faction : winPoints.keySet()){
|
||||
if(winPoints.get(faction) >= winPointsForWin){
|
||||
return faction;
|
||||
}
|
||||
if(getCurrentPlayerWinpoints() >= winPointsForWin){
|
||||
return getCurrentPlayerFaction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private HashMap<Faction, Integer> getWinPoints(){
|
||||
HashMap<Faction, Integer> winPoints = new HashMap<>();
|
||||
public int getCurrentPlayerWinpoints(){
|
||||
int winPoints = 0;
|
||||
List<Structure> structures = board.getCorners();
|
||||
for(Structure structure : structures) {
|
||||
|
||||
|
@ -349,15 +346,9 @@ public class SiedlerGame {
|
|||
} else if(structure instanceof Settlement) {
|
||||
newWinPoints = 1;
|
||||
}
|
||||
|
||||
Faction faction = structure.getFaction();
|
||||
if(winPoints.containsKey(faction)) {
|
||||
winPoints.put(faction, winPoints.get(faction) + newWinPoints);
|
||||
if(structure.getFaction() == getCurrentPlayerFaction()){
|
||||
winPoints ++;
|
||||
}
|
||||
else {
|
||||
winPoints.put(faction, newWinPoints);
|
||||
}
|
||||
|
||||
}
|
||||
//todo add points for longest road
|
||||
return winPoints;
|
||||
|
|
Loading…
Reference in New Issue