Some bugs need to be solved

main
selim 2024-04-29 18:14:57 +02:00
parent df415b4042
commit 7657f010a9
8 changed files with 37 additions and 23 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -265,7 +265,7 @@ public class Box {
else if (option.equals("categoryBigStreet")) else if (option.equals("categoryBigStreet"))
setCategoryBigStreet = categoryBigStreet; setCategoryBigStreet = categoryBigStreet;
else if (option.equals("categoryYahtzee")) { else if (option.equals("categoryYahtzee")) {
if (setCategoryYahtzee > 0) { if (setCategoryYahtzee != null) {
setCategoryYahtzee += 50; setCategoryYahtzee += 50;
if (counter[0] == 5) if (counter[0] == 5)
setCategoryOne = 5; setCategoryOne = 5;

View File

@ -1,5 +1,7 @@
package domain; package domain;
import java.lang.Math;
public class Dice { public class Dice {
private int diceNumber; private int diceNumber;
@ -8,9 +10,9 @@ public class Dice {
public Dice(String gamemode) { public Dice(String gamemode) {
this.savedGamemode = gamemode; this.savedGamemode = gamemode;
if (gamemode.equals("Normal") || gamemode.equals("StarWarsDay")) if (gamemode.equals("Normal") || gamemode.equals("StarWarsDay"))
this.diceNumber = (int) Math.random() * 6 + 1; this.diceNumber = ((int) (Math.random() * 6)) + 1;
else if (gamemode.equals("Special8")) else if (gamemode.equals("Special8"))
this.diceNumber = (int) Math.random() * 8 + 1; this.diceNumber = ((int) (Math.random() * 8)) + 1;
} }
public Dice(String gamemode, int diceNumber) { public Dice(String gamemode, int diceNumber) {
@ -21,9 +23,9 @@ public class Dice {
public void rerollDice() { public void rerollDice() {
if (this.savedGamemode.equals("Normal") || this.savedGamemode.equals("StarWarsDay")) if (this.savedGamemode.equals("Normal") || this.savedGamemode.equals("StarWarsDay"))
this.diceNumber = (int) Math.random() * 6 + 1; this.diceNumber = ((int) (Math.random() * 6)) + 1;
else if (this.savedGamemode.equals("Special8")) else if (this.savedGamemode.equals("Special8"))
this.diceNumber = (int) Math.random() * 8 + 1; this.diceNumber = ((int) (Math.random() * 8)) + 1;
} }

View File

@ -5,15 +5,15 @@ import java.util.ArrayList;
public class Hand { public class Hand {
private ArrayList<Dice> dices = new ArrayList<>(5); private ArrayList<Dice> dices = new ArrayList<>(5);
private ArrayList<Dice> lockedInDices; private ArrayList<Dice> lockedInDices = new ArrayList<>();
private int leftRolls = 2; private int leftRolls = 3;
private String savedGamemode; private String savedGamemode;
public Hand(String gamemode) { public Hand(String gamemode) {
this.savedGamemode = gamemode; this.savedGamemode = gamemode;
for (int i = 0; i < dices.size(); i++) { for (int i = 0; i < 5; i++) {
dices.add(i, new Dice(gamemode)); dices.add(i, new Dice(gamemode));
@ -56,6 +56,12 @@ public class Hand {
} }
leftRolls--; leftRolls--;
if (this.leftRolls == 1)
for (int i = 0; i < this.dices.size(); i++) {
lockInDice(this.dices.get(i).getDiceNumber());
}
} }
public ArrayList<Integer> getAllDiceNumbers() { public ArrayList<Integer> getAllDiceNumbers() {

View File

@ -17,7 +17,7 @@ public class TUI {
YahtzeeGame game = new YahtzeeGame() { YahtzeeGame game = new YahtzeeGame() {
}; };
System.out.println("Main menu:\n"); System.out.println("\nMain menu:\n");
System.out.println(">Play"); System.out.println(">Play");
System.out.println(">Highscores"); System.out.println(">Highscores");
choice = sc.nextLine(); choice = sc.nextLine();
@ -32,11 +32,11 @@ public class TUI {
else if (choice.equals("Delete")) { else if (choice.equals("Delete")) {
System.out.println( System.out.println(
"Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': "); "\nAre you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': ");
choice = sc.nextLine(); choice = sc.nextLine();
if (choice.equals("I AM SURE")) { if (choice.equals("I AM SURE")) {
game.deleteHighscores(); game.deleteHighscores();
System.out.println("Highscore file got deleted...\nReturning to the main menu..."); System.out.println("\nHighscore file got deleted...\nReturning to the main menu...");
} else { } else {
System.out.println("Highscore file not deleted...\nReturning to the main menu..."); System.out.println("Highscore file not deleted...\nReturning to the main menu...");
} }
@ -47,18 +47,19 @@ public class TUI {
else if (choice.equals("Play")) { else if (choice.equals("Play")) {
System.out.println("Choose your gamemode: "); System.out.println("\nChoose your gamemode: ");
System.out.println(">Normal"); System.out.println(">Normal");
System.out.println(">StarWarsDay"); System.out.println(">StarWarsDay");
System.out.println(">Special8"); System.out.println(">Special8");
game.setGamemode(sc.nextLine()); game.setGamemode(sc.nextLine());
System.out.println("Amount of players: "); System.out.println("\nAmount of players: ");
System.out.println(">1-6"); System.out.println(">1-6");
game.setPlayercount(sc.nextInt()); game.setPlayercount(Integer.parseInt(sc.nextLine()));
System.out.println("Type in the player names, lock in each name with Enter: "); System.out.println("\nType in the player names, lock in each name with Enter: ");
System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]"); System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]");
String playerNames[] = new String[game.playerCount]; 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(); playerNames[i] = sc.nextLine();
} }
@ -72,26 +73,31 @@ public class TUI {
if (game.gameOver(i)) if (game.gameOver(i))
continue; continue;
System.out.println("Its your turn " + game.getPlayerName(i)); System.out.println("\nIts your turn " + game.getPlayerName(i));
System.out.println("This is your Yahtzee Box: "); System.out.println("\nThis is your Yahtzee Box: ");
System.out.println(game.selectedOptionsPrinted(i) + "\n"); System.out.println("\n" + game.selectedOptionsPrinted(i) + "\n");
while (!game.allDicesLockedIn(i) || !game.noMoreRolls(i)) { while (!game.allDicesLockedIn(i) && !game.noMoreRolls(i)) {
System.out.println("Rolling dices... ");
game.rollDices(i);
System.out.println("Your dices: ");
System.out.println("Free dices: " + game.getFreeDiceNumbers(i)); System.out.println("Free dices: " + game.getFreeDiceNumbers(i));
System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i)); System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i));
System.out.println( 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): "); "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(); choice = sc.nextLine();
game.lockInDices(i, choice.split(" ")); game.lockInDices(i, choice.split(" "));
game.rollDices(i);
System.out.println(game.getLeftRolls(i) + " rolls left"); if ((game.getLeftRolls(i)) != 1)
System.out.println("Rerolling dices... "); System.out.println("\n" + game.getLeftRolls(i) + " rolls left");
else
System.out.println("\n" + game.getLeftRolls(i) + " roll left");
} }
System.out.println("Done locking in... Here are your options: "); System.out.println("Done locking in... Here are your options: ");
System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i));
System.out.println(game.optionsPrinted(i)); System.out.println(game.optionsPrinted(i));
System.out.println("Which option you want to select?: "); System.out.println("Which option you want to select?: ");
game.selectOption(i, sc.nextLine()); game.selectOption(i, sc.nextLine());