First business logic

main
selim 2024-04-28 05:00:29 +02:00
parent 03664b404c
commit 45878b8b7d
8 changed files with 411 additions and 6 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

276
src/domain/Box.java 100644
View File

@ -0,0 +1,276 @@
package domain;
import java.util.ArrayList;
import java.util.Arrays;
public class Box {
private int categoryOne;
private int categoryTwo;
private int categoryThree;
private int categoryFour;
private int categoryFive;
private int categorySix;
private int categorySeven;
private int categoryEight;
private Integer setCategoryOne;
private Integer setCategoryTwo;
private Integer setCategoryThree;
private Integer setCategoryFour;
private Integer setCategoryFive;
private Integer setCategorySix;
private Integer setCategorySeven;
private Integer setCategoryEight;
private int categoryTripleMatch;
private int categoryFourOfAKind;
private int categoryFullHouse;
private int categorySmallStreet;
private int categoryBigStreet;
private int categoryYahtzee;
private int categoryChance;
private int categoryR2D2;
private Integer setCategoryTripleMatch;
private Integer setCategoryFourOfAKind;
private Integer setCategoryFullHouse;
private Integer setCategorySmallStreet;
private Integer setCategoryBigStreet;
private Integer setCategoryYahtzee;
private Integer setCategoryChance;
private Integer setCategoryR2D2;
private int counter[] = new int[8];
public void evaluateUpperBoxOptions(ArrayList<Integer> diceNumbers) {
if (diceNumbers.contains(1))
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 1)
this.categoryOne += diceNumbers.get(i);
}
else if (diceNumbers.contains(2))
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 2)
this.categoryTwo += diceNumbers.get(i);
}
else if (diceNumbers.contains(3))
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 3)
this.categoryThree += diceNumbers.get(i);
}
else if (diceNumbers.contains(4))
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 4)
this.categoryFour += diceNumbers.get(i);
}
else if (diceNumbers.contains(5))
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 5)
this.categoryFive += diceNumbers.get(i);
}
else if (diceNumbers.contains(6))
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 6)
this.categorySix += diceNumbers.get(i);
}
else if (diceNumbers.contains(7))
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 7)
this.categorySeven += diceNumbers.get(i);
}
else if (diceNumbers.contains(8))
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 8)
this.categoryEight += diceNumbers.get(i);
}
}
public void evaluateLowerBoxOptions(ArrayList<Integer> diceNumbers) {
int sumOfAllNumbers = 0;
for (int i = 0; i < diceNumbers.size(); i++) {
if (diceNumbers.get(i) == 1)
counter[0]++;
else if (diceNumbers.get(i) == 2)
counter[1]++;
else if (diceNumbers.get(i) == 3)
counter[2]++;
else if (diceNumbers.get(i) == 4)
counter[3]++;
else if (diceNumbers.get(i) == 5)
counter[4]++;
else if (diceNumbers.get(i) == 6)
counter[5]++;
else if (diceNumbers.get(i) == 7)
counter[6]++;
else if (diceNumbers.get(i) == 8)
counter[7]++;
}
for (int i = 0; i < diceNumbers.size(); i++) {
sumOfAllNumbers += diceNumbers.get(i);
}
categoryChance = sumOfAllNumbers;
for (int i = 0; i < counter.length; i++) {
if (counter[i] >= 3)
categoryTripleMatch = sumOfAllNumbers;
if (counter[i] >= 4)
categoryFourOfAKind = sumOfAllNumbers;
if (counter[i] == 5) {
categoryYahtzee = 50;
}
for (int s = 0; s < counter.length; s++) {
if (counter[i] == 3 && counter[s] == 2)
categoryFullHouse = 25;
}
}
for (int i = 0; i < 6; i++) {
if (counter[i] == 1 && counter[i + 1] == 1 && counter[i + 2] == 1)
categorySmallStreet = 30;
}
for (int i = 0; i < 5; i++) {
if (counter[i] == 1 && counter[i + 1] == 1 && counter[i + 2] == 1 && counter[i + 3] == 1)
categoryBigStreet = 40;
}
if (counter[0] == 1 && counter[1] == 2 && counter[3] == 1 && counter[7] == 1)
categoryR2D2 = 42;
}
public void evaluateBoxOptions(ArrayList<Integer> diceNumbers) {
evaluateUpperBoxOptions(diceNumbers);
evaluateLowerBoxOptions(diceNumbers);
}
public ArrayList<String> giveAllOptions() {
ArrayList<String> res = new ArrayList<>();
if (categoryOne > 0 && (setCategoryOne == null))
res.add("categoryOne: " + categoryOne);
if (categoryTwo > 0 && (setCategoryTwo == null))
res.add("categoryTwo: " + categoryTwo);
if (categoryThree > 0 && (setCategoryThree == null))
res.add("categoryThree: " + categoryThree);
if (categoryFour > 0 && (setCategoryFour == null))
res.add("categoryFour: " + categoryFour);
if (categoryFive > 0 && (setCategoryFive == null))
res.add("categoryFive: " + categoryFive);
if (categorySix > 0 && (setCategorySix == null))
res.add("categorySix: " + categorySix);
if (categorySeven > 0 && (setCategorySeven == null))
res.add("categorySeven: " + categorySeven);
if (categoryEight > 0 && (setCategoryEight == null))
res.add("categoryEight: " + categoryEight);
if (categoryTripleMatch > 0 && (setCategoryTripleMatch == null))
res.add("categoryTrippleMatch: " + categoryTripleMatch);
if (categoryFourOfAKind > 0 && (setCategoryFourOfAKind == null))
res.add("categoryFourOfAKind: " + categoryFourOfAKind);
if (categoryFullHouse > 0 && (setCategoryFullHouse == null))
res.add("categoryFullHouse: " + categoryFullHouse);
if (categorySmallStreet > 0 && (setCategorySmallStreet == null))
res.add("categorySmallStreet: " + categorySmallStreet);
if (categoryBigStreet > 0 && (setCategoryBigStreet == null))
res.add("categoryBigStreet: " + categoryBigStreet);
if (categoryYahtzee > 0)
res.add("categoryYahtzee: " + categoryYahtzee);
if (categoryChance > 0 && (setCategoryChance == null))
res.add("categoryChance: " + categoryChance);
if (categoryR2D2 > 0 && (setCategoryR2D2 == null))
res.add("categoryR2D2: " + categoryR2D2);
if (res.isEmpty())
res.add("No options left");
return res;
}
public void selectOption(String option) {
if (option.equals("categoryOne"))
setCategoryOne = categoryOne;
else if (option.equals("categoryTwo"))
setCategoryTwo = categoryTwo;
else if (option.equals("categoryThree"))
setCategoryThree = categoryThree;
else if (option.equals("categoryFour"))
setCategoryFour = categoryFour;
else if (option.equals("categoryFive"))
setCategoryFive = categoryFive;
else if (option.equals("categorySix"))
setCategorySix = categorySix;
else if (option.equals("categorySeven"))
setCategorySeven = categorySeven;
else if (option.equals("categoryEight"))
setCategoryEight = categoryEight;
else if (option.equals("categoryTripleMatch"))
setCategoryTripleMatch = categoryTripleMatch;
else if (option.equals("categoryFourOfAKind"))
setCategoryFourOfAKind = categoryFourOfAKind;
else if (option.equals("categoryFullHouse"))
setCategoryFullHouse = categoryFullHouse;
else if (option.equals("categorySmallStreet"))
setCategorySmallStreet = categorySmallStreet;
else if (option.equals("categoryBigStreet"))
setCategoryBigStreet = categoryBigStreet;
else if (option.equals("categoryYahtzee")) {
if (setCategoryYahtzee > 0) {
setCategoryYahtzee += 50;
if (counter[0] == 5)
setCategoryOne = 5;
else if (counter[1] == 5)
setCategoryTwo = 10;
else if (counter[2] == 5)
setCategoryThree = 15;
else if (counter[3] == 5)
setCategoryFour = 20;
else if (counter[4] == 5)
setCategoryFive = 25;
else if (counter[5] == 5)
setCategorySix = 30;
else if (counter[6] == 5)
setCategorySeven = 35;
else if (counter[7] == 5)
setCategoryEight = 40;
} else
setCategoryYahtzee = categoryYahtzee;
} else if (option.equals("categoryChance"))
setCategoryChance = categoryChance;
else if (option.equals("categoryR2D2"))
setCategoryR2D2 = categoryR2D2;
}
public void resetOptions() {
categoryOne = categoryTwo = categoryThree = categoryFour = categoryFive = categorySix = categorySeven = categoryEight = categoryTripleMatch = categoryFourOfAKind = categoryFullHouse = categorySmallStreet = categoryBigStreet = categoryYahtzee = categoryChance = categoryR2D2 = 0;
Arrays.fill(counter, 0);
}
public int returnTotalPoints() {
return setCategoryOne + setCategoryTwo + setCategoryThree + setCategoryFour + setCategoryFive
+ setCategorySix + setCategorySeven + setCategoryEight + setCategoryTripleMatch + setCategoryFourOfAKind
+ setCategoryFullHouse + setCategorySmallStreet + setCategoryBigStreet + setCategoryYahtzee
+ setCategoryChance
+ setCategoryR2D2;
}
}

