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

View File

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

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -0,0 +1,8 @@
package ch.zhaw.catan;
public class City extends Structure {
public City(Config.Faction faction) {
super(faction);
}
}

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 {
}
}

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<>();

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);

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

View File

@ -10,4 +10,8 @@ public abstract class Structure {
public String toString() {
return faction.toString();
}
public Config.Faction getFaction() {
return faction;
}
}