nearly done
parent
b207c6ab88
commit
0dc39592db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/ui/TUI.class
BIN
bin/ui/TUI.class
Binary file not shown.
|
@ -348,4 +348,53 @@ public class Box {
|
|||
|
||||
}
|
||||
|
||||
public String selectedOptionsPrinted(int player) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (savedGamemode.equals("Special8")) {
|
||||
sb.append("categoryOne: " + nullCheck(setCategoryOne) + "\n");
|
||||
sb.append("categoryTwo: " + nullCheck(setCategoryTwo) + "\n");
|
||||
sb.append("categoryThree: " + nullCheck(setCategoryThree) + "\n");
|
||||
sb.append("categoryFour: " + nullCheck(setCategoryFour) + "\n");
|
||||
sb.append("categoryFive: " + nullCheck(setCategoryFive) + "\n");
|
||||
sb.append("categorySix: " + nullCheck(setCategorySix) + "\n");
|
||||
sb.append("categorySeven: " + nullCheck(setCategorySeven) + "\n");
|
||||
sb.append("categoryEight: " + nullCheck(setCategoryEight) + "\n");
|
||||
sb.append("\n--------------------------\n\n");
|
||||
sb.append("categoryTripleMatch: " + nullCheck(setCategoryTripleMatch) + "\n");
|
||||
sb.append("categoryFourOfAKind: " + nullCheck(setCategoryFourOfAKind) + "\n");
|
||||
sb.append("categoryFullHouse: " + nullCheck(setCategoryFullHouse) + "\n");
|
||||
sb.append("categorySmallStreet: " + nullCheck(setCategorySmallStreet) + "\n");
|
||||
sb.append("categoryBigStreet: " + nullCheck(setCategoryBigStreet) + "\n");
|
||||
sb.append("categoryYahtzee: " + nullCheck(setCategoryYahtzee) + "\n");
|
||||
sb.append("categoryChance: " + nullCheck(setCategoryChance) + "\n");
|
||||
sb.append("categoryR2D2: " + nullCheck(setCategoryR2D2) + "\n");
|
||||
} else {
|
||||
sb.append("categoryOne: " + nullCheck(setCategoryOne) + "\n");
|
||||
sb.append("categoryTwo: " + nullCheck(setCategoryTwo) + "\n");
|
||||
sb.append("categoryThree: " + nullCheck(setCategoryThree) + "\n");
|
||||
sb.append("categoryFour: " + nullCheck(setCategoryFour) + "\n");
|
||||
sb.append("categoryFive: " + nullCheck(setCategoryFive) + "\n");
|
||||
sb.append("categorySix: " + nullCheck(setCategorySix) + "\n");
|
||||
sb.append("\n--------------------------\n\n");
|
||||
sb.append("categoryTripleMatch: " + nullCheck(setCategoryTripleMatch) + "\n");
|
||||
sb.append("categoryFourOfAKind: " + nullCheck(setCategoryFourOfAKind) + "\n");
|
||||
sb.append("categoryFullHouse: " + nullCheck(setCategoryFullHouse) + "\n");
|
||||
sb.append("categorySmallStreet: " + nullCheck(setCategorySmallStreet) + "\n");
|
||||
sb.append("categoryBigStreet: " + nullCheck(setCategoryBigStreet) + "\n");
|
||||
sb.append("categoryYahtzee: " + nullCheck(setCategoryYahtzee) + "\n");
|
||||
sb.append("categoryChance: " + nullCheck(setCategoryChance) + "\n");
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
public String nullCheck(Integer i) {
|
||||
|
||||
if (i == null)
|
||||
return "___";
|
||||
else
|
||||
return "" + i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,13 +33,19 @@ public class Hand {
|
|||
|
||||
}
|
||||
|
||||
public void lockInDices(int... dices) {
|
||||
public void lockInDices(String... dices) {
|
||||
|
||||
for (int i = 0; i < dices.length; i++) {
|
||||
lockInDice(dices[i]);
|
||||
lockInDice(Integer.parseInt(dices[i]));
|
||||
}
|
||||
}
|
||||
|
||||
public int getLockedInDiceAmount() {
|
||||
|
||||
return lockedInDices.size();
|
||||
|
||||
}
|
||||
|
||||
public void rollDices() {
|
||||
|
||||
if (this.leftRolls > 0)
|
||||
|
@ -96,4 +102,5 @@ public class Hand {
|
|||
|
||||
return this.leftRolls;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,15 +9,12 @@ import java.util.Scanner;
|
|||
|
||||
import domain.Player;
|
||||
|
||||
|
||||
|
||||
public class YahtzeeGame {
|
||||
|
||||
public int playerCount;
|
||||
public ArrayList<Player> players = new ArrayList<>();
|
||||
public String savedGamemode;
|
||||
|
||||
|
||||
public YahtzeeGame() {
|
||||
|
||||
}
|
||||
|
@ -69,21 +66,35 @@ public class YahtzeeGame {
|
|||
|
||||
}
|
||||
|
||||
public void lockInDices(int player, int... dices) {
|
||||
public void lockInDices(int player, String... dices) {
|
||||
|
||||
if (dices[0].equals("none"))
|
||||
return;
|
||||
players.get(player).hand.lockInDices(dices);
|
||||
|
||||
}
|
||||
|
||||
public boolean allDicesLockedIn(int player) {
|
||||
|
||||
return players.get(player).hand.getLockedInDiceAmount() == 5;
|
||||
|
||||
}
|
||||
|
||||
public int getLeftRolls(int player) {
|
||||
|
||||
return players.get(player).hand.getLeftRolls();
|
||||
|
||||
}
|
||||
|
||||
public boolean noMoreRolls(int player) {
|
||||
|
||||
return 0 == getLeftRolls(player);
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<String> getAllOptionsEvaluated(int player) {
|
||||
|
||||
players.get(player).box.evaluateBoxOptions(players.get(player - 1).hand.getAllDiceNumbers());
|
||||
players.get(player).box.evaluateBoxOptions(players.get(player).hand.getAllDiceNumbers());
|
||||
return players.get(player).box.getAllOptions();
|
||||
|
||||
}
|
||||
|
@ -96,6 +107,25 @@ public class YahtzeeGame {
|
|||
|
||||
}
|
||||
|
||||
public String optionsPrinted(int player) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < getAllOptionsEvaluated(player).size(); i++) {
|
||||
|
||||
sb.append(getAllOptionsEvaluated(player).get(i) + "\n");
|
||||
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
public String selectedOptionsPrinted(int player) {
|
||||
|
||||
return players.get(player).box.selectedOptionsPrinted(player);
|
||||
}
|
||||
|
||||
public boolean gameOver(int player) {
|
||||
|
||||
return players.get(player).box.gameOver();
|
||||
|
@ -147,7 +177,6 @@ public class YahtzeeGame {
|
|||
try {
|
||||
if (returnTotalPoints(player) < Integer.parseInt(highscores[9][2])) {
|
||||
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
@ -353,7 +382,7 @@ public class YahtzeeGame {
|
|||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int s = 0; s < 3; s++) {
|
||||
out.print(i + ": " + LocalDate.now() + ": " + players.get(player).name + ": "
|
||||
out.print((i + 1) + ": " + LocalDate.now() + ": " + players.get(player).name + ": "
|
||||
+ returnTotalPoints(player));
|
||||
}
|
||||
out.println();
|
||||
|
@ -379,7 +408,7 @@ public class YahtzeeGame {
|
|||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
sb.append(i+": "+refreshHighscoreList()[i][0]);
|
||||
sb.append((i + 1) + ": " + refreshHighscoreList()[i][0]);
|
||||
sb.append(": " + refreshHighscoreList()[i][1]);
|
||||
sb.append(": " + refreshHighscoreList()[i][2] + "\n");
|
||||
|
||||
|
@ -398,4 +427,20 @@ public class YahtzeeGame {
|
|||
out.close();
|
||||
|
||||
}
|
||||
|
||||
public String getWinnerMessage() {
|
||||
|
||||
int winnerScore = returnTotalPoints(0);
|
||||
String winnerName = getPlayerName(0);
|
||||
|
||||
for (int i = 0; i < this.playerCount; i++) {
|
||||
if (winnerScore < returnTotalPoints(i)) {
|
||||
winnerScore = returnTotalPoints(i);
|
||||
winnerName = getPlayerName(i);
|
||||
}
|
||||
}
|
||||
|
||||
return winnerName + " is the winner, with a total score of: " + winnerScore;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import facade.YahtzeeGame;
|
||||
|
@ -16,7 +17,8 @@ public class TUI {
|
|||
System.out.println("Yahtzee Star Wars Special!");
|
||||
|
||||
while (newGame) {
|
||||
YahtzeeGame game = new YahtzeeGame(){};
|
||||
YahtzeeGame game = new YahtzeeGame() {
|
||||
};
|
||||
|
||||
while (!choice.equals("stop")) {
|
||||
|
||||
|
@ -33,13 +35,13 @@ public class TUI {
|
|||
if (choice.equals("Return"))
|
||||
break;
|
||||
else if (choice.equals("Delete")) {
|
||||
System.out.println("Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': ");
|
||||
System.out.println(
|
||||
"Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': ");
|
||||
choice = sc.nextLine();
|
||||
if (choice.equals("I AM SURE")) {
|
||||
game.deleteHighscores();
|
||||
System.out.println("Highscore file got deleted...\nReturning to the main menu...");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
System.out.println("Highscore file not deleted...\nReturning to the main menu...");
|
||||
}
|
||||
|
||||
|
@ -47,7 +49,6 @@ public class TUI {
|
|||
|
||||
}
|
||||
|
||||
|
||||
else if (choice.equals("Play")) {
|
||||
|
||||
System.out.println("Choose your gamemode: ");
|
||||
|
@ -72,11 +73,42 @@ public class TUI {
|
|||
|
||||
for (int i = 0; i < game.playerCount; i++) {
|
||||
|
||||
if (game.gameOver(i))
|
||||
continue;
|
||||
|
||||
System.out.println("Its your turn " + game.getPlayerName(i));
|
||||
System.out.println("This is your Yahtzee Box: ");
|
||||
System.out.println(game.selectedOptionsPrinted(i) + "\n");
|
||||
|
||||
while (!game.allDicesLockedIn(i) || !game.noMoreRolls(i)) {
|
||||
|
||||
System.out.println("Your dices: ");
|
||||
System.out.println("Free dices: " + game.getFreeDiceNumbers(i));
|
||||
System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i));
|
||||
System.out.println(
|
||||
"Type in which free dices you want to keep \n(seperated by space, type 'none' if you dont want to keep any): ");
|
||||
choice = sc.nextLine();
|
||||
game.lockInDices(i, choice.split(" "));
|
||||
game.rollDices(i);
|
||||
System.out.println(game.getLeftRolls(i) + " rolls left");
|
||||
System.out.println("Rerolling dices... ");
|
||||
|
||||
}
|
||||
|
||||
System.out.println("Done locking in... Here are your options: ");
|
||||
System.out.println(game.optionsPrinted(i));
|
||||
System.out.println("Which option you want to select?: ");
|
||||
game.selectOption(i, sc.nextLine());
|
||||
|
||||
if (game.gameOver(i)) {
|
||||
System.out.println(
|
||||
"Your game is over, here is your total score: " + game.returnTotalPoints(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("The game is over, saving all highscores to the highscore table...");
|
||||
game.saveAllPlayersHighscores();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue