diff --git a/Partie_3_GUI/img/deck.png b/Partie_3_GUI/img/deck.png new file mode 100644 index 0000000000000000000000000000000000000000..d4d66d7417325d1c577fc826c72b97d9507c1a34 Binary files /dev/null and b/Partie_3_GUI/img/deck.png differ diff --git a/Partie_3_GUI/img/money.png b/Partie_3_GUI/img/money.png new file mode 100644 index 0000000000000000000000000000000000000000..939e7e13349715907c755c4c6cd7041cbfb2c289 Binary files /dev/null and b/Partie_3_GUI/img/money.png differ diff --git a/Partie_3_GUI/save.csv b/Partie_3_GUI/save.csv index b407c144fbb472b4528733a32bc5b9e5523974d5..aabf4d639bbbd3f6dba3520d462d164909530cf5 100644 --- a/Partie_3_GUI/save.csv +++ b/Partie_3_GUI/save.csv @@ -1,3 +1,3 @@ -Human,110.0,0 -Player_1,190.0,1 -Player_2,305.0,1 \ No newline at end of file +Human,90.0,0,0 +Player_1,180.0,1,false +Player_2,2.0,1,true \ No newline at end of file diff --git a/Partie_3_GUI/src/main/java/ch/hepia/BlackjackGUI.java b/Partie_3_GUI/src/main/java/ch/hepia/BlackjackGUI.java index 4598e091c1c6f1d7026fa627c064d079ffbd33a1..109fc53c7ec5ac1211b773a6fb50e133cd31a1b8 100644 --- a/Partie_3_GUI/src/main/java/ch/hepia/BlackjackGUI.java +++ b/Partie_3_GUI/src/main/java/ch/hepia/BlackjackGUI.java @@ -43,24 +43,13 @@ public class BlackjackGUI extends Application { if (loaded) { Save Game = new Save(); - BlackJack = new GameManager(Game.loadMoney(), Game.loadStrategy()); + BlackJack = new GameManager(Game.loadMoney(), Game.loadStrategy(), Game.loadGameOver()); } else { BlackJack = new GameManager(nbPlayer, startMoney, aiStrength); } BlackJack.StartTurn(primaryStage); - // boolean GameOver = false; - - /* - * while (!GameOver) { - * BlackJack.StartTurn(primaryStage); - * BlackJack.PlayTurn(primaryStage); - * GameOver = BlackJack.ResolveTurn(primaryStage); - * } - */ - - // primaryStage.close(); } @Override diff --git a/Partie_3_GUI/src/main/java/ch/hepia/GameManager.java b/Partie_3_GUI/src/main/java/ch/hepia/GameManager.java index 01f0f8681180af66735a20560fbe42f223d8e00a..ca8423b93c7c546390778afcdbe23953366e30de 100644 --- a/Partie_3_GUI/src/main/java/ch/hepia/GameManager.java +++ b/Partie_3_GUI/src/main/java/ch/hepia/GameManager.java @@ -10,12 +10,10 @@ import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.BackgroundImage; import javafx.scene.layout.BackgroundPosition; import javafx.scene.layout.BackgroundRepeat; import javafx.scene.layout.BackgroundSize; -import javafx.scene.layout.CornerRadii; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; @@ -24,6 +22,7 @@ import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; +import javafx.scene.transform.Rotate; import javafx.stage.Stage; import javafx.beans.value.*; @@ -61,7 +60,7 @@ public class GameManager { this.Dealer = new JoueurCroupier(Deck); } - public GameManager(ArrayList<Double> Money, ArrayList<Integer> Strategy) { + public GameManager(ArrayList<Double> Money, ArrayList<Integer> Strategy, ArrayList<Boolean> GameOver) { // Create a new BlackJack Deck of card (6 x 52 cards game) this.Deck = new JeudeCarte(new Paquet(6, 52)); @@ -78,8 +77,10 @@ public class GameManager { // All other are controlled by the computer if (Money.size() > 1) { for (int x = 1; x < Money.size(); x++) { - ComputerPlayers++; - this.Players.add(new JoueurOrdinateur(Deck, Money.get(x), Strategy.get(x))); + if (!GameOver.get(x)) { + ComputerPlayers++; + this.Players.add(new JoueurOrdinateur(Deck, Money.get(x), Strategy.get(x))); + } } } @@ -216,7 +217,7 @@ public class GameManager { } layout.setVisible(false); - + PlayTurn(primaryStage); } }); @@ -235,220 +236,298 @@ public class GameManager { // Ask the player for all his interactions with this cards public void PlayTurn(Stage primaryStage) { - boolean EndTurn = false, CanSplit = false, CanInsure = false, CanDouble = false, CanDraw = false; + Image backgroundImage = new Image("file:img/background.jpg"); + BackgroundImage background = new BackgroundImage( + backgroundImage, + BackgroundRepeat.NO_REPEAT, + BackgroundRepeat.NO_REPEAT, + BackgroundPosition.CENTER, + new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, false, false, true, true)); - // Continue interacting with the player until all actions have been taken on all - // his hands - while (!EndTurn) { + StackPane root = new StackPane(); + root.setBackground(new Background(background)); - char choice = 'x'; + Image dealerCard = new Image("file:img/" + this.Dealer.GetCard(0, 0) + ".png"); + ImageView dealerCardView = new ImageView(dealerCard); + dealerCardView.setFitHeight(150); + dealerCardView.setPreserveRatio(true); - // Go thew all hands of the player - for (int HandNb = 0; HandNb < this.Players.get(0).GetNbHands(); HandNb++) { + Image playerCard1 = new Image("file:img/" + this.Players.get(0).GetCard(0, 0) + ".png"); + ImageView playerCard1View = new ImageView(playerCard1); + playerCard1View.setFitHeight(150); + Rotate rotate1 = new Rotate(); + rotate1.setPivotX(50); + rotate1.setPivotY(playerCard1View.getFitWidth() / 2); + playerCard1View.getTransforms().add(rotate1); + rotate1.setAngle(-20); + playerCard1View.setPreserveRatio(true); - CanSplit = false; - CanInsure = false; - CanDouble = false; - CanDraw = false; - choice = 'x'; + Image playerCard2 = new Image("file:img/" + this.Players.get(0).GetCard(0, 1) + ".png"); + ImageView playerCard2View = new ImageView(playerCard2); + playerCard2View.setFitHeight(150); + Rotate rotate2 = new Rotate(); + rotate2.setPivotX(50); + rotate2.setPivotY(playerCard2View.getFitWidth() / 2); + playerCard2View.getTransforms().add(rotate2); + rotate2.setAngle(20); + playerCard2View.setPreserveRatio(true); - System.out.print("\033[H\033[2J"); - System.out.flush(); + Image deckImage = new Image("file:img/deck.png"); + ImageView deckView = new ImageView(deckImage); + deckView.setFitHeight(50); + deckView.setPreserveRatio(true); - // System.out.println("*~-~* " + App.ANSI_RED + "BlackJack" + App.ANSI_RESET + " - // *~-~*\n"); + Image moneyImage = new Image("file:img/money.png"); + ImageView moneyView = new ImageView(moneyImage); + moneyView.setFitHeight(50); + moneyView.setPreserveRatio(true); - // 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"); + Text cardsInDeck = new Text(String.valueOf(this.Deck.GetNbCards())); + cardsInDeck.setFill(Color.WHITE); + cardsInDeck.setFont(Font.font("Courier New", FontWeight.BOLD, 20)); - // Dealer has only 1 card in his hand at this point in time - // System.out.println("Dealer Strength : " + App.ANSI_PURPLE + - // this.Dealer.GetStrength(0) + App.ANSI_RESET); + Text moneyPlayer = new Text(String.valueOf(this.Players.get(0).GetMoney())); + moneyPlayer.setFill(Color.WHITE); + moneyPlayer.setFont(Font.font("Courier New", FontWeight.BOLD, 20)); - // Show the dealer hand - this.Dealer.ShowHands(); + HBox deckBox = new HBox(5); + deckBox.getChildren().addAll(deckView, cardsInDeck); + deckBox.setAlignment(Pos.CENTER_LEFT); - // Show the current player balance - // System.out.println("\nMoney : " + App.ANSI_BLUE + - // this.Players.get(0).GetMoney() + App.ANSI_RESET); + HBox moneyBox = new HBox(5); + moneyBox.getChildren().addAll(moneyView, moneyPlayer); + moneyBox.setAlignment(Pos.CENTER_LEFT); - // 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); - } + VBox moneyDeckBox = new VBox(5); + moneyDeckBox.getChildren().addAll(deckBox, moneyBox); + moneyDeckBox.setAlignment(Pos.CENTER_LEFT); - // 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); + HBox dealerCardsBox = new HBox(10); + dealerCardsBox.getChildren().add(dealerCardView); + dealerCardsBox.setAlignment(Pos.TOP_CENTER); - // Show the hand strength of the player - // 99 = BlackJack - // >21 = Busted - // <=21 = show the strength - // System.out.print("Strength of Hand " + App.ANSI_GREEN + (HandNb + 1) + - // App.ANSI_RESET + " : "+ App.ANSI_PURPLE); - if (this.Players.get(0).GetStrength(HandNb) == 99) { - // System.out.println("BlackJack" + App.ANSI_RESET); - } else if (this.Players.get(0).GetStrength(HandNb) > 21) { - // System.out.println(this.Players.get(0).GetStrength(HandNb) + App.ANSI_RED + " - // [BUSTED]" + App.ANSI_RESET); - } else { - // System.out.println(this.Players.get(0).GetStrength(HandNb) + App.ANSI_RESET); - } + Text strengthDealer = new Text(String.valueOf(this.Dealer.GetStrength(0))); + strengthDealer.setFill(Color.WHITE); + strengthDealer.setTextAlignment(TextAlignment.CENTER); + strengthDealer.setFont(Font.font("Courier New", FontWeight.BOLD, 30)); - // 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"); - - // Insurance - // Can only insure if it's the first thing that the players does - // AND - // That he hasn't already insured during this round - if (this.Step == 0 && this.Dealer.HasOnlyAs() - && !this.Players.get(0).HasInsured()) { - CanInsure = true; - // System.out.println(App.ANSI_BLUE + "[i]" + App.ANSI_RESET + " Insurance - // against Dealer"); - } + VBox dealerCardsStrengthBox = new VBox(20); + dealerCardsStrengthBox.getChildren().addAll(dealerCardsBox, strengthDealer); + dealerCardsStrengthBox.setAlignment(Pos.TOP_CENTER); - // Split - // Can only split if this hand can be split (if it wasn't already split AND if - // 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).GetNbHands() < 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"); - } + HBox playerCardsBox = new HBox(10); + playerCardsBox.getChildren().addAll(playerCard1View, playerCard2View); + playerCardsBox.setAlignment(Pos.TOP_CENTER); - // Double - // Can only double if this hand wasn't already doubled - // AND - // 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).GetNbCards(HandNb) == 2 - && this.Players.get(0).GetStrength(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"); - } + Text strengthHand1 = new Text(String.valueOf(this.Players.get(0).GetStrength(0))); + strengthHand1.setFill(Color.WHITE); + strengthHand1.setTextAlignment(TextAlignment.CENTER); + strengthHand1.setFont(Font.font("Courier New", FontWeight.BOLD, 30)); - // Draw a Card (Hit) - // Can NOT draw if this hand was doubled AND has already 3 cards - // AND - // 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).GetNbCards(HandNb) == 3) - && !(this.Players.get(0).HasSplit(HandNb) - && this.Players.get(0).GetCardStrength(HandNb, 0) == 1) - && this.Players.get(0).GetStrength(HandNb) < 21) { - CanDraw = true; - // System.out.println(App.ANSI_BLUE + "[h]" + App.ANSI_RESET + " Hit"); - } + VBox playerCardsStrengthBox = new VBox(20); + playerCardsStrengthBox.getChildren().addAll(strengthHand1, playerCardsBox); + playerCardsStrengthBox.setAlignment(Pos.TOP_CENTER); - // Keep (Stand) - // System.out.println(App.ANSI_BLUE + "[k]" + App.ANSI_RESET + " Keep current - // Hand"); - - // Ask for the player choice until a valide one is given - /* - * while (true) { - * System.out.print("> "); - * - * choice = App.in.next().charAt(0); - * - * // 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--; - } + HBox actions = new HBox(10); + actions.setAlignment(Pos.BOTTOM_CENTER); - Step++; - } + StackPane deckMoney = new StackPane(); - // Insure - if (choice == 'i') { - this.Players.get(0).Insure(); - EndTurn = false; - } - // If this point is reached (and not because of the insurance), all hands have - // been played - else { - EndTurn = true; - } - } + StackPane dealer = new StackPane(); + + StackPane player = new StackPane(); + + dealer.getChildren().add(dealerCardsStrengthBox); + player.getChildren().addAll(playerCardsStrengthBox, actions); + deckMoney.getChildren().add(moneyDeckBox); + + deckMoney.setTranslateX(5); + + dealer.setTranslateY(50); + + player.setTranslateY(primaryStage.getHeight() - 175 - player.getBoundsInLocal().getHeight()); + + root.getChildren().addAll(deckMoney, dealer, player); + + Scene scene_4 = new Scene(root, 1400, 800); + + primaryStage.setScene(scene_4); + + // 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("Strength of Hand " + App.ANSI_GREEN + (HandNb + 1) + + // App.ANSI_RESET + " : "+ App.ANSI_PURPLE); + // if (this.Players.get(0).GetStrength(HandNb) == 99) { + // System.out.println("BlackJack" + App.ANSI_RESET); + // } else if (this.Players.get(0).GetStrength(HandNb) > 21) { + // System.out.println(this.Players.get(0).GetStrength(HandNb) + App.ANSI_RED + " + // [BUSTED]" + App.ANSI_RESET); + // } else { + // System.out.println(this.Players.get(0).GetStrength(HandNb) + App.ANSI_RESET); + // } + + // 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"); + + // Insurance + // Can only insure if it's the first thing that the players does + // AND + // That he hasn't already insured during this round + // if (this.Step == 0 && this.Dealer.HasOnlyAs() + // && !this.Players.get(0).HasInsured()) { + // CanInsure = true; + // System.out.println(App.ANSI_BLUE + "[i]" + App.ANSI_RESET + " Insurance + // against Dealer"); + // } + + // Split + // Can only split if this hand can be split (if it wasn't already split AND if + // 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).GetNbHands() < 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"); + // } + + // Double + // Can only double if this hand wasn't already doubled + // AND + // 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).GetNbCards(HandNb) == 2 + // && this.Players.get(0).GetStrength(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"); + // } + + // Draw a Card (Hit) + // Can NOT draw if this hand was doubled AND has already 3 cards + // AND + // 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).GetNbCards(HandNb) == 3) + // && !(this.Players.get(0).HasSplit(HandNb) + // && this.Players.get(0).GetCardStrength(HandNb, 0) == 1) + // && this.Players.get(0).GetStrength(HandNb) < 21) { + // CanDraw = true; + // System.out.println(App.ANSI_BLUE + "[h]" + App.ANSI_RESET + " Hit"); + // } + + // Keep (Stand) + // System.out.println(App.ANSI_BLUE + "[k]" + App.ANSI_RESET + " Keep current + // Hand"); + + // Ask for the player choice until a valide one is given + /* + * while (true) { + * System.out.print("> "); + * + * choice = App.in.next().charAt(0); + * + * // 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; + // } + // If this point is reached (and not because of the insurance), all hands have + // been played + // else { + // EndTurn = true; + // } } diff --git a/Partie_3_GUI/src/main/java/ch/hepia/Joueur.java b/Partie_3_GUI/src/main/java/ch/hepia/Joueur.java index e69d341308e200397ff706a20aab3267e9d0019c..5233df9f951faa0aa5b0189460162e83982f1979 100644 --- a/Partie_3_GUI/src/main/java/ch/hepia/Joueur.java +++ b/Partie_3_GUI/src/main/java/ch/hepia/Joueur.java @@ -31,6 +31,9 @@ interface Joueur { // Get number of cards in specific hand public int GetNbCards(int handNb); + // Get specific card of specific hand + public String GetCard(int handNb, int cardNb); + // Show specific hand in terminal public void ShowHand(int handNb); @@ -67,6 +70,12 @@ interface Joueur { // Has the player insured himself public boolean HasInsured(); + // Set the player game status + public void SetGameOver(boolean state); + + // Is the player game status + public boolean IsGameOver(); + // Reset player for next turn public void Reset(JeudeCarte Jeu); } @@ -181,6 +190,22 @@ class JoueurHumain implements Joueur { return this.Hands.get(handNb).NbCard(); } + public String GetCard(int handNb, int cardNb) { + + // Check if the hand ID is valide + if (handNb < 0 || handNb > Hands.size()) { + throw new RuntimeException("Hand number not valid."); + } + + // Check if the Card ID is valide + if (cardNb < 0 || cardNb > Hands.get(handNb).NbCard()) { + throw new RuntimeException("Card number not valid."); + } + + // Get Card String + return this.Hands.get(handNb).GetCarte(cardNb).getNomComplet(); + } + public void ShowHand(int handNb) { // Check if the hand ID is valide @@ -314,6 +339,16 @@ class JoueurHumain implements Joueur { return this.Insured; } + public void SetGameOver(boolean state) { + // Human Player doesn't GameOver like That + throw new RuntimeException("Human Player doesn't GameOver like That."); + } + + public boolean IsGameOver() { + // Human Player can't be in state GameOver + throw new RuntimeException("Human Player can't be in state GameOver."); + } + public void Reset(JeudeCarte Jeu) { this.Insured = false; @@ -335,6 +370,7 @@ class JoueurOrdinateur implements Joueur { private double Money; private double Insurance; private boolean Insured; + private boolean GameOver; /* * 1 = Smart @@ -354,6 +390,24 @@ class JoueurOrdinateur implements Joueur { this.Money = Money; this.Insurance = 0; this.Insured = false; + this.GameOver = false; + + this.Strategy = Strategy; + } + + public JoueurOrdinateur(JeudeCarte Jeu, double Money, int Strategy, boolean GameOver) { + + this.Hands = new ArrayList<>(); + + // At creation, player get's 1 hand with 2 cards + Hands.add(new Hand(Jeu, 2)); + + Hands.get(0).SetBet(0); + + this.Money = Money; + this.Insurance = 0; + this.Insured = false; + this.GameOver = GameOver; this.Strategy = Strategy; } @@ -456,6 +510,22 @@ class JoueurOrdinateur implements Joueur { this.Hands.get(handNb).ShowHand(); } + public String GetCard(int handNb, int cardNb) { + + // Check if the hand ID is valide + if (handNb < 0 || handNb > Hands.size()) { + throw new RuntimeException("Hand number not valid."); + } + + // Check if the Card ID is valide + if (cardNb < 0 || cardNb > Hands.get(handNb).NbCard()) { + throw new RuntimeException("Card number not valid."); + } + + // Get Card String + return this.Hands.get(handNb).GetCarte(cardNb).getNomComplet(); + } + public void ShowHands() { // Go threw all hands @@ -578,17 +648,31 @@ class JoueurOrdinateur implements Joueur { return this.Insured; } + public void SetGameOver(boolean state) { + this.GameOver = state; + } + + public boolean IsGameOver() { + return this.GameOver; + } + public void Reset(JeudeCarte Jeu) { - this.Insured = false; + if (!this.IsGameOver() && this.GetMoney() >= 10) { - // Reset hands - this.Hands = new ArrayList<>(); + this.Insured = false; - // Draw 2 card from Deck - this.Hands.add(new Hand(Jeu, 2)); + // Reset hands + this.Hands = new ArrayList<>(); + + // Draw 2 card from Deck + this.Hands.add(new Hand(Jeu, 2)); + + this.Hands.get(0).SetBet(0); + } else { + this.SetGameOver(true); + } - this.Hands.get(0).SetBet(0); } } @@ -650,6 +734,22 @@ class JoueurCroupier implements Joueur { return this.Hand.NbCard(); } + public String GetCard(int handNb, int cardNb) { + + // Check if the hand ID is valide + if (handNb != 0) { + throw new RuntimeException("Dealer has only 1 hand."); + } + + // Check if the Card ID is valide + if (cardNb < 0 || cardNb > Hand.NbCard()) { + throw new RuntimeException("Card number not valid."); + } + + // Get Card String + return this.Hand.GetCarte(cardNb).getNomComplet(); + } + public void ShowHand(int handNb) { // Dealer has only 1 hand @@ -739,6 +839,16 @@ class JoueurCroupier implements Joueur { } + public void SetGameOver(boolean state) { + // Dealer can't GameOver + throw new RuntimeException("Dealer can't GameOver."); + } + + public boolean IsGameOver() { + // Dealer can't GameOver + throw new RuntimeException("Dealer can't GameOver."); + } + public void Reset(JeudeCarte Jeu) { // Create a new hand with 1 card diff --git a/Partie_3_GUI/src/main/java/ch/hepia/Save.java b/Partie_3_GUI/src/main/java/ch/hepia/Save.java index d66eaa2917f5d6490e862edd6cc920a6ecb9043b..084c583d067b1eaa68dddf41649ed3f7991c3351 100644 --- a/Partie_3_GUI/src/main/java/ch/hepia/Save.java +++ b/Partie_3_GUI/src/main/java/ch/hepia/Save.java @@ -28,7 +28,7 @@ public class Save { CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END); - String[] data = { "Human", Double.toString(Players.get(0).GetMoney()), "0" }; + String[] data = { "Human", Double.toString(Players.get(0).GetMoney()), "0", "false" }; writer.writeNext(data); @@ -37,6 +37,7 @@ public class Save { data[0] = "Player_" + x; data[1] = Double.toString(Players.get(x).GetMoney()); data[2] = Integer.toString(Players.get(x).GetStrategy()); + data[3] = Boolean.toString(Players.get(x).IsGameOver()); writer.writeNext(data); } @@ -97,4 +98,28 @@ public class Save { return Strategy; } + + public ArrayList<Boolean> loadGameOver() { + + File file = new File("save.csv"); + + ArrayList<Boolean> Strategy = new ArrayList<>(); + + try { + + List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); + + for (String string : lines) { + + String[] array = string.split(","); + + Strategy.add(Boolean.valueOf(array[3])); + } + + } catch (IOException e) { + e.printStackTrace(); + } + + return Strategy; + } } diff --git a/Partie_3_GUI/target/classes/ch/hepia/BlackjackGUI$1.class b/Partie_3_GUI/target/classes/ch/hepia/BlackjackGUI$1.class index 0108bfa7beeb341799a40b35a1d2f409ab7042bb..dfb5471cba8b04ad6653a41ecd555366c06feec5 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/BlackjackGUI$1.class and b/Partie_3_GUI/target/classes/ch/hepia/BlackjackGUI$1.class differ diff --git a/Partie_3_GUI/target/classes/ch/hepia/BlackjackGUI.class b/Partie_3_GUI/target/classes/ch/hepia/BlackjackGUI.class index 99b73da8cdc04a71b6522bf8776c23ecdd313229..6fe366d35383b346eafd305a8fc28ad162058b8a 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/BlackjackGUI.class and b/Partie_3_GUI/target/classes/ch/hepia/BlackjackGUI.class differ diff --git a/Partie_3_GUI/target/classes/ch/hepia/GameManager$1.class b/Partie_3_GUI/target/classes/ch/hepia/GameManager$1.class index cf32a393bd62ad299b967bad90ea50167be45046..82b531d2386cff7bfa2ecf229689f10a12ca232e 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/GameManager$1.class and b/Partie_3_GUI/target/classes/ch/hepia/GameManager$1.class differ diff --git a/Partie_3_GUI/target/classes/ch/hepia/GameManager.class b/Partie_3_GUI/target/classes/ch/hepia/GameManager.class index ef64cca08dec5fb70b0de12ed32d495f51e0441d..49bf11c8df1da0c4591bec6005fb9144658e718e 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/GameManager.class and b/Partie_3_GUI/target/classes/ch/hepia/GameManager.class differ diff --git a/Partie_3_GUI/target/classes/ch/hepia/Joueur.class b/Partie_3_GUI/target/classes/ch/hepia/Joueur.class index cec581d3b0582175934534582a999fa29a5d8288..e2f4d163f308ff95389ba16accd06a18a2a648e8 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/Joueur.class and b/Partie_3_GUI/target/classes/ch/hepia/Joueur.class differ diff --git a/Partie_3_GUI/target/classes/ch/hepia/JoueurCroupier.class b/Partie_3_GUI/target/classes/ch/hepia/JoueurCroupier.class index 1d0bb3797ec4281bcbc48e36763785c6e864c086..ee10f8ced66ab7b4ff9eb559374349b52fe989cf 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/JoueurCroupier.class and b/Partie_3_GUI/target/classes/ch/hepia/JoueurCroupier.class differ diff --git a/Partie_3_GUI/target/classes/ch/hepia/JoueurHumain.class b/Partie_3_GUI/target/classes/ch/hepia/JoueurHumain.class index 068028eff942eafbe3b36e821e7fc43a0fe1309b..b347b0df66a226ff911963b22b6328f62b306db3 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/JoueurHumain.class and b/Partie_3_GUI/target/classes/ch/hepia/JoueurHumain.class differ diff --git a/Partie_3_GUI/target/classes/ch/hepia/JoueurOrdinateur.class b/Partie_3_GUI/target/classes/ch/hepia/JoueurOrdinateur.class index e8925bd7d60d537103d49935df82fae23c2b1f36..98bf239de9c4ba25f246d073e32bb3c8431c22e4 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/JoueurOrdinateur.class and b/Partie_3_GUI/target/classes/ch/hepia/JoueurOrdinateur.class differ diff --git a/Partie_3_GUI/target/classes/ch/hepia/Save.class b/Partie_3_GUI/target/classes/ch/hepia/Save.class index 9573a2e368dea090dc72a1674ce1aa82a9c79b87..39aa445e9a2eb5d5b6624a59c5c69096c77c1227 100644 Binary files a/Partie_3_GUI/target/classes/ch/hepia/Save.class and b/Partie_3_GUI/target/classes/ch/hepia/Save.class differ diff --git a/Partie_3_GUI/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/Partie_3_GUI/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 639a23cb9cc4566af378d8ea8f8b8ade38dd3540..f7841a8d2ec9a3e8dfe8d1fd956ba5f6976609cd 100644 --- a/Partie_3_GUI/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/Partie_3_GUI/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,5 +1,6 @@ ch/hepia/Hand.class ch/hepia/JeudeCarte.class +ch/hepia/GameManager$1.class ch/hepia/Carte.class ch/hepia/Save.class ch/hepia/JoueurOrdinateur.class @@ -8,5 +9,8 @@ ch/hepia/COULEUR.class ch/hepia/Hand$1.class ch/hepia/Paquet.class ch/hepia/JoueurCroupier.class +ch/hepia/BlackjackGUI.class ch/hepia/JeudeCarte$1.class +ch/hepia/BlackjackGUI$1.class +ch/hepia/GameManager.class ch/hepia/JoueurHumain.class