diff --git a/Partie_2/.vscode/c_cpp_properties.json b/Partie_2/.vscode/c_cpp_properties.json new file mode 100644 index 0000000000000000000000000000000000000000..c2098a2d0c4b96621c02cb4e33bc58231ccffc1d --- /dev/null +++ b/Partie_2/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Partie_2/.vscode/launch.json b/Partie_2/.vscode/launch.json new file mode 100644 index 0000000000000000000000000000000000000000..7f873a9001f36511d308c7bfb198f7e8789586d0 --- /dev/null +++ b/Partie_2/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/padi/Téléchargements", + "program": "/home/padi/Téléchargements/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/Partie_2/.vscode/settings.json b/Partie_2/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..3e5eb956e1aac2b053a4d09e761fcc26bb2b106e --- /dev/null +++ b/Partie_2/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/Partie_2/src/main/java/ch/hepia/App.java b/Partie_2/src/main/java/ch/hepia/App.java index f3de79a859d846f8de27e13acdc22e908dc454ed..000bcecbb346a9016299fff04596f095524bc727 100644 --- a/Partie_2/src/main/java/ch/hepia/App.java +++ b/Partie_2/src/main/java/ch/hepia/App.java @@ -4,7 +4,10 @@ import java.util.Scanner; public class App { + // Scanner will be used all along to take user inputs in the terminal public static final Scanner in = new Scanner(System.in); + + // All Color choices to be used in terminal prints public static final String ANSI_RESET = "\u001B[0m"; public static final String ANSI_BLACK = "\u001B[30m"; public static final String ANSI_RED = "\u001B[31m"; @@ -25,9 +28,12 @@ public class App { int numPlayers; int startMoney; + // Ask the number of players until a valide answer is given while (true) { + System.out.print("How many players ? "); + // Check that the input is an valid int while (!App.in.hasNextInt()) { System.out.println( App.ANSI_YELLOW + "Please enter a valid number for the number of players." + App.ANSI_RESET); @@ -37,6 +43,7 @@ public class App { numPlayers = App.in.nextInt(); + // Player count must be between 1 and 7 if (numPlayers >= 1 && numPlayers <= 7) { System.out.print(""); break; @@ -46,9 +53,12 @@ public class App { } } + // Ask the start money count for each players until a valide answer is given while (true) { + System.out.print("How much money do you start with ? "); + // Check that the input is an valid int while (!App.in.hasNextInt()) { System.out.println(App.ANSI_YELLOW + "Please enter a valid number for your Money." + App.ANSI_RESET); System.out.print("How much money do you start with ? "); @@ -57,6 +67,7 @@ public class App { startMoney = App.in.nextInt(); + // Starting money must be more or equal to minimum bid amount if (startMoney >= 10) { System.out.print(""); break; @@ -65,16 +76,28 @@ public class App { } } + // Create a new game GameManager BlackJack = new GameManager(numPlayers, startMoney); boolean GameOver = false; + // Game run's in 3 Phases : + // Phase 1 (StartTurn): + // Ask the player how much he wan't to bid + // Phase 2 (PlayTurn): + // Ask the player for all his interactions with this cards + // Phase 3 (ResolveTurn): + // Make the Dealer pick cards + // Do all the math for the player gains and losses + // Check if the player can continue et prepare for the next round while (!GameOver) { BlackJack.StartTurn(); BlackJack.PlayTurn(); GameOver = BlackJack.ResolveTurn(); } + // The player has less than the minimum bid amount allowed = Game Over + System.out.print("\033[H\033[2J"); System.out.flush(); @@ -87,6 +110,7 @@ public class App { public static void main(String[] args) { + // Play 1 BlackJack Game BlackJack(); } diff --git a/Partie_2/src/main/java/ch/hepia/GameManager.java b/Partie_2/src/main/java/ch/hepia/GameManager.java index 4bbb816a3fcf70bf3d9086cdc882668e1caf204b..36cbf8e0595b86f34754f07f41df38df9335a651 100644 --- a/Partie_2/src/main/java/ch/hepia/GameManager.java +++ b/Partie_2/src/main/java/ch/hepia/GameManager.java @@ -12,12 +12,15 @@ public class GameManager { public GameManager(int nbPlayer, int startMoney) { + // Create a new BlackJack Deck of card (6 x 52 cards game) this.Deck = new JeudeCarte(new Paquet(6, 52)); this.Players = new ArrayList<>(); + // First Player is always the humain this.Players.add(new JoueurHumain(Deck, startMoney)); + // All other are controlled by the computer if (nbPlayer > 1) { for (int x = 1; x < nbPlayer; x++) { this.Players.add(new JoueurOrdinateur(Deck, startMoney)); @@ -27,69 +30,122 @@ public class GameManager { this.Dealer = new JoueurCroupier(Deck); } - public boolean ResolveTurn() { + // Phase 1 (StartTurn): + // Ask the player how much he wan't to bid + public void StartTurn() { - this.Dealer.DrawCard(0, this.Deck); + this.Step = 0; - // If the player has less than the minimum bid amount allowed - if (this.Players.get(0).GetMoney() <= 10) { - return true; - } + System.out.print("\033[H\033[2J"); + System.out.flush(); - this.Dealer.Reset(this.Deck); - for (Joueur Player : this.Players) { - Player.Reset(this.Deck); - } + System.out.println("*~-~* " + App.ANSI_RED + "BlackJack" + App.ANSI_RESET + " *~-~*\n"); - return false; - } + double bet; - public void PlayTurn() { + System.out.println("Money : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET); - boolean EndTurn = false; + // Ask the bid amount until a valide answer is given + while (true) { - while (!EndTurn) { + System.out.print("How much do you want to bet (Min. 10) ? "); - boolean CanSplit = false, CanInsure = false, CanDouble = false, CanDraw = false; + // Check that the input is an valid double + while (!App.in.hasNextDouble()) { + System.out.println(App.ANSI_YELLOW + "Please enter a valid number to bet." + App.ANSI_RESET); + System.out.print("How much do you want to bet (Min. 10) ?"); + App.in.next(); + } - System.out.print("\033[H\033[2J"); - System.out.flush(); + bet = App.in.nextDouble(); - System.out.println("*~-~* " + App.ANSI_RED + "BlackJack" + App.ANSI_RESET + " *~-~*\n"); + // Check if the player has enough money to place the bid + if (bet <= this.Players.get(0).GetMoney()) { - System.out.println("Cards in Deck : " + App.ANSI_GREEN + this.Deck.GetNbCards() + App.ANSI_RESET + "\n"); + // Check if the minimum bid amount it cleared + if (bet < 10) { + System.out.println(App.ANSI_YELLOW + "Minimum bid amount is 10." + App.ANSI_RESET); + } else { + break; + } - System.out.print("Dealer Score : " + App.ANSI_PURPLE); - if (this.Dealer.GetForce(0) == 99) { - System.out.println("BlackJack" + App.ANSI_RESET); } else { - System.out.println(this.Dealer.GetForce(0) + App.ANSI_RESET); + System.out.println(App.ANSI_YELLOW + "You don't have enough money." + App.ANSI_RESET); } - this.Dealer.ShowHands(); + } - System.out.println("\nMoney : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET); + // Set the player bid for this turn + Players.get(0).SetBet(bet, 0); + } - if (this.Players.get(0).HasInsured()) { - System.out.println("Insured : " + App.ANSI_BLUE + this.Players.get(0).GetInsured() + App.ANSI_RESET); - } + // Phase 2 (PlayTurn): + // Ask the player for all his interactions with this cards + public void PlayTurn() { + + boolean EndTurn = false, CanSplit = false, CanInsure = false, CanDouble = false, CanDraw = false; + + // Continue interacting with the player until all actions have been taken on all + // his hands + while (!EndTurn) { char choice = 'x'; + // Go thew all hands of the player for (int HandNb = 0; HandNb < this.Players.get(0).NbHands(); HandNb++) { + CanSplit = false; + CanInsure = false; + CanDouble = false; + CanDraw = false; + choice = 'x'; + + System.out.print("\033[H\033[2J"); + System.out.flush(); + + System.out.println("*~-~* " + App.ANSI_RED + "BlackJack" + App.ANSI_RESET + " *~-~*\n"); + + // Show the remaining amount of cards in the deck + System.out.println( + "Cards in Deck : " + App.ANSI_GREEN + this.Deck.GetNbCards() + App.ANSI_RESET + "\n"); + + // Dealer has only 1 card in his hand at this point in time + System.out.print("Dealer Strength : " + App.ANSI_PURPLE + this.Dealer.GetForce(0) + App.ANSI_RESET); + + // Show the dealer hand + this.Dealer.ShowHands(); + + // Show the current player balance + System.out.println("\nMoney : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET); + + // Check if the player has put down an insurance + if (this.Players.get(0).HasInsured()) { + System.out.println( + "Insured : " + App.ANSI_BLUE + this.Players.get(0).GetInsured() + App.ANSI_RESET); + } + + // Show the hand number of the player System.out .println("Bet on Hand " + App.ANSI_GREEN + (HandNb + 1) + App.ANSI_RESET + " : " + App.ANSI_BLUE + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET); + // Show the hand strength of the player + // 99 = BlackJack + // >21 = Busted + // <=21 = show the strength System.out - .print("Score of Hand " + App.ANSI_GREEN + (HandNb + 1) + App.ANSI_RESET + " : " + .print("Strength of Hand " + App.ANSI_GREEN + (HandNb + 1) + App.ANSI_RESET + " : " + App.ANSI_PURPLE); if (this.Players.get(0).GetForce(HandNb) == 99) { System.out.println("BlackJack" + App.ANSI_RESET); + } else if (this.Players.get(0).GetForce(HandNb) > 21) { + System.out.println( + this.Players.get(0).GetForce(HandNb) + App.ANSI_RED + " [BUSTED]" + App.ANSI_RESET); } else { System.out.println(this.Players.get(0).GetForce(HandNb) + App.ANSI_RESET); } - this.Players.get(0).ShowHands(); + + // Show the player hand + this.Players.get(0).ShowHand(HandNb); // Choices for player System.out.println("\n--- " + App.ANSI_GREEN + "Choices" + App.ANSI_RESET + " ---\n"); @@ -109,8 +165,11 @@ public class GameManager { // the 2 cards have the same strength) // AND // if we have less that 3 hands already (Max 2 splits) + // AND + // if the player has enough money if (this.Players.get(0).CanSplit(HandNb) - && this.Players.get(0).NbHands() < 3) { + && this.Players.get(0).NbHands() < 3 + && this.Players.get(0).GetBet(HandNb) <= this.Players.get(0).GetMoney()) { CanSplit = true; System.out.println(App.ANSI_BLUE + "[s]" + App.ANSI_RESET + " Split your Hand"); } @@ -121,9 +180,12 @@ public class GameManager { // if the hand has only 2 cards // AND // if the hand is not a BlackJack + // AND + // if the player has enough money if (!this.Players.get(0).HasDoubled(HandNb) && this.Players.get(0).NbCards(HandNb) == 2 - && this.Players.get(0).GetForce(HandNb) != 99) { + && this.Players.get(0).GetForce(HandNb) != 99 + && this.Players.get(0).GetBet(HandNb) <= this.Players.get(0).GetMoney()) { CanDouble = true; System.out.println(App.ANSI_BLUE + "[d]" + App.ANSI_RESET + " Double your Hand"); } @@ -134,89 +196,188 @@ public class GameManager { // if the hand has been splitted with a pair of Asses // AND // if the player has a BlackJack + // AND + // if the strength of the hand is more than 21 if (!(this.Players.get(0).HasDoubled(HandNb) && this.Players.get(0).NbCards(HandNb) == 3) - && !(this.Players.get(0).CanSplit(HandNb) && this.Players.get(0).GetCardForce(HandNb, 0) == 1) - && this.Players.get(0).GetForce(HandNb) != 99) { + && !(this.Players.get(0).HasSplit(HandNb) && this.Players.get(0).GetCardForce(HandNb, 0) == 1) + && this.Players.get(0).GetForce(HandNb) < 21) { CanDraw = true; System.out.println(App.ANSI_BLUE + "[h]" + App.ANSI_RESET + " Hit"); } - // Stand - System.out.println(App.ANSI_BLUE + "[s]" + App.ANSI_RESET + " Stand"); + // Keep (Stand) + System.out.println(App.ANSI_BLUE + "[k]" + App.ANSI_RESET + " Keep current Hand"); - if (CanInsure || CanSplit || CanDouble || CanDraw || this.Players.get(0).GetForce(HandNb) == 99) { + // Ask for the player choice until a valide one is given + while (true) { + System.out.print("> "); - while (true) { - System.out.print("> "); + choice = App.in.next().charAt(0); - choice = App.in.next().charAt(0); - - if ((choice == 'i' && CanInsure) || (choice == 's' && CanSplit) || (choice == 'd' && CanDouble) - || (choice == 'h' && CanDraw) - || choice == 's') { - break; - } else { - System.out.println(App.ANSI_YELLOW + "Please enter a valid choice." + App.ANSI_RESET); - } + // Choices are checked with available one for confirmation + if ((choice == 'i' && CanInsure) || (choice == 's' && CanSplit) || (choice == 'd' && CanDouble) + || (choice == 'h' && CanDraw) + || choice == 'k') { + break; + } else { + System.out.println(App.ANSI_YELLOW + "Please enter a valid choice." + App.ANSI_RESET); } } + // Hit if (choice == 'h') { this.Players.get(0).DrawCard(HandNb, this.Deck); + // Go back 1 hand to stay on the same hand in the for loop + HandNb--; + } + // Split + else if (choice == 's') { + this.Players.get(0).Split(HandNb, this.Deck); + // Go back 1 hand to stay on the same hand in the for loop + HandNb--; + } + // Double + else if (choice == 'd') { + this.Players.get(0).Double(HandNb, this.Deck); + // Go back 1 hand to stay on the same hand in the for loop + HandNb--; } Step++; } + // Insure if (choice == 'i') { this.Players.get(0).Insure(); EndTurn = false; - } else if (choice == 'h') { - EndTurn = false; - } else { + } + // If this point is reached (and not because of the insurance), all hands have + // been played + else { EndTurn = true; } } + } - public void StartTurn() { + // Phase 3 (ResolveTurn): + // Make the Dealer pick cards + // Do all the math for the player gains and losses + // Check if the player can continue et prepare for the next round + public boolean ResolveTurn() { - this.Step = 0; + // Dealer draws card until he hits 17 or more + while (this.Dealer.GetForce(0) <= 17) { + this.Dealer.DrawCard(0, this.Deck); + } System.out.print("\033[H\033[2J"); System.out.flush(); System.out.println("*~-~* " + App.ANSI_RED + "BlackJack" + App.ANSI_RESET + " *~-~*\n"); - double bet; + // Show the remaining amount of cards in the deck + System.out.println( + "Cards in Deck : " + App.ANSI_GREEN + this.Deck.GetNbCards() + App.ANSI_RESET + "\n"); + + // Show the hand strength of the dealer + // 99 = BlackJack + // >21 = Busted + // <=21 = show the strength + System.out.print("Dealer Score : " + App.ANSI_PURPLE); + if (this.Dealer.GetForce(0) == 99) { + System.out.println("BlackJack" + App.ANSI_RESET); + } else if (this.Dealer.GetForce(0) > 21) { + System.out.println(this.Dealer.GetForce(0) + App.ANSI_RED + " [BUSTED]" + App.ANSI_RESET); + } else { + System.out.println(this.Dealer.GetForce(0) + App.ANSI_RESET); + } - System.out.println("Money : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET); + // Show the dealers hand + this.Dealer.ShowHands(); - while (true) { + // Check if the player has put down an insurance + if (this.Players.get(0).HasInsured()) { + System.out.println( + "Insured : " + App.ANSI_BLUE + this.Players.get(0).GetInsured() + App.ANSI_RESET); + } - System.out.print("How much do you want to bet (Min. 10) ? "); + // Go thew all hands of the player + for (int HandNb = 0; HandNb < this.Players.get(0).NbHands(); HandNb++) { - while (!App.in.hasNextDouble()) { - System.out.println(App.ANSI_YELLOW + "Please enter a valid number to bet." + App.ANSI_RESET); - System.out.print("How much do you want to bet ?"); - App.in.next(); + System.out.println("\nHand " + App.ANSI_GREEN + (HandNb + 1) + App.ANSI_RESET + " :"); + + System.out.println("\tBet : " + App.ANSI_BLUE + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET); + + System.out.print("\tStrength : " + App.ANSI_PURPLE); + if (this.Players.get(0).GetForce(HandNb) == 99) { + System.out.println("BlackJack" + App.ANSI_RESET); + } else if (this.Players.get(0).GetForce(HandNb) > 21) { + System.out.println( + this.Players.get(0).GetForce(HandNb) + App.ANSI_RED + " [BUSTED]" + App.ANSI_RESET); + } else { + System.out.println(this.Players.get(0).GetForce(HandNb) + App.ANSI_RESET); } - bet = App.in.nextDouble(); + System.out.print("\tResult : "); + if (this.Players.get(0).GetForce(HandNb) > 21 && this.Players.get(0).GetForce(HandNb) != 99) { + System.out.println(App.ANSI_RED + "-" + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET); + } else if (this.Dealer.GetForce(0) == this.Players.get(0).GetForce(HandNb)) { + System.out.println(App.ANSI_BLUE + "±0" + App.ANSI_RESET); + this.Players.get(0).AddMoney(this.Players.get(0).GetBet(HandNb)); + } else if (this.Players.get(0).GetForce(HandNb) == 99) { + System.out.println(App.ANSI_GREEN + "+" + (this.Players.get(0).GetBet(HandNb) * 1.5) + App.ANSI_RESET); + this.Players.get(0).AddMoney(this.Players.get(0).GetBet(HandNb) * 2.5); + } else if (this.Dealer.GetForce(0) > 21 && this.Dealer.GetForce(0) != 99) { + System.out.println(App.ANSI_GREEN + "+" + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET); + this.Players.get(0).AddMoney(this.Players.get(0).GetBet(HandNb) * 2); + } else if (this.Players.get(0).GetForce(HandNb) < this.Dealer.GetForce(0)) { + System.out.println(App.ANSI_RED + "-" + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET); + } else if (this.Players.get(0).GetForce(HandNb) > this.Dealer.GetForce(0)) { + System.out.println(App.ANSI_GREEN + "+" + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET); + this.Players.get(0).AddMoney(this.Players.get(0).GetBet(HandNb) * 2); + } - if (bet <= this.Players.get(0).GetMoney()) { - if (bet < 10) { - System.out.println(App.ANSI_YELLOW + "Minimum bid amount is 10." + App.ANSI_RESET); - } else { - break; - } + } + + if (this.Players.get(0).HasInsured()) { + System.out.print("Insurance : "); + + if (this.Dealer.GetForce(0) == 99) { + System.out.println(App.ANSI_GREEN + "+" + (this.Players.get(0).GetInsured() * 3) + App.ANSI_RESET); + this.Players.get(0).AddMoney(this.Players.get(0).GetInsured() * 3); } else { - System.out.println(App.ANSI_YELLOW + "You don't have enough money." + App.ANSI_RESET); + System.out.println(App.ANSI_RED + "-" + (this.Players.get(0).GetInsured()) + App.ANSI_RESET); } } - Players.get(0).SetBet(bet, 0); + System.out.println("\nMoney : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET); + + System.out.print("> "); + + try { + System.in.read(); + } catch (Exception e) { + } + + // If the player has less than the minimum bid amount allowed + if (this.Players.get(0).GetMoney() <= 10) { + return true; + } + + // If more thn 75% of the Deck has been used, reshuffle all cards. In our case: + // simply recreate a new deck + if (this.Deck.GetNbCards() < 78) { + this.Deck = new JeudeCarte(new Paquet(6, 52)); + } + + this.Dealer.Reset(this.Deck); + for (Joueur Player : this.Players) { + Player.Reset(this.Deck); + } + + return false; } } diff --git a/Partie_2/src/main/java/ch/hepia/Hand.java b/Partie_2/src/main/java/ch/hepia/Hand.java index 449df4bd87f7294d66c600ef027bb615c16795dc..0006e501133c47f00ac6ba4d90a2ca19d081c8b9 100644 --- a/Partie_2/src/main/java/ch/hepia/Hand.java +++ b/Partie_2/src/main/java/ch/hepia/Hand.java @@ -41,6 +41,7 @@ public class Hand implements Comparable<Hand> { public void Double() { this.Doubled = true; + this.Bet *= 2; } public boolean HasSplit() { @@ -182,7 +183,7 @@ public class Hand implements Comparable<Hand> { public void ShowHand() { - this.SortHand(); + // this.SortHand(); for (Carte carte : Hand) { diff --git a/Partie_2/src/main/java/ch/hepia/Joueur.java b/Partie_2/src/main/java/ch/hepia/Joueur.java index d80144970b997e7368a1ff85157eaebc29344c82..fc142cd248ad5183f08340c2b51a4f31aea49390 100644 --- a/Partie_2/src/main/java/ch/hepia/Joueur.java +++ b/Partie_2/src/main/java/ch/hepia/Joueur.java @@ -22,12 +22,14 @@ interface Joueur { public void ShowHands(); - public void Split(int handNb); + public void Split(int handNb, JeudeCarte Jeu); public int GetForce(int handNb); public boolean CanSplit(int handNb); + public boolean HasSplit(int handNb); + public void Reset(JeudeCarte Jeu); public boolean HasInsured(); @@ -38,7 +40,7 @@ interface Joueur { public boolean HasDoubled(int handNb); - public void Double(int handNb); + public void Double(int handNb, JeudeCarte Jeu); public int NbHands(); @@ -81,19 +83,26 @@ class JoueurHumain implements Joueur { return this.Hands.get(handNb).HasDoubled(); } - public void Double(int handNb) { + public void Double(int handNb, JeudeCarte Jeu) { + this.RemoveMoney(this.Hands.get(handNb).GetBet()); this.Hands.get(handNb).Double(); + this.Hands.get(handNb).DrawCardFromGame(Jeu); } public boolean CanSplit(int handNb) { - if (!this.Hands.get(handNb).HasSplit() - && this.Hands.get(handNb).GetCarte(0).getForce() == this.Hands.get(handNb).GetCarte(1).getForce()) { + if (!(this.Hands.get(handNb).HasSplit() && this.Hands.get(handNb).GetCarte(0).getForce() == 1) + && this.Hands.get(handNb).GetCarte(0).getForce() == this.Hands.get(handNb).GetCarte(1).getForce() + && this.Hands.get(handNb).NbCard() == 2) { return true; } return false; } + public boolean HasSplit(int handNb) { + return this.Hands.get(handNb).HasSplit(); + } + public boolean HasInsured() { return this.Insured; } @@ -101,6 +110,7 @@ class JoueurHumain implements Joueur { public void Insure() { this.Insured = true; this.Insurance = this.Hands.get(0).GetBet() / 2; + this.RemoveMoney(this.Insurance); } public double GetInsured() { @@ -137,7 +147,14 @@ class JoueurHumain implements Joueur { } public int GetForce(int handNb) { - return this.Hands.get(handNb).GetForce(); + if ((this.Hands.get(handNb).GetForce() == 99 && this.Hands.get(handNb).HasSplit()) + || (this.Hands.get(handNb).GetForce() == 99 && handNb != 0) + || (this.Hands.get(handNb).GetForce() == 99 && this.Hands.get(handNb).NbCard() != 2)) { + return 21; + } else { + return this.Hands.get(handNb).GetForce(); + } + } public void SetBet(double amount, int handNb) { @@ -188,21 +205,26 @@ class JoueurHumain implements Joueur { this.Hands.get(handNb).ShowHand(); } - public void Split(int handNb) { + public void Split(int handNb, JeudeCarte Jeu) { if (this.Hands.size() == 3) { throw new RuntimeException("Max number of slipts."); - } else if (this.Hands.get(handNb).HasSplit()) { - throw new RuntimeException("Can't split Hand twice."); } - Carte card = this.Hands.get(handNb).GetCarte(handNb); + Carte card = this.Hands.get(handNb).GetCarte(1); + + this.Hands.add(new Hand(card)); this.Hands.get(handNb).RemoveCardFromHand(card); this.Hands.get(handNb).Splitted(); + this.Hands.get(this.Hands.size() - 1).Splitted(); - this.Hands.add(new Hand(card)); + this.Hands.get(this.Hands.size() - 1).SetBet(this.Hands.get(handNb).GetBet()); + this.RemoveMoney(this.Hands.get(handNb).GetBet()); + + this.Hands.get(handNb).DrawCardFromGame(Jeu); + this.Hands.get(this.Hands.size() - 1).DrawCardFromGame(Jeu); } public int NbHands() { @@ -246,20 +268,27 @@ class JoueurOrdinateur implements Joueur { return this.Hands.get(handNb).HasDoubled(); } - public void Double(int handNb) { + public void Double(int handNb, JeudeCarte Jeu) { + this.RemoveMoney(this.Hands.get(handNb).GetBet()); this.Hands.get(handNb).Double(); + this.Hands.get(handNb).DrawCardFromGame(Jeu); } public boolean CanSplit(int handNb) { - if (this.Hands.get(handNb).HasSplit() - || this.Hands.get(handNb).GetCarte(0).getForce() != this.Hands.get(handNb).GetCarte(1).getForce()) { - return false; + if (!(this.Hands.get(handNb).HasSplit() && this.Hands.get(handNb).GetCarte(0).getForce() == 1) + && this.Hands.get(handNb).GetCarte(0).getForce() == this.Hands.get(handNb).GetCarte(1).getForce() + && this.Hands.get(handNb).NbCard() == 2) { + return true; } return true; } + public boolean HasSplit(int handNb) { + return this.Hands.get(handNb).HasSplit(); + } + public boolean HasInsured() { return this.Insured; } @@ -271,6 +300,7 @@ class JoueurOrdinateur implements Joueur { public void Insure() { this.Insured = true; this.Insurance = this.Hands.get(0).GetBet() / 2; + this.RemoveMoney(this.Insurance); } public void Reset(JeudeCarte Jeu) { @@ -360,21 +390,26 @@ class JoueurOrdinateur implements Joueur { this.Hands.get(handNb).ShowHand(); } - public void Split(int handNb) { + public void Split(int handNb, JeudeCarte Jeu) { - if (Hands.size() == 3) { + if (this.Hands.size() == 3) { throw new RuntimeException("Max number of slipts."); - } else if (this.Hands.get(handNb).HasSplit()) { - throw new RuntimeException("Can't split Hand twice."); } - Carte card = this.Hands.get(handNb).GetCarte(handNb); + Carte card = this.Hands.get(handNb).GetCarte(1); + + this.Hands.add(new Hand(card)); this.Hands.get(handNb).RemoveCardFromHand(card); this.Hands.get(handNb).Splitted(); + this.Hands.get(this.Hands.size() - 1).Splitted(); - this.Hands.add(new Hand(card)); + this.Hands.get(this.Hands.size() - 1).SetBet(this.Hands.get(handNb).GetBet()); + this.RemoveMoney(this.Hands.get(handNb).GetBet()); + + this.Hands.get(handNb).DrawCardFromGame(Jeu); + this.Hands.get(this.Hands.size() - 1).DrawCardFromGame(Jeu); } public int NbHands() { @@ -422,13 +457,17 @@ class JoueurCroupier implements Joueur { throw new RuntimeException("Bank cant Double."); } - public void Double(int handNb) { + public void Double(int handNb, JeudeCarte Jeu) { // La Banque ne peut pas doubler throw new RuntimeException("Bank cant Double."); } public boolean CanSplit(int handNb) { + // La Banque ne peut pas split + throw new RuntimeException("Bank cant Split."); + } + public boolean HasSplit(int handNb) { // La Banque ne peut pas split throw new RuntimeException("Bank cant Split."); } @@ -504,7 +543,7 @@ class JoueurCroupier implements Joueur { return this.Hand.GetForce(); } - public void Split(int handNb) { + public void Split(int handNb, JeudeCarte Jeu) { // La Banque ne peut pas slip throw new RuntimeException("Bank can't Split."); } diff --git a/Partie_2/target/classes/ch/hepia/App.class b/Partie_2/target/classes/ch/hepia/App.class index 1e730631e4c898c9083ecffaf77a899ec69da689..7b2a1df8e106d74a6b78784c9f545cf4350d308a 100644 Binary files a/Partie_2/target/classes/ch/hepia/App.class and b/Partie_2/target/classes/ch/hepia/App.class differ diff --git a/Partie_2/target/classes/ch/hepia/GameManager.class b/Partie_2/target/classes/ch/hepia/GameManager.class index 0c1af52db05f54c74267841b06de56799bd9df50..aa63352e5ebc774b29262cbba7e764d0ba1f1ed2 100644 Binary files a/Partie_2/target/classes/ch/hepia/GameManager.class and b/Partie_2/target/classes/ch/hepia/GameManager.class differ diff --git a/Partie_2/target/classes/ch/hepia/Hand$1.class b/Partie_2/target/classes/ch/hepia/Hand$1.class index 7f75d8fe38a1822b70b602d9d7536438562761f5..aa652b46b36c5a4f704da400b85707c9489d2d20 100644 Binary files a/Partie_2/target/classes/ch/hepia/Hand$1.class and b/Partie_2/target/classes/ch/hepia/Hand$1.class differ diff --git a/Partie_2/target/classes/ch/hepia/Hand.class b/Partie_2/target/classes/ch/hepia/Hand.class index 22668a718d2fcdc679e7db293da325b101f7c2b1..8b98417991b333f0983a463db2bea69fec600b4e 100644 Binary files a/Partie_2/target/classes/ch/hepia/Hand.class and b/Partie_2/target/classes/ch/hepia/Hand.class differ diff --git a/Partie_2/target/classes/ch/hepia/Joueur.class b/Partie_2/target/classes/ch/hepia/Joueur.class index bcf855977f1b52f5f93a278ebe3557311fabd2ba..1af6aa5209a7ccec4a3d33ded164f65f26bfacb6 100644 Binary files a/Partie_2/target/classes/ch/hepia/Joueur.class and b/Partie_2/target/classes/ch/hepia/Joueur.class differ diff --git a/Partie_2/target/classes/ch/hepia/JoueurCroupier.class b/Partie_2/target/classes/ch/hepia/JoueurCroupier.class index e3fabea53944ae65b74e0e594f8ff39da4b162f3..876136367815a06b441cb6c838899103d693ada0 100644 Binary files a/Partie_2/target/classes/ch/hepia/JoueurCroupier.class and b/Partie_2/target/classes/ch/hepia/JoueurCroupier.class differ diff --git a/Partie_2/target/classes/ch/hepia/JoueurHumain.class b/Partie_2/target/classes/ch/hepia/JoueurHumain.class index 8d288dc186f39d3a4733813bb2aa020e68d3b710..9debc8be63144d904e9f87b6b480b14804ff24fb 100644 Binary files a/Partie_2/target/classes/ch/hepia/JoueurHumain.class and b/Partie_2/target/classes/ch/hepia/JoueurHumain.class differ diff --git a/Partie_2/target/classes/ch/hepia/JoueurOrdinateur.class b/Partie_2/target/classes/ch/hepia/JoueurOrdinateur.class index 2f71a0b80ecd3ac59ee101b5ef06748b16c8ec66..744d8a3ed0522b42651ca1ff2a0e437ba8688d6a 100644 Binary files a/Partie_2/target/classes/ch/hepia/JoueurOrdinateur.class and b/Partie_2/target/classes/ch/hepia/JoueurOrdinateur.class differ