Merge remote-tracking branch 'origin/main'

This commit is contained in:
Leonardo Brandenberger 2021-11-26 11:41:15 +01:00
commit 647fa90f30
24 changed files with 130 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/out/

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -15,15 +15,14 @@ public class Dummy {
SHOW, QUIT SHOW, QUIT
} }
private void run() { private void run() {
TextIO textIO = TextIoFactory.getTextIO(); TextIO textIO = TextIoFactory.getTextIO();
TextTerminal<?> textTerminal = textIO.getTextTerminal(); TextTerminal<?> textTerminal = textIO.getTextTerminal();
SiedlerBoard board = new SiedlerBoard(); SiedlerBoard board = new SiedlerBoard();
board.addField(new Point(2, 2), Land.FOREST); board.addField(new Point(2, 2), Land.FOREST);
board.setCorner(new Point(3, 3), "RR"); board.setCorner(new Point(3, 3), new Settlement(Config.Faction.RED));
board.setEdge(new Point(2, 0), new Point(3, 1), "r"); board.setEdge(new Point(2, 0), new Point(3, 1), new Road(Config.Faction.BLUE));
board.addFieldAnnotation(new Point(2, 2), new Point(3, 1), "AA"); board.addFieldAnnotation(new Point(2, 2), new Point(3, 1), "AA");
Map<Point, Label> lowerFieldLabel = new HashMap<>(); Map<Point, Label> lowerFieldLabel = new HashMap<>();

View File

@ -0,0 +1,61 @@
package ch.zhaw.catan;
import java.util.HashMap;
/**
* New Class PLayer
* This class is here to add players to the game.
* @author: Stefan Amador
*/
public class Player {
private String name;
private Config.Faction faction;
private HashMap<Config.Resource,Integer> resources;
private int roadsToUse;
private int settlementsToUse;
public Player (String name, Config.Faction faction){
//Datenfelder
this.name = name;
this.faction = faction;
roadsToUse = Config.Structure.ROAD.getStockPerPlayer();
settlementsToUse = Config.Structure.SETTLEMENT.getStockPerPlayer();
//Ressourcen initialisiern
resources = new HashMap<>();
for(Config.Resource resource : Config.Resource.values()) {
resources.put(resource,0);
}
}
/**
* This method returns all the resources the player has at the moment
* @return HashMap
*/
public HashMap<Config.Resource,Integer> getResources() {
return resources;
}
public boolean buildRoad() {
if (roadsToUse > 0) {
roadsToUse--;
return true;
}
return false;
}
public boolean buildSettlement() {
if (settlementsToUse > 0) {
settlementsToUse--;
return true;
}
return false;
}
}

View File

@ -0,0 +1,19 @@
package ch.zhaw.catan;
import java.util.HashMap;
public class Road {
private HashMap<Config.Resource,Integer> buildCost;
private Config.Faction faction;
public Road(Config.Faction faction) {
this.faction = faction;
buildCost = new HashMap<>();
buildCost.put(Config.Resource.BRICK,1);
buildCost.put(Config.Resource.LUMBER,1);
}
public HashMap<Config.Resource,Integer> getBuildCost() {
return buildCost;
}
}

View File

@ -0,0 +1,22 @@
package ch.zhaw.catan;
import java.util.HashMap;
public class Settlement {
private HashMap<Config.Resource,Integer> buildCost;
private Config.Faction faction;
public Settlement(Config.Faction faction) {
this.faction = faction;
buildCost = new HashMap<>();
buildCost.put(Config.Resource.LUMBER,1);
buildCost.put(Config.Resource.BRICK,1);
buildCost.put(Config.Resource.GRAIN,1);
buildCost.put(Config.Resource.WOOL,1);
}
public HashMap<Config.Resource,Integer> getBuildCost() {
return buildCost;
}
}

View File

@ -16,5 +16,7 @@ public class Siedler {
TextTerminal<?> textTerminal = textIO.getTextTerminal(); TextTerminal<?> textTerminal = textIO.getTextTerminal();
textTerminal.println(game.getBoard().getTextView()); textTerminal.println(game.getBoard().getTextView());
} }
} }

View File

@ -8,7 +8,7 @@ import java.awt.*;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
public class SiedlerBoard extends HexBoard<Land, String, String, String> { public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
Map<Point, ch.zhaw.hexboard.Label> lowerFieldLabel = new HashMap<>(); Map<Point, ch.zhaw.hexboard.Label> lowerFieldLabel = new HashMap<>();

View File

@ -24,7 +24,9 @@ public class SiedlerGame {
static final int FOUR_TO_ONE_TRADE_OFFER = 4; static final int FOUR_TO_ONE_TRADE_OFFER = 4;
static final int FOUR_TO_ONE_TRADE_WANT = 1; static final int FOUR_TO_ONE_TRADE_WANT = 1;
SiedlerBoard board; private SiedlerBoard board;
private Player[] allPlayers;
private int winPoints;
/** /**
* Constructs a SiedlerGame game state object. * Constructs a SiedlerGame game state object.
@ -38,6 +40,8 @@ public class SiedlerGame {
public SiedlerGame(int winPoints, int numberOfPlayers) { public SiedlerGame(int winPoints, int numberOfPlayers) {
board = new SiedlerBoard(); board = new SiedlerBoard();
board.createFixGamefield(); board.createFixGamefield();
allPlayers = new Player[numberOfPlayers];
this.winPoints = winPoints;
} }
/** /**
@ -69,6 +73,9 @@ public class SiedlerGame {
*/ */
public List<Faction> getPlayerFactions() { public List<Faction> getPlayerFactions() {
// TODO: Implement // TODO: Implement
Faction[] factions = new Faction[allPlayers.length];
return Collections.emptyList(); return Collections.emptyList();
} }
@ -212,7 +219,18 @@ public class SiedlerGame {
* @return true, if the placement was successful * @return true, if the placement was successful
*/ */
public boolean buildRoad(Point roadStart, Point roadEnd) { public boolean buildRoad(Point roadStart, Point roadEnd) {
// TODO: Implement //1. Check if Edge
if(!board.hasEdge(roadStart,roadEnd)){
// TODO: Error message
}
//2. Check if Edge is empty
if(board.getEdge(roadStart,roadEnd) != null) {
// TODO: Error message
}
//3. Can Player build road
// TODO
return false; return false;
} }

View File

@ -98,7 +98,7 @@ import java.util.Map;
public class HexBoardTextView<F, C, E, A> { public class HexBoardTextView<F, C, E, A> {
private static final String ONE_SPACE = " "; private static final String ONE_SPACE = " ";
private static final String TWO_SPACES = " "; private static final String TWO_SPACES = " ";
private static final String FOUR_SPACES = " "; private static final String FOUR_SPACES = " ";
private static final String FIVE_SPACES = " "; private static final String FIVE_SPACES = " ";
private static final String SIX_SPACES = " "; private static final String SIX_SPACES = " ";