implemented Method getWinner and getWinPoints

added Class City for later use.
This commit is contained in:
schrom01
2021-11-30 20:20:48 +01:00
parent 54b1d794f8
commit 3830cf6594
8 changed files with 64 additions and 10 deletions
+8
View File
@@ -0,0 +1,8 @@
package ch.zhaw.catan;
public class City extends Structure {
public City(Config.Faction faction) {
super(faction);
}
}
+6 -1
View File
@@ -4,12 +4,14 @@ import org.beryx.textio.TextIO;
import org.beryx.textio.TextIoFactory;
import org.beryx.textio.TextTerminal;
import java.awt.*;
public class Siedler {
public static void main(String[] args) {
//Spiel erstellen
SiedlerGame game = new SiedlerGame(0, 0);
SiedlerGame game = new SiedlerGame(3, 2);
//Spielfeld ausgeben
TextIO textIO = TextIoFactory.getTextIO();
@@ -18,5 +20,8 @@ public class Siedler {
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ import java.awt.*;
import java.util.*;
import java.util.List;
public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
public class SiedlerBoard extends HexBoard<Land, Structure, Road, String> {
Map<Point, ch.zhaw.hexboard.Label> lowerFieldLabel = new HashMap<>();
+1 -1
View File
@@ -6,7 +6,7 @@ import ch.zhaw.hexboard.Label;
import java.awt.*;
public class SiedlerBoardTextView extends HexBoardTextView<Land, Settlement, Road, String> {
public class SiedlerBoardTextView extends HexBoardTextView<Land, Structure, Road, String> {
public SiedlerBoardTextView(SiedlerBoard board) {
super(board);
+33 -6
View File
@@ -7,10 +7,7 @@ import org.beryx.textio.TextIoFactory;
import org.beryx.textio.TextTerminal;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
@@ -26,7 +23,7 @@ public class SiedlerGame {
private SiedlerBoard board;
private ArrayList<Player> allPlayers;
private int winPoints;
private int winPointsForWin;
private Bank bank;
private int activePlayer;
@@ -48,7 +45,7 @@ public class SiedlerGame {
allPlayers = new ArrayList<>();
createPlayer(numberOfPlayers);
activePlayer = 0;
this.winPoints = winPoints;
this.winPointsForWin = winPoints;
}
private void createPlayer(int numberOfPlayers) {
@@ -292,9 +289,39 @@ public class SiedlerGame {
*/
public Faction getWinner() {
// TODO: Implement
HashMap<Faction, Integer> winPoints = getWinPoints();
for(Faction faction : winPoints.keySet()){
if(winPoints.get(faction) >= winPointsForWin){
return faction;
}
}
return null;
}
private HashMap<Faction, Integer> getWinPoints(){
HashMap<Faction, Integer> winPoints = new HashMap<>();
List<Structure> structures = board.getCorners();
for(Structure structure : structures) {
int newWinPoints = 0;
if(structure instanceof Settlement){
newWinPoints = 1;
} else if(structure instanceof City) {
newWinPoints = 2;
}
Faction faction = structure.getFaction();
if(winPoints.containsKey(faction)) {
winPoints.put(faction, winPoints.get(faction) + newWinPoints);
}
else {
winPoints.put(faction, newWinPoints);
}
}
return winPoints;
}
/**
* Places the thief on the specified field and steals a random resource card (if
+4
View File
@@ -10,4 +10,8 @@ public abstract class Structure {
public String toString() {
return faction.toString();
}
public Config.Faction getFaction() {
return faction;
}
}