package domain; import domain.sheets.*; import java.util.ArrayList; import java.util.HashMap; public class Sheet { int amountTurns; ArrayList unusedRows = new ArrayList<>(); ArrayList usedRows = new ArrayList<>(); ArrayList crossedRows = new ArrayList<>(); //? Sheet rows, upper half Aces aces; Twos twos; Threes threes; Fours fours; Fives fives; Sixes sixes; //? Sheet rows, lower half ThreeOfKind threeOfKind; FourOfKind fourOfKind; FullHouse fullHouse; SmallStraight smallStraight; LargeStraight largeStraight; Yahtzee yahtzee; Chance chance; public Sheet(){ this.aces = new Aces(); unusedRows.add(this.aces.toString()); this.twos = new Twos(); unusedRows.add(this.twos.toString()); this.threes = new Threes(); unusedRows.add(this.threes.toString()); this.fours = new Fours(); unusedRows.add(this.fours.toString()); this.fives = new Fives(); unusedRows.add(this.fives.toString()); this.sixes = new Sixes(); unusedRows.add(this.sixes.toString()); this.threeOfKind = new ThreeOfKind(); unusedRows.add(this.threeOfKind.toString()); this.fourOfKind = new FourOfKind(); unusedRows.add(this.fourOfKind.toString()); this.fullHouse = new FullHouse(); unusedRows.add(this.fullHouse.toString()); this.smallStraight = new SmallStraight(); unusedRows.add(this.smallStraight.toString()); this.largeStraight = new LargeStraight(); unusedRows.add(this.largeStraight.toString()); this.yahtzee = new Yahtzee(); unusedRows.add(this.yahtzee.toString()); this.chance = new Chance(); unusedRows.add(this.chance.toString()); amountTurns = unusedRows.size(); } 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 "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 "Yahtzee": yahtzee = (Yahtzee) categoryToWrite; manageArrays(crossing, yahtzee); break; case "Chance": chance = (Chance) categoryToWrite; manageArrays(crossing, chance); break; } } public void manageArrays(boolean crossing, Category category){ category.setCrossed(crossing); unusedRows.remove(category.toString()); if (crossing){ crossedRows.add(category.toString()); } else { usedRows.add(category.toString()); } } public int calcSheet(){ int upperSum = calcUpperHalf(); int upperScore = calcUpperBonus(upperSum); int lowerScore = calcLowerHalf(); return upperScore + lowerScore; } public int calcUpperHalf(){ int upperSum = 0; upperSum += aces.getValue(); upperSum += twos.getValue(); upperSum += threes.getValue(); upperSum += fours.getValue(); upperSum += fives.getValue(); upperSum += sixes.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 += chance.getValue(); return lowerSum; } public int calcUpperBonus(int upperSum){ if (upperSum >= 63){ upperSum += 35; } return upperSum; } public boolean checkGameEnd(){ return (usedRows.size() + crossedRows.size()) == amountTurns; } public ArrayList getCrossedRows(){ return crossedRows; } public ArrayList getUnusedRows(){ return unusedRows; } public ArrayList getUsedRows(){ return usedRows; } 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("ThreeOfKind", threeOfKind); allCategories.put("FourOfKind", fourOfKind); allCategories.put("FullHouse", fullHouse); allCategories.put("SmallStraight", smallStraight); allCategories.put("LargeStraight", largeStraight); allCategories.put("Yahtzee", yahtzee); allCategories.put("Chance", chance); return allCategories; } }