Added evaluation for the upper block half
Added automatic value calculation when setting or adding the amount of a Category object. Added value calculation for the upper half of the block categories.main
parent
b7731de0b2
commit
495306ecb5
|
@ -12,7 +12,7 @@ public class Game {
|
|||
public Game(){
|
||||
currentPlayers = new ArrayList<Player>();
|
||||
turnPlayer = 0;
|
||||
dice = new Dice(8);
|
||||
dice = new Dice(6);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
package domain;
|
||||
|
||||
import domain.sheets.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Sheet {
|
||||
private String[] usedRows;
|
||||
private String[] canceledRows;
|
||||
private String[] emptyRows;
|
||||
|
||||
// Sheet rows, first half
|
||||
int aces;
|
||||
int twos;
|
||||
int threes;
|
||||
int fours;
|
||||
int fives;
|
||||
int sixes;
|
||||
Aces aces;
|
||||
Twos twos;
|
||||
Threes threes;
|
||||
Fours fours;
|
||||
Fives fives;
|
||||
Sixes sixes;
|
||||
|
||||
// Sheet rows, second half
|
||||
int three_of_kind;
|
||||
|
@ -20,4 +24,28 @@ public class Sheet {
|
|||
int small_straight;
|
||||
int large_straight;
|
||||
int chance;
|
||||
|
||||
|
||||
public Sheet(){
|
||||
this.aces = new Aces();
|
||||
this.twos = new Twos();
|
||||
this.threes = new Threes();
|
||||
this.fours = new Fours();
|
||||
this.fives = new Fives();
|
||||
this.sixes = new Sixes();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
return allCategories;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package domain.sheets;
|
||||
|
||||
public class Aces extends Category {
|
||||
|
||||
@Override
|
||||
public int calcValueFromAmount() {
|
||||
this.value = this.amount;
|
||||
return this.value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package domain.sheets;
|
||||
|
||||
public class Category {
|
||||
int amount = 0;
|
||||
int value = 0;
|
||||
boolean crossed = false;
|
||||
|
||||
|
||||
public int calcValueFromAmount(){
|
||||
return amount;
|
||||
}
|
||||
|
||||
|
||||
//? Amount
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
public Category setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
this.value = calcValueFromAmount();
|
||||
return this;
|
||||
}
|
||||
public void addAmount(){
|
||||
setAmount(this.amount + 1);
|
||||
}
|
||||
|
||||
|
||||
//? Value
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
public Category setValue(int value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
//? Crossed
|
||||
public boolean getCrossed() {
|
||||
return crossed;
|
||||
}
|
||||
public Category setCrossed(boolean crossed) {
|
||||
this.crossed = crossed;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s", this.getClass().getSimpleName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package domain.sheets;
|
||||
|
||||
public class Fives extends Category {
|
||||
|
||||
@Override
|
||||
public int calcValueFromAmount() {
|
||||
this.value = this.amount * 5;
|
||||
return this.value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package domain.sheets;
|
||||
|
||||
public class Fours extends Category {
|
||||
|
||||
@Override
|
||||
public int calcValueFromAmount() {
|
||||
this.value = this.amount * 4;
|
||||
return this.value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package domain.sheets;
|
||||
|
||||
public class Sixes extends Category {
|
||||
|
||||
@Override
|
||||
public int calcValueFromAmount() {
|
||||
this.value = this.amount * 6;
|
||||
return this.value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package domain.sheets;
|
||||
|
||||
public class Three_of_kind extends Category {
|
||||
@Override
|
||||
public int calcValueFromAmount() {
|
||||
this.value = this.amount * 2;
|
||||
return this.value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package domain.sheets;
|
||||
|
||||
public class Threes extends Category {
|
||||
|
||||
@Override
|
||||
public int calcValueFromAmount() {
|
||||
this.value = this.amount * 3;
|
||||
return this.value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package domain.sheets;
|
||||
|
||||
public class Twos extends Category {
|
||||
|
||||
@Override
|
||||
public int calcValueFromAmount() {
|
||||
this.value = this.amount * 2;
|
||||
return this.value;
|
||||
}
|
||||
}
|
|
@ -73,6 +73,11 @@ public class KniffelSystem {
|
|||
|
||||
|
||||
public ArrayList<Integer> rollDices(ArrayList<Integer> rolls, String keptDice){
|
||||
//? DEV TEST
|
||||
if (keptDice.startsWith("dev")){
|
||||
return createDevRoll(keptDice);
|
||||
}
|
||||
|
||||
ArrayList<Integer> oldRolls = extractKeptDice(rolls, keptDice);
|
||||
|
||||
int amountNewRolls = oldRolls.size();
|
||||
|
@ -104,6 +109,9 @@ public class KniffelSystem {
|
|||
return keptRolls;
|
||||
}
|
||||
|
||||
//? Remove whitespaces
|
||||
keptDice = keptDice.replaceAll("\\s+","");
|
||||
|
||||
if (keptDice.length() == 1){
|
||||
int singleIndex = Integer.parseInt(keptDice);
|
||||
keptRolls.add(previousRolls.get(singleIndex - 1));
|
||||
|
@ -111,11 +119,9 @@ public class KniffelSystem {
|
|||
}
|
||||
|
||||
|
||||
keptDice = keptDice.replaceAll("\\s+","");
|
||||
keptDice = keptDice.substring(1, keptDice.length()-1);
|
||||
|
||||
System.out.printf("Edited keptDice String: %s \n", keptDice); // TEST
|
||||
|
||||
System.out.printf("Edited keptDice String: %s \n", keptDice); //! TEST
|
||||
|
||||
String[] keptDiceIndicesStrings = keptDice.split(",");
|
||||
|
||||
|
@ -129,7 +135,7 @@ public class KniffelSystem {
|
|||
|
||||
|
||||
private ArrayList<Integer> rollMultipleDice(int amountRolls){
|
||||
System.out.printf("Amount rolls: %d \n", amountRolls); // TEST
|
||||
System.out.printf("Amount rolls: %d \n", amountRolls); //! TEST
|
||||
ArrayList<Integer> rolls = new ArrayList<>();
|
||||
if (amountRolls == 0){
|
||||
return rolls;
|
||||
|
@ -142,7 +148,23 @@ public class KniffelSystem {
|
|||
}
|
||||
|
||||
|
||||
// TEST
|
||||
private ArrayList<Integer> createDevRoll(String keptDice){
|
||||
// Format: dev(1,2,3,4,5)
|
||||
// values aren't indices, they are the dice value
|
||||
ArrayList<Integer> devRoll = new ArrayList<>();
|
||||
|
||||
keptDice = keptDice.replaceAll("\\s+","");
|
||||
keptDice = keptDice.substring(4, keptDice.length()-1);
|
||||
|
||||
String[] rollStrings = keptDice.split(",");
|
||||
for (String rollString : rollStrings){
|
||||
devRoll.add(Integer.parseInt(rollString));
|
||||
}
|
||||
return devRoll;
|
||||
}
|
||||
|
||||
|
||||
//! TEST
|
||||
public String[] getAllPlayerStrings(){
|
||||
ArrayList<Player> players = game.getPlayers();
|
||||
String[] returnStrings = new String[players.size()];
|
||||
|
|
76
tui/TUI.java
76
tui/TUI.java
|
@ -1,9 +1,13 @@
|
|||
package tui;
|
||||
|
||||
import domain.Sheet;
|
||||
import domain.sheets.*;
|
||||
import fassade.KniffelSystem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
|
||||
public class TUI {
|
||||
static KniffelSystem gameSystem;
|
||||
|
@ -12,15 +16,15 @@ public class TUI {
|
|||
public static void main(String[] args) {
|
||||
System.out.println("Welcome to the PR2 Kniffel game!");
|
||||
|
||||
while (true){
|
||||
mainMenuOutput();
|
||||
}
|
||||
// while (true){
|
||||
// mainMenuOutput();
|
||||
// }
|
||||
|
||||
|
||||
// DEV:
|
||||
// gameSystem = new KniffelSystem();
|
||||
// gameSystem.createTestPlayers(6);
|
||||
// gameLoop();
|
||||
gameSystem = new KniffelSystem();
|
||||
gameSystem.createTestPlayers(6);
|
||||
gameLoop();
|
||||
}
|
||||
|
||||
private static int mainMenuOutput(){
|
||||
|
@ -103,6 +107,7 @@ public class TUI {
|
|||
rolls = gameSystem.rollDices(rolls, keptDice);
|
||||
String newRollsString = diceArrToString(rolls);
|
||||
System.out.println(newRollsString);
|
||||
evaluateRoll(rolls);
|
||||
|
||||
System.out.println("Which dice do you want to keep?");
|
||||
System.out.println("Empty for none, single digit for one dice or (1,3,4) for multiple dice.");
|
||||
|
@ -118,10 +123,69 @@ public class TUI {
|
|||
|
||||
|
||||
private static String evaluateRoll(ArrayList<Integer> rolls){
|
||||
HashMap<String, Category> possibleCombinations = createCategorieHashMap();
|
||||
ArrayList<Category> validCombinations = new ArrayList<>();
|
||||
//TODO Add starwars logic
|
||||
|
||||
|
||||
for (int dice : rolls){
|
||||
switch (dice){
|
||||
case 1:
|
||||
possibleCombinations.get("Aces").addAmount();
|
||||
break;
|
||||
case 2:
|
||||
possibleCombinations.get("Twos").addAmount();
|
||||
break;
|
||||
case 3:
|
||||
possibleCombinations.get("Threes").addAmount();
|
||||
break;
|
||||
case 4:
|
||||
possibleCombinations.get("Fours").addAmount();
|
||||
break;
|
||||
case 5:
|
||||
possibleCombinations.get("Fives").addAmount();
|
||||
break;
|
||||
case 6:
|
||||
possibleCombinations.get("Sixes").addAmount();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Possible combinations: \n");
|
||||
|
||||
Set<String> keys = possibleCombinations.keySet();
|
||||
for (String key : keys) {
|
||||
Category keyObj = possibleCombinations.get(key);
|
||||
int keyAmount = keyObj.getAmount();
|
||||
int keyValue = keyObj.getValue();
|
||||
|
||||
if (keyAmount != 0){
|
||||
validCombinations.add(keyObj);
|
||||
sb.append(String.format("%s: Amount: %d, Value: %d \n",key, keyAmount, keyValue));
|
||||
}
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
|
||||
for(Category categorie : validCombinations){
|
||||
if (categorie.getAmount() == 3){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return "TODO";
|
||||
}
|
||||
|
||||
|
||||
private static HashMap<String, Category> createCategorieHashMap(){
|
||||
// TODO starwars sheet implementieren
|
||||
Sheet sheet = new Sheet();
|
||||
|
||||
return sheet.getAllCategories();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static String diceArrToString(ArrayList<Integer> diceArr){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Your rolls: \n");
|
||||
|
|
Loading…
Reference in New Issue