View File

@ -0,0 +1,36 @@
package domain;
public class Dice {
private int diceNumber;
private String savedGamemode;
public Dice(String gamemode) {
this.savedGamemode = gamemode;
if (gamemode.equals("Normal") || gamemode.equals("StarWarsDay"))
this.diceNumber = (int) Math.random() * 6 + 1;
else if (gamemode.equals("Special8"))
this.diceNumber = (int) Math.random() * 8 + 1;
}
public Dice(String gamemode, int diceNumber) {
this.savedGamemode = gamemode;
this.diceNumber = diceNumber;
}
public void rerollDice() {
if (this.savedGamemode.equals("Normal") || this.savedGamemode.equals("StarWarsDay"))
this.diceNumber = (int) Math.random() * 6 + 1;
else if (this.savedGamemode.equals("Special8"))
this.diceNumber = (int) Math.random() * 8 + 1;
}
public int getDiceNumber() {
return this.diceNumber;
}
}

View File

@ -0,0 +1,99 @@
package domain;
import java.util.ArrayList;
public class Hand {
private ArrayList<Dice> dices = new ArrayList<>(5);
private ArrayList<Dice> lockedInDices;
private int leftRolls = 2;
private String savedGamemode;
public Hand(String gamemode) {
this.savedGamemode = gamemode;
for (int i = 0; i < dices.size(); i++) {
dices.add(i, new Dice(gamemode));
}
}
public void lockInDice(int dice) {
for (int i = 0; i < this.dices.size(); i++) {
if (this.dices.get(i).getDiceNumber() == dice) {
this.dices.remove(i);
this.lockedInDices.add(new Dice(savedGamemode, dice));
}
}
}
public void lockInDices(int... dices) {
for (int i = 0; i < dices.length; i++) {
lockInDice(dices[i]);
}
}
public void rollDices() {
if (this.leftRolls > 0)
for (int i = 0; i < this.dices.size(); i++) {
this.dices.get(i).rerollDice();
}
leftRolls--;
}
public ArrayList<Integer> getAllDiceNumbers() {
ArrayList<Integer> res = new ArrayList<>();
for (int i = 0; i < this.dices.size(); i++) {
res.add(this.dices.get(i).getDiceNumber());
}
for (int i = 0; i < this.lockedInDices.size(); i++) {
res.add(this.lockedInDices.get(i).getDiceNumber());
}
return res;
}
public ArrayList<Integer> getFreeDiceNumbers() {
ArrayList<Integer> res = new ArrayList<>();
for (int i = 0; i < this.dices.size(); i++) {
res.add(this.dices.get(i).getDiceNumber());
}
return res;
}
public ArrayList<Integer> getLockedInDiceNumbers() {
ArrayList<Integer> res = new ArrayList<>();
for (int i = 0; i < this.lockedInDices.size(); i++) {
res.add(this.lockedInDices.get(i).getDiceNumber());
}
return res;
}
public int getLeftRolls() {
return this.leftRolls;
}
}

View File

@ -1,6 +0,0 @@
package domain;
public class YahtzeeSheet {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
}
}