Nearly everything implemented

main
selim 2024-04-29 16:47:41 +02:00
parent 0dc39592db
commit df415b4042
10 changed files with 90 additions and 82 deletions

View File

@ -0,0 +1 @@
1
1

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/ui/TUI$1.class 100644

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
1
1

View File

@ -42,8 +42,10 @@ public class Hand {
public int getLockedInDiceAmount() { public int getLockedInDiceAmount() {
return lockedInDices.size(); if (lockedInDices != null)
return lockedInDices.size();
else
return 0;
} }
public void rollDices() { public void rollDices() {
@ -89,7 +91,7 @@ public class Hand {
public ArrayList<Integer> getLockedInDiceNumbers() { public ArrayList<Integer> getLockedInDiceNumbers() {
ArrayList<Integer> res = new ArrayList<>(); ArrayList<Integer> res = new ArrayList<>();
for (int i = 0; i < this.lockedInDices.size(); i++) { for (int i = 0; i < getLockedInDiceAmount(); i++) {
res.add(this.lockedInDices.get(i).getDiceNumber()); res.add(this.lockedInDices.get(i).getDiceNumber());

View File

@ -1,5 +1,7 @@
package facade; package facade;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -151,10 +153,10 @@ public class YahtzeeGame {
return 0; return 0;
} }
private String[][] refreshHighscoreList() { private String[][] refreshHighscoreList() throws FileNotFoundException {
String highscores[][] = new String[10][3]; String highscores[][] = new String[10][3];
Scanner sc = new Scanner("src/csv/highscores.csv"); Scanner sc = new Scanner(new File("src/csv/highscores.csv"));
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
@ -162,7 +164,12 @@ public class YahtzeeGame {
highscores[i][0] = sc.next(); highscores[i][0] = sc.next();
highscores[i][1] = sc.next(); highscores[i][1] = sc.next();
highscores[i][2] = sc.nextLine(); highscores[i][2] = sc.nextLine();
} else {
highscores[i][0] = "___";
highscores[i][1] = "___";
highscores[i][2] = "0";
} }
} }
sc.close(); sc.close();
@ -402,7 +409,7 @@ public class YahtzeeGame {
} }
public String showHighscores() { public String showHighscores() throws FileNotFoundException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@ -1,9 +1,7 @@
package ui; package ui;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
import facade.YahtzeeGame; import facade.YahtzeeGame;
public class TUI { public class TUI {
@ -12,107 +10,106 @@ public class TUI {
String choice = ""; String choice = "";
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
boolean newGame = false;
System.out.println("Yahtzee Star Wars Special!"); System.out.println("Yahtzee Star Wars Special!");
while (newGame) { while (!choice.equals("stop")) {
YahtzeeGame game = new YahtzeeGame() { YahtzeeGame game = new YahtzeeGame() {
}; };
System.out.println("Main menu:\n");
System.out.println(">Play");
System.out.println(">Highscores");
choice = sc.nextLine();
while (!choice.equals("stop")) { if (choice.equals("Highscores")) {
System.out.println(game.showHighscores());
System.out.println("Main menu:\n"); System.out.println(">Return");
System.out.println(">Play"); System.out.println(">Delete");
System.out.println(">Highscores");
choice = sc.nextLine(); choice = sc.nextLine();
if (choice.equals("Return")) {
}
if (choice.equals("Highscores")) { else if (choice.equals("Delete")) {
System.out.println(game.showHighscores()); System.out.println(
System.out.println(">Return"); "Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': ");
System.out.println(">Delete");
choice = sc.nextLine(); choice = sc.nextLine();
if (choice.equals("Return")) if (choice.equals("I AM SURE")) {
break; game.deleteHighscores();
else if (choice.equals("Delete")) { System.out.println("Highscore file got deleted...\nReturning to the main menu...");
System.out.println( } else {
"Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': "); System.out.println("Highscore file not deleted...\nReturning to the main menu...");
choice = sc.nextLine();
if (choice.equals("I AM SURE")) {
game.deleteHighscores();
System.out.println("Highscore file got deleted...\nReturning to the main menu...");
} else {
System.out.println("Highscore file not deleted...\nReturning to the main menu...");
}
} }
} }
else if (choice.equals("Play")) { }
System.out.println("Choose your gamemode: "); else if (choice.equals("Play")) {
System.out.println(">Normal");
System.out.println(">StarWarsDay"); System.out.println("Choose your gamemode: ");
System.out.println(">Special8"); System.out.println(">Normal");
game.setGamemode(sc.nextLine()); System.out.println(">StarWarsDay");
System.out.println("Amount of players: "); System.out.println(">Special8");
System.out.println(">1-6"); game.setGamemode(sc.nextLine());
game.setPlayercount(sc.nextInt()); System.out.println("Amount of players: ");
System.out.println("Type in the player names, lock in each name with Enter: "); System.out.println(">1-6");
System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]"); game.setPlayercount(sc.nextInt());
System.out.println("Type in the player names, lock in each name with Enter: ");
System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]");
String playerNames[] = new String[game.playerCount];
for (int i = 0; i < game.playerCount; i++) {
playerNames[i] = sc.nextLine();
}
game.setPlayerNames(playerNames);
while (!game.gameOverAll()) {
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();
}
game.setPlayerNames(playerNames); if (game.gameOver(i))
continue;
while (!game.gameOverAll()) { System.out.println("Its your turn " + game.getPlayerName(i));
System.out.println("This is your Yahtzee Box: ");
System.out.println(game.selectedOptionsPrinted(i) + "\n");
for (int i = 0; i < game.playerCount; i++) { while (!game.allDicesLockedIn(i) || !game.noMoreRolls(i)) {
if (game.gameOver(i)) System.out.println("Your dices: ");
continue; 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("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("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());
System.out.println("Your dices: "); if (game.gameOver(i)) {
System.out.println("Free dices: " + game.getFreeDiceNumbers(i)); System.out.println(
System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i)); "Your game is over, here is your total score: " + game.returnTotalPoints(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();
} }
System.out.println("The game is over, " + game.getWinnerMessage());
System.out.println("Saving all highscores to the highscore table...");
game.saveAllPlayersHighscores();
System.out.println(
"If you want to stop the programm type: 'stop', otherwise you will return to the main menu:");
choice = sc.nextLine();
} }
} }
} }
} }