From 7657f010a9a3f993df3ffaa82fdb948a83edd50a Mon Sep 17 00:00:00 2001 From: selim Date: Mon, 29 Apr 2024 18:14:57 +0200 Subject: [PATCH] Some bugs need to be solved --- bin/domain/Box.class | Bin 10705 -> 10702 bytes bin/domain/Dice.class | Bin 1036 -> 1058 bytes bin/domain/Hand.class | Bin 2715 -> 2803 bytes bin/ui/TUI.class | Bin 4622 -> 4749 bytes src/domain/Box.java | 2 +- src/domain/Dice.java | 10 ++++++---- src/domain/Hand.java | 12 +++++++++--- src/ui/TUI.java | 36 +++++++++++++++++++++--------------- 8 files changed, 37 insertions(+), 23 deletions(-) diff --git a/bin/domain/Box.class b/bin/domain/Box.class index b233fb26b188aee417864ddfd91948128af0bbb0..bb0735ca700fa211be9765e1dab75468dd4eb419 100644 GIT binary patch delta 424 zcmYMxJ4*vW6o%pRO`3=p-7#6?ZNkP&u~VA}iod{a#h{WRjYR@tAu3pe`~X2&P*Yim zj3C}f6s;_T*ePNcj3R0jtOP4TFpR~N=XtyD+<7GrBI4 z<+^1`ozvJUttr+ldCl;YW?$i3@<+onnl}_`l0O+vYc48O{B>bRk0gIKF{9(Q!j^w2 z?0iA;7Zc}n+*Qa*{%Uw$^PYky`J3Sd&HD^uzOW-J=9jgdq6A|pd#sNBTfhexfiCc7`if+`=gD>>r y2Liu{u^=24Mx4db$0Yh$0)vzwBKv=LO44xSYJ7k`$t6&h$e(a543%b`T<{M(PIz1Z delta 440 zcmYk(&nv@m9LMqZ>!U<6_GaJB@Lj{C@24CYhxrdUtgO)v;zZ;iiNh}Y1Ez1OQJnZF zrLkEK%8gtUuI5L6=c=5P^>O%k-`T7shQ~FpDLhENH=NR(Q@C(fZ7Xmn`O(A)9k&!V+*8|1 zXCyzFIH%*b!mQ+H!}FSV6-Fh$7+%o4r!XY>)$pR`eT5#$Z-$pNA1HVwziTc##cH}K z(eP#=5n4eyhI)*^gCrU-g+|Q5i)An}XhIgvSceZgu#krzCkWsSEx1MyWwhc0ZTLbv zeqakiNY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k0$Zj^apmEC1X0^qjXP&RAjt z?TJ_Dns3=a=mo-wrWc4Lk}t5&JNgu%#7_uEU!i9{xqSnIJob{js0~|-Wa)c*(ovb*Dem*fjcUy@mN@jz^>%lRuw!^c@ zt6o2pAIB9K#3NR8!9Q`qPYT2nHpDVc{DPh`PDdW2*IgNz=eRGjfr&EC&uwAw zrp90|)dRu|9l>tm>BT;#4C5TR)sRnCkxycZcol(-*CB6#_Z^y4zX#vq5>hVUWwI8v z!veT1k&GUHiOXetE?APU*Ej#F!RVlbz#+mo%wioP=XhQEa5cREy>6!u)urcGPSR`K zpsU>MX^zy8b*3C|utNsc@0s@*7oGC$wBa3P@%ou{(9S49q!do6q%2-2@y`u(@?Tu^ z9hW>DhZr*QJ^H*OPtnDBI8v#{7mt*R$ck;4KNIsj=*!Y#HO7wcCz$&r4RngOIf)p~ z;5c8kB7De6;o=C;7h)7;8-<^{chFSZ-~3uBe2ICUbsFNP4e)mY6yX=d;TyP>mI6eR z0w`L6c={z48jSI_dhqOr4vL2Bn{SgpFut#@3C7q8<23a-9OQTm7szJ{X^uB>*=Cfm zYrNnxYN4Qa?A8sk=1vm~RcAV*OC_9Bi!N_A+CTD9?oxYpNmpbVm_Kou5B+cEb%a7R z88FS{*GOoFgszd$oK3>%C{(_08WJ zP%jYmZKA$I)VFEtOdaaMD(YAjb)PGJ4YllTk2+WFtpRe7HffR$kbd&mPLLNdVA?62 OK5BAPD%`VAng0QS=>?(y diff --git a/bin/ui/TUI.class b/bin/ui/TUI.class index 5fa08a11546b21d4cd320280f405d04376b633cf..fe70f11c7d3923db4409839fc2d67cf225aa1488 100644 GIT binary patch delta 1781 zcmYjRYgANK6#n*^_nnL2BqC-xE+2smSS&?DT$$#B77z+)x^&qD*AX0MaAqJ-bMmc_ zTAnho((ECb<&!3xGJBVnSz20_mX&3erlpn2qjTIho2p~x45Y$42UU#h)DDhYMLIh(< zZt6HIstC6#{ID^b?&l6umbq5NOw8g1rp`kiP%#Jb*QOS@E3}}j`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 zWQ3%t=qc483@2};7&h@+#Md|?8k79^2H%3eWT_nA;V2|rDcy?i@dGU6po#dA^JH=% z4L_j)R=SpAQsRhXT;Licbs*h_0vnPqV1W&Vjt*4Y@H08j^HAH6 z#~;IS9w*@!{K~zTmvfq@|HHI@n)Ywgo;B^iraf=k3%JN5+ 0) { + if (setCategoryYahtzee != null) { setCategoryYahtzee += 50; if (counter[0] == 5) setCategoryOne = 5; diff --git a/src/domain/Dice.java b/src/domain/Dice.java index dbce06c..31e2724 100644 --- a/src/domain/Dice.java +++ b/src/domain/Dice.java @@ -1,5 +1,7 @@ package domain; +import java.lang.Math; + public class Dice { private int diceNumber; @@ -8,9 +10,9 @@ public class Dice { public Dice(String gamemode) { this.savedGamemode = gamemode; 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")) - this.diceNumber = (int) Math.random() * 8 + 1; + this.diceNumber = ((int) (Math.random() * 8)) + 1; } public Dice(String gamemode, int diceNumber) { @@ -21,9 +23,9 @@ public class Dice { public void rerollDice() { 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")) - this.diceNumber = (int) Math.random() * 8 + 1; + this.diceNumber = ((int) (Math.random() * 8)) + 1; } diff --git a/src/domain/Hand.java b/src/domain/Hand.java index 3669566..310a672 100644 --- a/src/domain/Hand.java +++ b/src/domain/Hand.java @@ -5,15 +5,15 @@ import java.util.ArrayList; public class Hand { private ArrayList dices = new ArrayList<>(5); - private ArrayList lockedInDices; - private int leftRolls = 2; + private ArrayList lockedInDices = new ArrayList<>(); + private int leftRolls = 3; private String savedGamemode; public Hand(String 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)); @@ -56,6 +56,12 @@ public class Hand { } leftRolls--; + + if (this.leftRolls == 1) + for (int i = 0; i < this.dices.size(); i++) { + lockInDice(this.dices.get(i).getDiceNumber()); + } + } public ArrayList getAllDiceNumbers() { diff --git a/src/ui/TUI.java b/src/ui/TUI.java index 863d494..d773683 100644 --- a/src/ui/TUI.java +++ b/src/ui/TUI.java @@ -17,7 +17,7 @@ public class TUI { YahtzeeGame game = new YahtzeeGame() { }; - System.out.println("Main menu:\n"); + System.out.println("\nMain menu:\n"); System.out.println(">Play"); System.out.println(">Highscores"); choice = sc.nextLine(); @@ -32,11 +32,11 @@ public class TUI { 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': "); + "\nAre 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..."); + System.out.println("\nHighscore file got deleted...\nReturning to the main menu..."); } else { System.out.println("Highscore file not deleted...\nReturning to the main menu..."); } @@ -47,18 +47,19 @@ public class TUI { else if (choice.equals("Play")) { - System.out.println("Choose your gamemode: "); + System.out.println("\nChoose your gamemode: "); System.out.println(">Normal"); System.out.println(">StarWarsDay"); System.out.println(">Special8"); game.setGamemode(sc.nextLine()); - System.out.println("Amount of players: "); + System.out.println("\nAmount of players: "); System.out.println(">1-6"); - game.setPlayercount(sc.nextInt()); - System.out.println("Type in the player names, lock in each name with Enter: "); + game.setPlayercount(Integer.parseInt(sc.nextLine())); + System.out.println("\nType 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(); } @@ -72,26 +73,31 @@ public class TUI { 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"); + System.out.println("\nIts your turn " + game.getPlayerName(i)); + System.out.println("\nThis is your Yahtzee Box: "); + 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("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... "); + + if ((game.getLeftRolls(i)) != 1) + 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("Locked in dices: " + game.getLockedInDiceNumbers(i)); System.out.println(game.optionsPrinted(i)); System.out.println("Which option you want to select?: "); game.selectOption(i, sc.nextLine());