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,25 +9,22 @@ import java.util.Scanner;
|
|||
|
||||
import domain.Player;
|
||||
|
||||
|
||||
|
||||
public class YahtzeeGame {
|
||||
|
||||
public int playerCount;
|
||||
public ArrayList<Player> players = new ArrayList<>();
|
||||
public String savedGamemode;
|
||||
|
||||
|
||||
public YahtzeeGame() {
|
||||
|
||||
}
|
||||
|
||||
public void setPlayercount(int playerCount){
|
||||
public void setPlayercount(int playerCount) {
|
||||
this.playerCount = playerCount;
|
||||
|
||||
}
|
||||
|
||||
public void setPlayerNames(String... names){
|
||||
public void setPlayerNames(String... names) {
|
||||
for (int i = 0; i < this.playerCount; i++) {
|
||||
|
||||
this.players.add(new Player(names[i], this.savedGamemode));
|
||||
|
@ -36,11 +33,11 @@ public class YahtzeeGame {
|
|||
|
||||
}
|
||||
|
||||
public String getPlayerName(int player){
|
||||
public String getPlayerName(int player) {
|
||||
return players.get(player).name;
|
||||
}
|
||||
|
||||
public void setGamemode(String gamemode){
|
||||
public void setGamemode(String gamemode) {
|
||||
this.savedGamemode = gamemode;
|
||||
|
||||
}
|
||||
|
@ -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,17 +107,36 @@ 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();
|
||||
|
||||
}
|
||||
|
||||
public boolean gameOverAll(){
|
||||
public boolean gameOverAll() {
|
||||
int counter = 0;
|
||||
|
||||
for(int i = 0; i<playerCount; i++){
|
||||
if(players.get(i).box.gameOver())
|
||||
for (int i = 0; i < playerCount; i++) {
|
||||
if (players.get(i).box.gameOver())
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
@ -121,7 +151,7 @@ public class YahtzeeGame {
|
|||
return 0;
|
||||
}
|
||||
|
||||
private String[][] refreshHighscoreList(){
|
||||
private String[][] refreshHighscoreList() {
|
||||
|
||||
String highscores[][] = new String[10][3];
|
||||
Scanner sc = new Scanner("src/csv/highscores.csv");
|
||||
|
@ -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();
|
||||
|
@ -365,21 +394,21 @@ public class YahtzeeGame {
|
|||
|
||||
}
|
||||
|
||||
public void saveAllPlayersHighscores() throws IOException{
|
||||
public void saveAllPlayersHighscores() throws IOException {
|
||||
|
||||
for(int i = 0; i<playerCount; i++){
|
||||
setScoreToHighscores(i,refreshHighscoreList());
|
||||
for (int i = 0; i < playerCount; i++) {
|
||||
setScoreToHighscores(i, refreshHighscoreList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String showHighscores(){
|
||||
public String showHighscores() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(int i = 0; i<10; i++){
|
||||
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");
|
||||
|
||||
|
@ -389,7 +418,7 @@ public class YahtzeeGame {
|
|||
|
||||
}
|
||||
|
||||
public void deleteHighscores() throws IOException{
|
||||
public void deleteHighscores() throws IOException {
|
||||
|
||||
PrintWriter out = new PrintWriter(new FileWriter("src/csv/highscores.csv", false));
|
||||
|
||||
|
@ -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;
|
||||
|
@ -9,14 +10,15 @@ public class TUI {
|
|||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
String choice ="";
|
||||
String choice = "";
|
||||
Scanner sc = new Scanner(System.in);
|
||||
boolean newGame = false;
|
||||
|
||||
System.out.println("Yahtzee Star Wars Special!");
|
||||
|
||||
while(newGame){
|
||||
YahtzeeGame game = new YahtzeeGame(){};
|
||||
while (newGame) {
|
||||
YahtzeeGame game = new YahtzeeGame() {
|
||||
};
|
||||
|
||||
while (!choice.equals("stop")) {
|
||||
|
||||
|
@ -25,21 +27,21 @@ public class TUI {
|
|||
System.out.println(">Highscores");
|
||||
choice = sc.nextLine();
|
||||
|
||||
if(choice.equals("Highscores")){
|
||||
if (choice.equals("Highscores")) {
|
||||
System.out.println(game.showHighscores());
|
||||
System.out.println(">Return");
|
||||
System.out.println(">Delete");
|
||||
choice = sc.nextLine();
|
||||
if(choice.equals("Return"))
|
||||
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': ");
|
||||
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': ");
|
||||
choice = sc.nextLine();
|
||||
if(choice.equals("I AM SURE")){
|
||||
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,8 +49,7 @@ public class TUI {
|
|||
|
||||
}
|
||||
|
||||
|
||||
else if(choice.equals("Play")){
|
||||
else if (choice.equals("Play")) {
|
||||
|
||||
System.out.println("Choose your gamemode: ");
|
||||
System.out.println(">Normal");
|
||||
|
@ -62,7 +63,7 @@ public class TUI {
|
|||
System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]");
|
||||
|
||||
String playerNames[] = new String[game.playerCount];
|
||||
for(int i = 0; i < game.playerCount; i++){
|
||||
for (int i = 0; i < game.playerCount; i++) {
|
||||
playerNames[i] = sc.nextLine();
|
||||
}
|
||||
|
||||
|
@ -70,13 +71,44 @@ public class TUI {
|
|||
|
||||
while (!game.gameOverAll()) {
|
||||
|
||||
for(int i = 0; i<game.playerCount; i++){
|
||||
for (int i = 0; i < game.playerCount; i++) {
|
||||
|
||||
System.out.println("Its your turn "+game.getPlayerName(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