From b07e0a0e02b987d67dc4d8e5f60c46f3ffcf6098 Mon Sep 17 00:00:00 2001 From: 3013050 <3013050@stud.hs-mannheim.de> Date: Tue, 7 May 2024 01:10:14 +0200 Subject: [PATCH] Finished starwars mode Now both gamemodes are implemented and completly playable. --- domain/Sheet.java | 9 +- domain/StarwarsSheet.java | 146 ++++++++++++++++++++++++++++++++- domain/sheets/R2D2.java | 6 +- domain/sheets/StarWarsDay.java | 24 +++++- fassade/KniffelSystem.java | 66 +++++++++++---- scores.csv | 3 + 6 files changed, 231 insertions(+), 23 deletions(-) diff --git a/domain/Sheet.java b/domain/Sheet.java index 7cfa83c..266f9a2 100644 --- a/domain/Sheet.java +++ b/domain/Sheet.java @@ -131,7 +131,7 @@ public class Sheet { } - private void manageArrays(boolean crossing, Category category){ + public void manageArrays(boolean crossing, Category category){ category.setCrossed(crossing); unusedRows.remove(category.toString()); @@ -152,7 +152,7 @@ public class Sheet { return upperScore + lowerScore; } - private int calcUpperHalf(){ + public int calcUpperHalf(){ int upperSum = 0; upperSum += aces.getValue(); upperSum += twos.getValue(); @@ -164,7 +164,8 @@ public class Sheet { return upperSum; } - private int calcLowerHalf(){ + + public int calcLowerHalf(){ int lowerSum = 0; lowerSum += threeOfKind.getValue(); lowerSum += fourOfKind.getValue(); @@ -177,7 +178,7 @@ public class Sheet { return lowerSum; } - private int calcUpperBonus(int upperSum){ + public int calcUpperBonus(int upperSum){ if (upperSum >= 63){ upperSum += 35; } diff --git a/domain/StarwarsSheet.java b/domain/StarwarsSheet.java index 04d6482..9d8f27d 100644 --- a/domain/StarwarsSheet.java +++ b/domain/StarwarsSheet.java @@ -2,6 +2,8 @@ package domain; import domain.sheets.*; +import java.util.HashMap; + public class StarwarsSheet extends Sheet{ //? Additional upper half 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 getAllCategories(){ + HashMap 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){ switch (categoryToWrite.toString()){ case "Sevens": @@ -46,7 +189,4 @@ public class StarwarsSheet extends Sheet{ break; } } - - - } diff --git a/domain/sheets/R2D2.java b/domain/sheets/R2D2.java index 97503b6..a8ab67b 100644 --- a/domain/sheets/R2D2.java +++ b/domain/sheets/R2D2.java @@ -1,5 +1,9 @@ package domain.sheets; public class R2D2 extends Category{ - //TODO + + @Override + public void independentValue() { + this.value = 42; + } } diff --git a/domain/sheets/StarWarsDay.java b/domain/sheets/StarWarsDay.java index 4f6fe33..2733608 100644 --- a/domain/sheets/StarWarsDay.java +++ b/domain/sheets/StarWarsDay.java @@ -1,6 +1,28 @@ package domain.sheets; +import java.util.ArrayList; + public class StarWarsDay extends Category{ - //TODO + @Override + public void calcValueFromRoll(ArrayList 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; + } } diff --git a/fassade/KniffelSystem.java b/fassade/KniffelSystem.java index eabcb55..03d1a63 100644 --- a/fassade/KniffelSystem.java +++ b/fassade/KniffelSystem.java @@ -3,6 +3,7 @@ package fassade; import domain.Game; import domain.Player; import domain.Sheet; +import domain.StarwarsSheet; import domain.sheets.Category; import java.io.*; @@ -167,6 +168,17 @@ public class KniffelSystem { possibleCombinations.get("Sixes").addAmount(); 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(); @@ -244,6 +256,29 @@ public class KniffelSystem { 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 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.calcValueFromRoll(rolls); @@ -315,6 +350,20 @@ public class KniffelSystem { } + private HashMap 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){ HashMap possibleCombinations = createCategoryHashMap(); @@ -334,11 +383,7 @@ public class KniffelSystem { } if (contains){ - if (getGamemode().equals("default")) { - currentPlayerSheet.writeCategory(categoryToWrite, false); - }else { - currentPlayerSheet.wr - } + currentPlayerSheet.writeCategory(categoryToWrite, false); }else { currentPlayerSheet.writeCategory(categoryToWrite, true); } @@ -378,7 +423,7 @@ public class KniffelSystem { int score = player.getScore(); 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(""); return; } - System.out.printf("Not empty |%s| \n", stringToEnter); + System.out.printf("Not empty |%s| \n", stringToEnter); //! TEST ArrayList currentRows = readFromFile(); @@ -431,13 +476,6 @@ public class KniffelSystem { } - private HashMap createCategoryHashMap(){ - // TODO starwars sheet implementieren - Sheet sheet = new Sheet(); - - return sheet.getAllCategories(); - } - private ArrayList createDevRoll(String keptDice){ // Format: dev(1,2,3,4,5) diff --git a/scores.csv b/scores.csv index e69de29..0dd2405 100644 --- a/scores.csv +++ b/scores.csv @@ -0,0 +1,3 @@ +Victor,1337,24.12.00 +Nastja,999,07.05.2024 +Luke,404,04.05.2024 \ No newline at end of file