Kniffel/domain/Sheet.java

187 lines
5.4 KiB
Java

package domain;
import domain.sheets.*;
import java.util.ArrayList;
import java.util.HashMap;
public class Sheet {
int amountTurns;
ArrayList<String> unusedRows = new ArrayList<>();
ArrayList<String> usedRows = new ArrayList<>();
ArrayList<String> crossedRows = new ArrayList<>();
// Sheet rows, first half
Aces aces;
Twos twos;
Threes threes;
Fours fours;
Fives fives;
Sixes sixes;
// Sheet rows, second 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;
}
}
private 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 boolean checkGameEnd(){
return (usedRows.size() + crossedRows.size()) == amountTurns;
}
public ArrayList<String> getCrossedRows(){
return crossedRows;
}
public ArrayList<String> getUnusedRows(){
return unusedRows;
}
public ArrayList<String> getUsedRows(){
return usedRows;
}
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("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;
}
}