diff --git a/Partie_3/src/main/java/ch/hepia/App.java b/Partie_3/src/main/java/ch/hepia/App.java index 000bcecbb346a9016299fff04596f095524bc727..eeac9451b948fbdd7753195b64a4da5cc81fed51 100644 --- a/Partie_3/src/main/java/ch/hepia/App.java +++ b/Partie_3/src/main/java/ch/hepia/App.java @@ -27,6 +27,7 @@ public class App { int numPlayers; int startMoney; + int computerStrategy = 1; // Ask the number of players until a valide answer is given while (true) { @@ -76,8 +77,34 @@ public class App { } } + // Ask if the Computer players should be smart of not + if (numPlayers > 1) { + while (true) { + + System.out.print("Should the Compter players be [1] Smart or [2] Stupid ? "); + + // Check that the input is an valid int + while (!App.in.hasNextInt()) { + System.out + .println(App.ANSI_YELLOW + "Please enter a valid choice." + App.ANSI_RESET); + System.out.print("Should the Compter players be [1] Smart or [2] Stupid ? "); + App.in.next(); + } + + computerStrategy = App.in.nextInt(); + + // Check if the value i s valide + if (computerStrategy == 1 || computerStrategy == 2) { + System.out.print(""); + break; + } else { + System.out.println(App.ANSI_YELLOW + "Please enter a valid choice." + App.ANSI_RESET); + } + } + } + // Create a new game - GameManager BlackJack = new GameManager(numPlayers, startMoney); + GameManager BlackJack = new GameManager(numPlayers, startMoney, computerStrategy); boolean GameOver = false; diff --git a/Partie_3/src/main/java/ch/hepia/GameManager.java b/Partie_3/src/main/java/ch/hepia/GameManager.java index ed86be6a73e16e88492deccb74b6770ca3e3d353..e5ce28379105e6514d69a11921c226f257d41b25 100644 --- a/Partie_3/src/main/java/ch/hepia/GameManager.java +++ b/Partie_3/src/main/java/ch/hepia/GameManager.java @@ -7,9 +7,10 @@ public class GameManager { private JeudeCarte Deck; private ArrayList<Joueur> Players; private JoueurCroupier Dealer; + private int ComputerPlayers; private int Step; - public GameManager(int nbPlayer, int startMoney) { + public GameManager(int nbPlayer, int startMoney, int computerStrategy) { // Create a new BlackJack Deck of card (6 x 52 cards game) this.Deck = new JeudeCarte(new Paquet(6, 52)); @@ -19,10 +20,13 @@ public class GameManager { // First Player is always the humain this.Players.add(new JoueurHumain(Deck, startMoney)); + this.ComputerPlayers = 0; + // All other are controlled by the computer if (nbPlayer > 1) { for (int x = 1; x < nbPlayer; x++) { - this.Players.add(new JoueurOrdinateur(Deck, startMoney)); + ComputerPlayers++; + this.Players.add(new JoueurOrdinateur(Deck, startMoney, computerStrategy)); } } @@ -75,6 +79,11 @@ public class GameManager { // Set the player bid for this turn Players.get(0).SetBet(bet, 0); + + // Set the Computer players bid for this turn + for (int x = 1; x <= this.ComputerPlayers; x++) { + Players.get(x).SetBet(10, 0); + } } // Phase 2 (PlayTurn): @@ -147,6 +156,28 @@ public class GameManager { // Show the player hand this.Players.get(0).ShowHand(HandNb); + // Show Computer Players hands + for (int x = 1; x <= this.ComputerPlayers; x++) { + for (int HandNbComputer = 0; HandNbComputer < this.Players.get(x).GetNbHands(); HandNbComputer++) { + System.out + .print("\nComputer " + App.ANSI_GREEN + x + App.ANSI_RESET + ", Money " + App.ANSI_BLUE + + this.Players.get(x).GetMoney() + App.ANSI_RESET + ", Hand " + + App.ANSI_GREEN + HandNbComputer + App.ANSI_RESET + ", Bet " + App.ANSI_BLUE + + this.Players.get(x).GetBet(HandNbComputer) + App.ANSI_RESET + ", Strength " + + App.ANSI_PURPLE); + if (this.Players.get(x).GetStrength(HandNbComputer) == 99) { + System.out.println("BlackJack" + App.ANSI_RESET + " :"); + } else if (this.Players.get(x).GetStrength(HandNbComputer) > 21) { + System.out.println( + this.Players.get(x).GetStrength(HandNbComputer) + App.ANSI_RED + " [BUSTED]" + + App.ANSI_RESET + " :"); + } else { + System.out.println(this.Players.get(x).GetStrength(HandNbComputer) + App.ANSI_RESET + " :"); + } + this.Players.get(x).ShowHand(HandNbComputer); + } + } + // Choices for player System.out.println("\n--- " + App.ANSI_GREEN + "Choices" + App.ANSI_RESET + " ---\n"); @@ -267,6 +298,23 @@ public class GameManager { // Check if the player can continue et prepare for the next round public boolean ResolveTurn() { + // Computer Players take turn to play + for (int x = 1; x <= this.ComputerPlayers; x++) { + + // Check there strategy + /* + * 1 = Smart + * 2 = Stupid + */ + if (this.Players.get(x).GetStrategy() == 1) { + + } else if (this.Players.get(x).GetStrategy() == 2) { + while (this.Players.get(x).GetStrength(0) <= 15) { + this.Players.get(x).DrawCard(0, this.Deck); + } + } + } + // Dealer draws card until he hits 17 or more while (this.Dealer.GetStrength(0) <= 17) { this.Dealer.DrawCard(0, this.Deck); @@ -303,6 +351,61 @@ public class GameManager { "Insured : " + App.ANSI_BLUE + this.Players.get(0).GetInsured() + App.ANSI_RESET); } + // Apply Computer Players Loss/Win + for (int x = 1; x <= this.ComputerPlayers; x++) { + for (int HandNbComputer = 0; HandNbComputer < this.Players.get(x).GetNbHands(); HandNbComputer++) { + // If the player is Busted (strength > 21 but not BlackJack (99)) + if (this.Players.get(x).GetStrength(HandNbComputer) > 21 + && this.Players.get(x).GetStrength(HandNbComputer) != 99) { + } + // If it's a Draw + else if (this.Dealer.GetStrength(0) == this.Players.get(x).GetStrength(HandNbComputer)) { + // Player get's back his bet + this.Players.get(x).AddMoney(this.Players.get(x).GetBet(HandNbComputer)); + } + // If the player has done a BlackJack + else if (this.Players.get(x).GetStrength(HandNbComputer) == 99) { + // Player gets payed 1.5 to 1 + this.Players.get(x).AddMoney(this.Players.get(x).GetBet(HandNbComputer) * 2.5); + } + // If the Dealer is Busted (strength > 21 but not BlackJack (99)) + else if (this.Dealer.GetStrength(0) > 21 && this.Dealer.GetStrength(0) != 99) { + // Player wins and get payed 1 to 1 + this.Players.get(x).AddMoney(this.Players.get(x).GetBet(HandNbComputer) * 2); + } + // If the Dealer has a better score + else if (this.Players.get(x).GetStrength(HandNbComputer) < this.Dealer.GetStrength(0)) { + } + // If the Player has a better score + else if (this.Players.get(x).GetStrength(HandNbComputer) > this.Dealer.GetStrength(0)) { + // Player wins and get payed 1 to 1 + this.Players.get(x).AddMoney(this.Players.get(x).GetBet(HandNbComputer) * 2); + } + } + } + + // Show Computer Players hands + for (int x = 1; x <= this.ComputerPlayers; x++) { + for (int HandNbComputer = 0; HandNbComputer < this.Players.get(x).GetNbHands(); HandNbComputer++) { + System.out + .print("\nComputer " + App.ANSI_GREEN + x + App.ANSI_RESET + ", Money " + App.ANSI_BLUE + + this.Players.get(x).GetMoney() + App.ANSI_RESET + ", Hand " + + App.ANSI_GREEN + HandNbComputer + App.ANSI_RESET + ", Bet " + App.ANSI_BLUE + + this.Players.get(x).GetBet(HandNbComputer) + App.ANSI_RESET + ", Strength " + + App.ANSI_PURPLE); + if (this.Players.get(x).GetStrength(HandNbComputer) == 99) { + System.out.println("BlackJack" + App.ANSI_RESET + " :"); + } else if (this.Players.get(x).GetStrength(HandNbComputer) > 21) { + System.out.println( + this.Players.get(x).GetStrength(HandNbComputer) + App.ANSI_RED + " [BUSTED]" + + App.ANSI_RESET + " :"); + } else { + System.out.println(this.Players.get(x).GetStrength(HandNbComputer) + App.ANSI_RESET + " :"); + } + this.Players.get(x).ShowHand(HandNbComputer); + } + } + // Go thew all hands of the player for (int HandNb = 0; HandNb < this.Players.get(0).GetNbHands(); HandNb++) { diff --git a/Partie_3/src/main/java/ch/hepia/Joueur.java b/Partie_3/src/main/java/ch/hepia/Joueur.java index 07d998787b9dcc9e0d5ba4435b31a4ed382085cb..036088f0018e7dab3436092c2cccd8948734adb2 100644 --- a/Partie_3/src/main/java/ch/hepia/Joueur.java +++ b/Partie_3/src/main/java/ch/hepia/Joueur.java @@ -4,8 +4,8 @@ import java.util.ArrayList; interface Joueur { - // Set the Play strategy - public void SetStrategy(); + // Get the Computer Player Strategy + public int GetStrategy(); // Add amount of money to the player balance public void AddMoney(double amount); @@ -93,7 +93,7 @@ class JoueurHumain implements Joueur { this.Insured = false; } - public void SetStrategy() { + public int GetStrategy() { // Human player has no strategy throw new RuntimeException("Humain Player has no Strategy."); } @@ -336,7 +336,13 @@ class JoueurOrdinateur implements Joueur { private double Insurance; private boolean Insured; - public JoueurOrdinateur(JeudeCarte Jeu, int Money) { + /* + * 1 = Smart + * 2 = Stupid + */ + private int Strategy; + + public JoueurOrdinateur(JeudeCarte Jeu, int Money, int Strategy) { this.Hands = new ArrayList<>(); @@ -348,11 +354,11 @@ class JoueurOrdinateur implements Joueur { this.Money = Money; this.Insurance = 0; this.Insured = false; + this.Strategy = Strategy; } - public void SetStrategy() { - // TODO - // Will be implemented in Part 3 of the project + public int GetStrategy() { + return this.Strategy; } public void AddMoney(double amount) { @@ -594,7 +600,7 @@ class JoueurCroupier implements Joueur { this.Hand = new Hand(Jeu, 1); } - public void SetStrategy() { + public int GetStrategy() { // Dealer has no strategy throw new RuntimeException("Dealer has no Strategy."); } diff --git a/Partie_3/target/classes/ch/hepia/App.class b/Partie_3/target/classes/ch/hepia/App.class index 7b2a1df8e106d74a6b78784c9f545cf4350d308a..2cd8ba87eca313ce79e1f20008967fe2848f2513 100644 Binary files a/Partie_3/target/classes/ch/hepia/App.class and b/Partie_3/target/classes/ch/hepia/App.class differ diff --git a/Partie_3/target/classes/ch/hepia/COULEUR.class b/Partie_3/target/classes/ch/hepia/COULEUR.class index c38a76f38b5f56aec3100849ad749e77c1255bcd..c582fd28bd308c74abcc31d7c543625ab96af75b 100644 Binary files a/Partie_3/target/classes/ch/hepia/COULEUR.class and b/Partie_3/target/classes/ch/hepia/COULEUR.class differ diff --git a/Partie_3/target/classes/ch/hepia/Carte.class b/Partie_3/target/classes/ch/hepia/Carte.class index bb77e1a2cf2b2c55d68d07f73a271f6ad870f1c6..f2e1b3556ab535a9579d8c800c12eb799aff3d01 100644 Binary files a/Partie_3/target/classes/ch/hepia/Carte.class and b/Partie_3/target/classes/ch/hepia/Carte.class differ diff --git a/Partie_3/target/classes/ch/hepia/GameManager.class b/Partie_3/target/classes/ch/hepia/GameManager.class index deab1ca162c602940cf4df190de3e8751b0ad034..73ed8bf9a6302d0a47db71fa3b031bb7bbb9c49e 100644 Binary files a/Partie_3/target/classes/ch/hepia/GameManager.class and b/Partie_3/target/classes/ch/hepia/GameManager.class differ diff --git a/Partie_3/target/classes/ch/hepia/Hand$1.class b/Partie_3/target/classes/ch/hepia/Hand$1.class index e2750c39ec1ee0ffda4f715b78a572443a2da898..2214bf48295c2e99569934bb083314370d6c1499 100644 Binary files a/Partie_3/target/classes/ch/hepia/Hand$1.class and b/Partie_3/target/classes/ch/hepia/Hand$1.class differ diff --git a/Partie_3/target/classes/ch/hepia/Hand.class b/Partie_3/target/classes/ch/hepia/Hand.class index a5d795896fe3549efa725a1873962850a6211e6f..6e99640898ba7d7dacac297d9754b15afd0dc13e 100644 Binary files a/Partie_3/target/classes/ch/hepia/Hand.class and b/Partie_3/target/classes/ch/hepia/Hand.class differ diff --git a/Partie_3/target/classes/ch/hepia/JeudeCarte$1.class b/Partie_3/target/classes/ch/hepia/JeudeCarte$1.class index e87f2ad85071fb1b622c4a955974eae6caf97a63..2735eb7c27de1aa52aa4584d2c1ef9d746a2b524 100644 Binary files a/Partie_3/target/classes/ch/hepia/JeudeCarte$1.class and b/Partie_3/target/classes/ch/hepia/JeudeCarte$1.class differ diff --git a/Partie_3/target/classes/ch/hepia/JeudeCarte.class b/Partie_3/target/classes/ch/hepia/JeudeCarte.class index 7c84a24a016f03fff7d97c2fd8eab208948f7fbf..ef19fe3892611f8ced9c139e6ced49f24319685c 100644 Binary files a/Partie_3/target/classes/ch/hepia/JeudeCarte.class and b/Partie_3/target/classes/ch/hepia/JeudeCarte.class differ diff --git a/Partie_3/target/classes/ch/hepia/Joueur.class b/Partie_3/target/classes/ch/hepia/Joueur.class index 5e4728e620596c8ce4d971e1d94e4d16b7f6bac8..cec581d3b0582175934534582a999fa29a5d8288 100644 Binary files a/Partie_3/target/classes/ch/hepia/Joueur.class and b/Partie_3/target/classes/ch/hepia/Joueur.class differ diff --git a/Partie_3/target/classes/ch/hepia/JoueurCroupier.class b/Partie_3/target/classes/ch/hepia/JoueurCroupier.class index 1a117b2e6248aecff4b395b75018848c471b8526..9a717ff4c56ce683fff710ba2f2f33ca8966b558 100644 Binary files a/Partie_3/target/classes/ch/hepia/JoueurCroupier.class and b/Partie_3/target/classes/ch/hepia/JoueurCroupier.class differ diff --git a/Partie_3/target/classes/ch/hepia/JoueurHumain.class b/Partie_3/target/classes/ch/hepia/JoueurHumain.class index 733a8e929c37ad44af07e0311c79cabaeee685a9..f48be18eb326b030e967eb4fcd4a691e8fb62038 100644 Binary files a/Partie_3/target/classes/ch/hepia/JoueurHumain.class and b/Partie_3/target/classes/ch/hepia/JoueurHumain.class differ diff --git a/Partie_3/target/classes/ch/hepia/JoueurOrdinateur.class b/Partie_3/target/classes/ch/hepia/JoueurOrdinateur.class index b83e6a0bea0dd6f64078eaf509636401c3c5324e..5d518578ec450182ac80c003ccfe22567f6000dd 100644 Binary files a/Partie_3/target/classes/ch/hepia/JoueurOrdinateur.class and b/Partie_3/target/classes/ch/hepia/JoueurOrdinateur.class differ diff --git a/Partie_3/target/classes/ch/hepia/Paquet.class b/Partie_3/target/classes/ch/hepia/Paquet.class index 79dc7afd66ab47cc77bb82fcf6c5682425eccc23..287773450d9a2e8fcd9120c796067e1f9f2a10cf 100644 Binary files a/Partie_3/target/classes/ch/hepia/Paquet.class and b/Partie_3/target/classes/ch/hepia/Paquet.class differ diff --git a/Partie_3/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/Partie_3/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 8643c6b1229fa6a0b75a7a07c874984c3b9ad5f8..127925b311677c80a5bd237e82f96ceaac2d73ed 100644 --- a/Partie_3/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/Partie_3/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1,7 +1,7 @@ -/home/padi/Git/java-card-game/Partie_2/src/main/java/ch/hepia/Hand.java -/home/padi/Git/java-card-game/Partie_2/src/main/java/ch/hepia/Carte.java -/home/padi/Git/java-card-game/Partie_2/src/main/java/ch/hepia/Joueur.java -/home/padi/Git/java-card-game/Partie_2/src/main/java/ch/hepia/GameManager.java -/home/padi/Git/java-card-game/Partie_2/src/main/java/ch/hepia/App.java -/home/padi/Git/java-card-game/Partie_2/src/main/java/ch/hepia/Paquet.java -/home/padi/Git/java-card-game/Partie_2/src/main/java/ch/hepia/JeudeCarte.java +/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Paquet.java +/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Joueur.java +/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/App.java +/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Hand.java +/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Carte.java +/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/GameManager.java +/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/JeudeCarte.java