Finished starwars mode
Now both gamemodes are implemented and completly playable.main
parent
9d5f8858e0
commit
b07e0a0e02
|
@ -131,7 +131,7 @@ public class Sheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void manageArrays(boolean crossing, Category category){
|
public void manageArrays(boolean crossing, Category category){
|
||||||
category.setCrossed(crossing);
|
category.setCrossed(crossing);
|
||||||
unusedRows.remove(category.toString());
|
unusedRows.remove(category.toString());
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class Sheet {
|
||||||
return upperScore + lowerScore;
|
return upperScore + lowerScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calcUpperHalf(){
|
public int calcUpperHalf(){
|
||||||
int upperSum = 0;
|
int upperSum = 0;
|
||||||
upperSum += aces.getValue();
|
upperSum += aces.getValue();
|
||||||
upperSum += twos.getValue();
|
upperSum += twos.getValue();
|
||||||
|
@ -164,7 +164,8 @@ public class Sheet {
|
||||||
return upperSum;
|
return upperSum;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calcLowerHalf(){
|
|
||||||
|
public int calcLowerHalf(){
|
||||||
int lowerSum = 0;
|
int lowerSum = 0;
|
||||||
lowerSum += threeOfKind.getValue();
|
lowerSum += threeOfKind.getValue();
|
||||||
lowerSum += fourOfKind.getValue();
|
lowerSum += fourOfKind.getValue();
|
||||||
|
@ -177,7 +178,7 @@ public class Sheet {
|
||||||
return lowerSum;
|
return lowerSum;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calcUpperBonus(int upperSum){
|
public int calcUpperBonus(int upperSum){
|
||||||
if (upperSum >= 63){
|
if (upperSum >= 63){
|
||||||
upperSum += 35;
|
upperSum += 35;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package domain;
|
||||||
|
|
||||||
import domain.sheets.*;
|
import domain.sheets.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class StarwarsSheet extends Sheet{
|
public class StarwarsSheet extends Sheet{
|
||||||
//? Additional upper half
|
//? Additional upper half
|
||||||
Sevens sevens;
|
Sevens sevens;
|
||||||
|
@ -27,6 +29,147 @@ public class StarwarsSheet extends Sheet{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void writeCategory(Category categoryToWrite, boolean crossing){
|
||||||
|
switch (categoryToWrite.toString()){
|
||||||
|
case "Aces":
|
||||||
|
aces = (Aces) categoryToWrite;
|
||||||
|
manageArrays(crossing, aces);
|
||||||
|
break;
|
||||||
|
case "Twos":
|
||||||
|
twos = (Twos) categoryToWrite;
|
||||||
|
manageArrays(crossing, twos);
|
||||||
|
break;
|
||||||
|
case "Threes":
|
||||||
|
threes = (Threes) categoryToWrite;
|
||||||
|
manageArrays(crossing, threes);
|
||||||
|
break;
|
||||||
|
case "Fours":
|
||||||
|
fours = (Fours) categoryToWrite;
|
||||||
|
manageArrays(crossing, fours);
|
||||||
|
break;
|
||||||
|
case "Fives":
|
||||||
|
fives = (Fives) categoryToWrite;
|
||||||
|
manageArrays(crossing, fives);
|
||||||
|
break;
|
||||||
|
case "Sixes":
|
||||||
|
sixes = (Sixes) categoryToWrite;
|
||||||
|
manageArrays(crossing, sixes);
|
||||||
|
break;
|
||||||
|
case "Sevens":
|
||||||
|
sevens = (Sevens) categoryToWrite;
|
||||||
|
manageArrays(crossing, sevens);
|
||||||
|
break;
|
||||||
|
case "Eights":
|
||||||
|
eights = (Eights) categoryToWrite;
|
||||||
|
manageArrays(crossing, eights);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "ThreeOfKind":
|
||||||
|
threeOfKind = (ThreeOfKind) categoryToWrite;
|
||||||
|
manageArrays(crossing, threeOfKind);
|
||||||
|
break;
|
||||||
|
case "FourOfKind":
|
||||||
|
fourOfKind = (FourOfKind) categoryToWrite;
|
||||||
|
manageArrays(crossing, fourOfKind);
|
||||||
|
break;
|
||||||
|
case "FullHouse":
|
||||||
|
fullHouse = (FullHouse) categoryToWrite;
|
||||||
|
manageArrays(crossing, fullHouse);
|
||||||
|
break;
|
||||||
|
case "SmallStraight":
|
||||||
|
smallStraight = (SmallStraight) categoryToWrite;
|
||||||
|
manageArrays(crossing, smallStraight);
|
||||||
|
break;
|
||||||
|
case "LargeStraight":
|
||||||
|
largeStraight = (LargeStraight) categoryToWrite;
|
||||||
|
manageArrays(crossing, largeStraight);
|
||||||
|
break;
|
||||||
|
case "StarWarsDay":
|
||||||
|
starWarsDay = (StarWarsDay) categoryToWrite;
|
||||||
|
manageArrays(crossing, starWarsDay);
|
||||||
|
break;
|
||||||
|
case "R2D2":
|
||||||
|
r2D2 = (R2D2) categoryToWrite;
|
||||||
|
manageArrays(crossing, r2D2);
|
||||||
|
break;
|
||||||
|
case "Yahtzee":
|
||||||
|
yahtzee = (Yahtzee) categoryToWrite;
|
||||||
|
manageArrays(crossing, yahtzee);
|
||||||
|
break;
|
||||||
|
case "Chance":
|
||||||
|
chance = (Chance) categoryToWrite;
|
||||||
|
manageArrays(crossing, chance);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int calcUpperHalf(){
|
||||||
|
int upperSum = 0;
|
||||||
|
upperSum += aces.getValue();
|
||||||
|
upperSum += twos.getValue();
|
||||||
|
upperSum += threes.getValue();
|
||||||
|
upperSum += fours.getValue();
|
||||||
|
upperSum += fives.getValue();
|
||||||
|
upperSum += sixes.getValue();
|
||||||
|
upperSum += sevens.getValue();
|
||||||
|
upperSum += eights.getValue();
|
||||||
|
|
||||||
|
return upperSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int calcLowerHalf(){
|
||||||
|
int lowerSum = 0;
|
||||||
|
lowerSum += threeOfKind.getValue();
|
||||||
|
lowerSum += fourOfKind.getValue();
|
||||||
|
lowerSum += fullHouse.getValue();
|
||||||
|
lowerSum += smallStraight.getValue();
|
||||||
|
lowerSum += largeStraight.getValue();
|
||||||
|
lowerSum += yahtzee.getValue();
|
||||||
|
lowerSum += starWarsDay.getValue();
|
||||||
|
lowerSum += r2D2.getValue();
|
||||||
|
lowerSum += chance.getValue();
|
||||||
|
|
||||||
|
return lowerSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int calcUpperBonus(int upperSum){
|
||||||
|
if (upperSum >= 108){
|
||||||
|
upperSum += 35;
|
||||||
|
}
|
||||||
|
return upperSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public HashMap<String, Category> getAllCategories(){
|
||||||
|
HashMap<String, Category> allCategories = new HashMap<>();
|
||||||
|
|
||||||
|
allCategories.put("Aces", aces);
|
||||||
|
allCategories.put("Twos", twos);
|
||||||
|
allCategories.put("Threes", threes);
|
||||||
|
allCategories.put("Fours", fours);
|
||||||
|
allCategories.put("Fives", fives);
|
||||||
|
allCategories.put("Sixes", sixes);
|
||||||
|
allCategories.put("Sevens", sevens);
|
||||||
|
allCategories.put("Eights", eights);
|
||||||
|
|
||||||
|
allCategories.put("ThreeOfKind", threeOfKind);
|
||||||
|
allCategories.put("FourOfKind", fourOfKind);
|
||||||
|
allCategories.put("FullHouse", fullHouse);
|
||||||
|
allCategories.put("SmallStraight", smallStraight);
|
||||||
|
allCategories.put("LargeStraight", largeStraight);
|
||||||
|
allCategories.put("StarWarsDay", starWarsDay);
|
||||||
|
allCategories.put("R2D2", r2D2);
|
||||||
|
allCategories.put("Yahtzee", yahtzee);
|
||||||
|
allCategories.put("Chance", chance);
|
||||||
|
|
||||||
|
return allCategories;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//? :/
|
||||||
public void writeStarwarsCategory(Category categoryToWrite, boolean crossing){
|
public void writeStarwarsCategory(Category categoryToWrite, boolean crossing){
|
||||||
switch (categoryToWrite.toString()){
|
switch (categoryToWrite.toString()){
|
||||||
case "Sevens":
|
case "Sevens":
|
||||||
|
@ -46,7 +189,4 @@ public class StarwarsSheet extends Sheet{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package domain.sheets;
|
package domain.sheets;
|
||||||
|
|
||||||
public class R2D2 extends Category{
|
public class R2D2 extends Category{
|
||||||
//TODO
|
|
||||||
|
@Override
|
||||||
|
public void independentValue() {
|
||||||
|
this.value = 42;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,28 @@
|
||||||
package domain.sheets;
|
package domain.sheets;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class StarWarsDay extends Category{
|
public class StarWarsDay extends Category{
|
||||||
|
|
||||||
//TODO
|
@Override
|
||||||
|
public void calcValueFromRoll(ArrayList<Integer> rolls) {
|
||||||
|
int amountFours = 0;
|
||||||
|
int amountFives = 0;
|
||||||
|
|
||||||
|
for (int roll : rolls){
|
||||||
|
if (roll == 4){
|
||||||
|
amountFours ++;
|
||||||
|
}
|
||||||
|
if (roll == 5){
|
||||||
|
amountFives++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int sum = 0;
|
||||||
|
|
||||||
|
sum += (amountFours) * 4;
|
||||||
|
sum += (amountFives) * 5;
|
||||||
|
|
||||||
|
this.value = sum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package fassade;
|
||||||
import domain.Game;
|
import domain.Game;
|
||||||
import domain.Player;
|
import domain.Player;
|
||||||
import domain.Sheet;
|
import domain.Sheet;
|
||||||
|
import domain.StarwarsSheet;
|
||||||
import domain.sheets.Category;
|
import domain.sheets.Category;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -167,6 +168,17 @@ public class KniffelSystem {
|
||||||
possibleCombinations.get("Sixes").addAmount();
|
possibleCombinations.get("Sixes").addAmount();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (getGamemode().equals("default")){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
switch (dice){
|
||||||
|
case 7:
|
||||||
|
possibleCombinations.get("Sevens").addAmount();
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
possibleCombinations.get("Eights").addAmount();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@ -244,6 +256,29 @@ public class KniffelSystem {
|
||||||
index ++;
|
index ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//? StarWars
|
||||||
|
if (getGamemode().equals("starwars")){
|
||||||
|
|
||||||
|
//? StarWarsDay
|
||||||
|
if ((rolls.contains(4)) && rolls.contains(5)){
|
||||||
|
keyObj = possibleCombinations.get("StarWarsDay");
|
||||||
|
|
||||||
|
keyObj.calcValueFromRoll(rolls);
|
||||||
|
addCombinationToStringbuilder(sb, keyObj, allValidCombinations);
|
||||||
|
}
|
||||||
|
|
||||||
|
//? R2D2
|
||||||
|
ArrayList<Integer> r2d2Array = new ArrayList<>(Arrays.asList(1, 8, 2, 4, 2));
|
||||||
|
if(rolls.equals(r2d2Array)){
|
||||||
|
keyObj = possibleCombinations.get("R2D2");
|
||||||
|
|
||||||
|
keyObj.independentValue();
|
||||||
|
addCombinationToStringbuilder(sb, keyObj, allValidCombinations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//? Chance
|
||||||
keyObj = possibleCombinations.get("Chance");
|
keyObj = possibleCombinations.get("Chance");
|
||||||
|
|
||||||
keyObj.calcValueFromRoll(rolls);
|
keyObj.calcValueFromRoll(rolls);
|
||||||
|
@ -315,6 +350,20 @@ public class KniffelSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private HashMap<String, Category> createCategoryHashMap(){
|
||||||
|
String gamemode = getGamemode();
|
||||||
|
Sheet sheet;
|
||||||
|
if (gamemode.equals("default")){
|
||||||
|
sheet = new Sheet();
|
||||||
|
} else {
|
||||||
|
sheet = new StarwarsSheet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return sheet.getAllCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void writeToSheet(String sheetInput){
|
public void writeToSheet(String sheetInput){
|
||||||
HashMap<String, Category> possibleCombinations = createCategoryHashMap();
|
HashMap<String, Category> possibleCombinations = createCategoryHashMap();
|
||||||
|
|
||||||
|
@ -334,11 +383,7 @@ public class KniffelSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contains){
|
if (contains){
|
||||||
if (getGamemode().equals("default")) {
|
|
||||||
currentPlayerSheet.writeCategory(categoryToWrite, false);
|
currentPlayerSheet.writeCategory(categoryToWrite, false);
|
||||||
}else {
|
|
||||||
currentPlayerSheet.wr
|
|
||||||
}
|
|
||||||
}else {
|
}else {
|
||||||
currentPlayerSheet.writeCategory(categoryToWrite, true);
|
currentPlayerSheet.writeCategory(categoryToWrite, true);
|
||||||
}
|
}
|
||||||
|
@ -378,7 +423,7 @@ public class KniffelSystem {
|
||||||
int score = player.getScore();
|
int score = player.getScore();
|
||||||
String name = player.getName();
|
String name = player.getName();
|
||||||
|
|
||||||
return String.format("%d - %s - %s \n", score, name, date);
|
return String.format("%s,%d,%s",name, score, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -407,7 +452,7 @@ public class KniffelSystem {
|
||||||
writer.write("");
|
writer.write("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.printf("Not empty |%s| \n", stringToEnter);
|
System.out.printf("Not empty |%s| \n", stringToEnter); //! TEST
|
||||||
|
|
||||||
ArrayList<String> currentRows = readFromFile();
|
ArrayList<String> currentRows = readFromFile();
|
||||||
|
|
||||||
|
@ -431,13 +476,6 @@ public class KniffelSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private HashMap<String, Category> createCategoryHashMap(){
|
|
||||||
// TODO starwars sheet implementieren
|
|
||||||
Sheet sheet = new Sheet();
|
|
||||||
|
|
||||||
return sheet.getAllCategories();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private ArrayList<Integer> createDevRoll(String keptDice){
|
private ArrayList<Integer> createDevRoll(String keptDice){
|
||||||
// Format: dev(1,2,3,4,5)
|
// Format: dev(1,2,3,4,5)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Victor,1337,24.12.00
|
||||||
|
Nastja,999,07.05.2024
|
||||||
|
Luke,404,04.05.2024
|
|
Loading…
Reference in New Issue