Skip to content
Snippets Groups Projects
Commit bdb70a30 authored by michael.divia's avatar michael.divia
Browse files

GUI 100%

parent 002a5096
Branches
No related tags found
No related merge requests found
...@@ -31,8 +31,8 @@ public class GameManager { ...@@ -31,8 +31,8 @@ public class GameManager {
private ArrayList<Joueur> Players; private ArrayList<Joueur> Players;
private JoueurCroupier Dealer; private JoueurCroupier Dealer;
private int ComputerPlayers; private int ComputerPlayers;
private int Step;
private boolean GameOver; private boolean GameOver;
private int CurrentHand;
public GameManager(int nbPlayer, int startMoney, int computerStrategy) { public GameManager(int nbPlayer, int startMoney, int computerStrategy) {
...@@ -90,7 +90,7 @@ public class GameManager { ...@@ -90,7 +90,7 @@ public class GameManager {
// Ask the player how much he wan't to bid // Ask the player how much he wan't to bid
public void StartTurn(Stage primaryStage) { public void StartTurn(Stage primaryStage) {
this.Step = 0; this.CurrentHand = 0;
Font font = Font.font("Courier New", FontWeight.BOLD, 25); Font font = Font.font("Courier New", FontWeight.BOLD, 25);
...@@ -110,6 +110,38 @@ public class GameManager { ...@@ -110,6 +110,38 @@ public class GameManager {
BackgroundPosition.CENTER, BackgroundPosition.CENTER,
new BackgroundSize(550, 400, false, false, true, true)); new BackgroundSize(550, 400, false, false, true, true));
Image deckImage = new Image("file:img/deck.png");
ImageView deckView = new ImageView(deckImage);
deckView.setFitHeight(50);
deckView.setPreserveRatio(true);
Image moneyImage = new Image("file:img/money.png");
ImageView moneyView = new ImageView(moneyImage);
moneyView.setFitHeight(50);
moneyView.setPreserveRatio(true);
Text cardsInDeck = new Text(String.valueOf(this.Deck.GetNbCards()));
cardsInDeck.setFill(Color.WHITE);
cardsInDeck.setFont(Font.font("Courier New", FontWeight.BOLD, 20));
Text moneyPlayer = new Text(String.valueOf(this.Players.get(0).GetMoney()));
moneyPlayer.setFill(Color.WHITE);
moneyPlayer.setFont(Font.font("Courier New", FontWeight.BOLD, 20));
HBox deckBox = new HBox(5);
deckBox.getChildren().addAll(deckView, cardsInDeck);
deckBox.setAlignment(Pos.CENTER_LEFT);
HBox moneyBox = new HBox(5);
moneyBox.getChildren().addAll(moneyView, moneyPlayer);
moneyBox.setAlignment(Pos.CENTER_LEFT);
VBox moneyDeckInsuredBox = new VBox(10);
moneyDeckInsuredBox.getChildren().addAll(deckBox, moneyBox);
moneyDeckInsuredBox.setAlignment(Pos.CENTER_LEFT);
moneyDeckInsuredBox.setTranslateX(5);
if (this.GameOver) { if (this.GameOver) {
Button exitButton = createButtonWithText("Exit", "file:img/red_button.png", 200, Button exitButton = createButtonWithText("Exit", "file:img/red_button.png", 200,
...@@ -128,7 +160,7 @@ public class GameManager { ...@@ -128,7 +160,7 @@ public class GameManager {
StackPane root = new StackPane(); StackPane root = new StackPane();
root.getChildren().add(layout); root.getChildren().addAll(moneyDeckInsuredBox, layout);
root.setBackground(new Background(background)); root.setBackground(new Background(background));
layout.setBackground(new Background(backgroundPopup)); layout.setBackground(new Background(backgroundPopup));
...@@ -181,7 +213,7 @@ public class GameManager { ...@@ -181,7 +213,7 @@ public class GameManager {
layout.setMinSize(550, 400); layout.setMinSize(550, 400);
layout.setMaxSize(550, 400); layout.setMaxSize(550, 400);
root.getChildren().add(layout); root.getChildren().addAll(moneyDeckInsuredBox, layout);
root.setBackground(new Background(background)); root.setBackground(new Background(background));
layout.setBackground(new Background(backgroundPopup)); layout.setBackground(new Background(backgroundPopup));
...@@ -212,8 +244,10 @@ public class GameManager { ...@@ -212,8 +244,10 @@ public class GameManager {
// Set the Computer players bid for this turn // Set the Computer players bid for this turn
for (int x = 1; x <= this.ComputerPlayers; x++) { for (int x = 1; x <= this.ComputerPlayers; x++) {
if (!this.Players.get(x).IsGameOver()) {
Players.get(x).SetBet(10, 0); Players.get(x).SetBet(10, 0);
} }
}
layout.setVisible(false); layout.setVisible(false);
PlayTurn(primaryStage); PlayTurn(primaryStage);
...@@ -235,8 +269,6 @@ public class GameManager { ...@@ -235,8 +269,6 @@ public class GameManager {
// Ask the player for all his interactions with this cards // Ask the player for all his interactions with this cards
public void PlayTurn(Stage primaryStage) { public void PlayTurn(Stage primaryStage) {
this.Step = 0;
Image backgroundImage = new Image("file:img/background.jpg"); Image backgroundImage = new Image("file:img/background.jpg");
BackgroundImage background = new BackgroundImage( BackgroundImage background = new BackgroundImage(
backgroundImage, backgroundImage,
...@@ -286,7 +318,7 @@ public class GameManager { ...@@ -286,7 +318,7 @@ public class GameManager {
moneyPlayer.setFill(Color.WHITE); moneyPlayer.setFill(Color.WHITE);
moneyPlayer.setFont(Font.font("Courier New", FontWeight.BOLD, 20)); moneyPlayer.setFont(Font.font("Courier New", FontWeight.BOLD, 20));
Text insured = new Text(String.valueOf(this.Players.get(0).HasInsured())); Text insured = new Text("0.0");
insured.setFill(Color.WHITE); insured.setFill(Color.WHITE);
insured.setFont(Font.font("Courier New", FontWeight.BOLD, 20)); insured.setFont(Font.font("Courier New", FontWeight.BOLD, 20));
...@@ -319,28 +351,45 @@ public class GameManager { ...@@ -319,28 +351,45 @@ public class GameManager {
dealerCardsStrengthBox.getChildren().addAll(dealerCardsBox, strengthDealer); dealerCardsStrengthBox.getChildren().addAll(dealerCardsBox, strengthDealer);
dealerCardsStrengthBox.setAlignment(Pos.TOP_CENTER); dealerCardsStrengthBox.setAlignment(Pos.TOP_CENTER);
HBox playerCardsBox = new HBox(-70); HBox[] playerCardsBox = new HBox[3];
playerCardsBox.getChildren().addAll(playerCard1View, playerCard2View);
playerCardsBox.setAlignment(Pos.TOP_CENTER); Text[] strengthHand = new Text[3];
Text[] betHand = new Text[3];
VBox[] playerCardsStrengthBox = new VBox[3];
for (int x = 0; x < 3; x++) {
strengthHand[x] = new Text();
strengthHand[x].setTextAlignment(TextAlignment.CENTER);
strengthHand[x].setFill(Color.WHITE);
strengthHand[x].setFont(Font.font("Courier New", FontWeight.BOLD, 30));
playerCardsBox[x] = new HBox();
playerCardsBox[x] = new HBox(-70);
playerCardsBox[x].setAlignment(Pos.TOP_CENTER);
betHand[x] = new Text();
betHand[x].setFill(Color.WHITE);
betHand[x].setTextAlignment(TextAlignment.CENTER);
betHand[x].setFont(Font.font("Courier New", FontWeight.BOLD, 25));
playerCardsStrengthBox[x] = new VBox(20);
playerCardsStrengthBox[x].setAlignment(Pos.TOP_CENTER);
playerCardsStrengthBox[x].getChildren().addAll(strengthHand[x], playerCardsBox[x], betHand[x]);
}
Text strengthHand1 = new Text();
if (this.Players.get(0).GetStrength(0) == 99) { if (this.Players.get(0).GetStrength(0) == 99) {
strengthHand1.setText("BlackJack"); strengthHand[0].setText("BlackJack");
strengthHand[0].setFill(Color.GOLD);
} else { } else {
strengthHand1.setText(String.valueOf(this.Players.get(0).GetStrength(0))); strengthHand[0].setText(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));
Text betHand1 = new Text(String.valueOf(this.Players.get(0).GetBet(0))); playerCardsBox[0].getChildren().addAll(playerCard1View, playerCard2View);
betHand1.setFill(Color.WHITE);
betHand1.setTextAlignment(TextAlignment.CENTER);
betHand1.setFont(Font.font("Courier New", FontWeight.BOLD, 25));
VBox playerCardsStrengthBox = new VBox(20); betHand[0].setText(String.valueOf(this.Players.get(0).GetBet(0)));
playerCardsStrengthBox.getChildren().addAll(strengthHand1, playerCardsBox, betHand1);
playerCardsStrengthBox.setAlignment(Pos.TOP_CENTER);
VBox computers = new VBox(15); VBox computers = new VBox(15);
computers.setAlignment(Pos.CENTER_RIGHT); computers.setAlignment(Pos.CENTER_RIGHT);
...@@ -378,21 +427,29 @@ public class GameManager { ...@@ -378,21 +427,29 @@ public class GameManager {
HBox actions = new HBox(10); HBox actions = new HBox(10);
actions.setAlignment(Pos.BOTTOM_CENTER); actions.setAlignment(Pos.BOTTOM_CENTER);
Button insureButton = createButtonWithText("Insure", "file:img/red_button.png", 175, 4.0);
Button splitButton = createButtonWithText("Split", "file:img/red_button.png", 175, 4.0);
Button doubleButton = createButtonWithText("Double", "file:img/gray_button.png", 175, 4.0);
Button hitButton = createButtonWithText("Hit", "file:img/light_green_button.png", 175, 4.0);
Button keepButton = createButtonWithText("Stand", "file:img/light_blue_button.png", 175, 4.0);
// Insurance // Insurance
// Can only insure if it's the first thing that the players does
// AND
// That he hasn't already insured during this round // That he hasn't already insured during this round
if (this.Step == 0 && this.Dealer.HasOnlyAs() && !this.Players.get(0).HasInsured()) { if (this.Dealer.HasOnlyAs() && !this.Players.get(0).HasInsured()) {
Button insureButton = createButtonWithText("Insure", "file:img/red_button.png", 175, 4.0);
actions.getChildren().add(insureButton); actions.getChildren().add(insureButton);
insureButton.setOnAction(event -> { insureButton.setOnAction(event -> {
this.Players.get(0).Insure(); this.Players.get(0).Insure();
insured.setText(String.valueOf(this.Players.get(0).HasInsured())); insured.setText(String.valueOf(this.Players.get(0).GetInsured()));
moneyPlayer.setText(String.valueOf(this.Players.get(0).GetMoney()));
actions.getChildren().remove(insureButton); actions.getChildren().remove(insureButton);
}); });
} }
HBox playerCardBox = new HBox(10);
playerCardBox.setAlignment(Pos.BOTTOM_CENTER);
// Split // Split
// Can only split if this hand can be split (if it wasn't already split AND if // Can only split if this hand can be split (if it wasn't already split AND if
// the 2 cards have the same strength) // the 2 cards have the same strength)
...@@ -400,10 +457,133 @@ public class GameManager { ...@@ -400,10 +457,133 @@ public class GameManager {
// if we have less that 3 hands already (Max 2 splits) // if we have less that 3 hands already (Max 2 splits)
// AND // AND
// if the player has enough money // if the player has enough money
if (this.Players.get(0).CanSplit(0) && this.Players.get(0).GetNbHands() < 3 if (this.Players.get(0).CanSplit(this.CurrentHand) && this.Players.get(0).GetNbHands() < 3
&& this.Players.get(0).GetBet(0) <= this.Players.get(0).GetMoney()) { && this.Players.get(0).GetBet(this.CurrentHand) <= this.Players.get(0).GetMoney()) {
Button splitButton = createButtonWithText("Split", "file:img/red_button.png", 175, 4.0);
actions.getChildren().add(splitButton); actions.getChildren().add(splitButton);
splitButton.setOnAction(event -> {
this.Players.get(0).Split(this.CurrentHand, Deck);
moneyPlayer.setText(String.valueOf(this.Players.get(0).GetMoney()));
playerCardsBox[this.CurrentHand].getChildren().clear();
Image Card1 = new Image("file:img/" + this.Players.get(0).GetCard(this.CurrentHand, 0) + ".png");
Image Card2 = new Image("file:img/" + this.Players.get(0).GetCard(this.CurrentHand, 1) + ".png");
ImageView Card1View = new ImageView(Card1);
Card1View.setFitHeight(150);
Card1View.setPreserveRatio(true);
ImageView Card2View = new ImageView(Card2);
Card2View.setFitHeight(150);
Card2View.setPreserveRatio(true);
playerCardsBox[this.CurrentHand].getChildren().addAll(Card1View, Card2View);
playerCardsBox[this.Players.get(0).GetNbHands() - 1].getChildren().clear();
Image Card3 = new Image(
"file:img/" + this.Players.get(0).GetCard(this.Players.get(0).GetNbHands() - 1, 0) + ".png");
Image Card4 = new Image(
"file:img/" + this.Players.get(0).GetCard(this.Players.get(0).GetNbHands() - 1, 1) + ".png");
ImageView Card3View = new ImageView(Card3);
Card3View.setFitHeight(150);
Card3View.setPreserveRatio(true);
ImageView Card4View = new ImageView(Card4);
Card4View.setFitHeight(150);
Card4View.setPreserveRatio(true);
playerCardsBox[this.Players.get(0).GetNbHands() - 1].getChildren().addAll(Card3View, Card4View);
if (this.Players.get(0).GetStrength(this.CurrentHand) == 99) {
strengthHand[this.CurrentHand].setText("BlackJack");
strengthHand[this.CurrentHand].setFill(Color.GOLD);
} else {
strengthHand[this.CurrentHand]
.setText(String.valueOf(this.Players.get(0).GetStrength(this.CurrentHand)));
}
if (this.Players.get(0).GetStrength(this.Players.get(0).GetNbHands() - 1) == 99) {
strengthHand[this.Players.get(0).GetNbHands() - 1].setText("BlackJack");
strengthHand[this.Players.get(0).GetNbHands() - 1].setFill(Color.GOLD);
} else {
strengthHand[this.Players.get(0).GetNbHands() - 1]
.setText(String
.valueOf(this.Players.get(0).GetStrength(this.Players.get(0).GetNbHands() - 1)));
}
betHand[this.Players.get(0).GetNbHands() - 1]
.setText(String.valueOf(this.Players.get(0).GetBet(this.Players.get(0).GetNbHands() - 1)));
for (int x = 0; x < this.Players.get(0).GetNbHands(); x++) {
playerCardsStrengthBox[x].setTranslateY(0);
}
playerCardsStrengthBox[this.CurrentHand].setTranslateY(-20);
playerCardBox.getChildren().add(playerCardsStrengthBox[this.Players.get(0).GetNbHands() - 1]);
if (actions.getChildren().contains(insureButton)) {
actions.getChildren().remove(insureButton);
}
if (actions.getChildren().contains(doubleButton)) {
actions.getChildren().remove(doubleButton);
}
if (this.Players.get(0).GetNbHands() == 3 || !this.Players.get(0).CanSplit(this.CurrentHand)) {
actions.getChildren().remove(splitButton);
}
});
}
// 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(this.CurrentHand)
&& this.Players.get(0).GetNbCards(this.CurrentHand) == 2
&& this.Players.get(0).GetStrength(this.CurrentHand) != 99
&& this.Players.get(0).GetBet(this.CurrentHand) <= this.Players.get(0).GetMoney()) {
actions.getChildren().add(doubleButton);
doubleButton.setOnAction(event -> {
actions.getChildren().clear();
actions.getChildren().add(keepButton);
this.Players.get(0).Double(this.CurrentHand, Deck);
Image playerCard = new Image(
"file:img/" + this.Players.get(0).GetCard(this.CurrentHand,
this.Players.get(0).GetNbCards(this.CurrentHand) - 1) + ".png");
ImageView playerCardView = new ImageView(playerCard);
playerCardView.setFitHeight(150);
playerCardView.setPreserveRatio(true);
playerCardsBox[this.CurrentHand].getChildren().add(playerCardView);
if (this.Players.get(0).GetStrength(this.CurrentHand) > 21) {
strengthHand[this.CurrentHand].setText("BUSTED");
strengthHand[this.CurrentHand].setFill(Color.RED);
} else {
strengthHand[this.CurrentHand]
.setText(String.valueOf(this.Players.get(0).GetStrength(this.CurrentHand)));
}
betHand[0].setText(String.valueOf(this.Players.get(0).GetBet(this.CurrentHand)));
moneyPlayer.setText(String.valueOf(this.Players.get(0).GetMoney()));
});
} }
// Draw a Card (Hit) // Draw a Card (Hit)
...@@ -414,15 +594,51 @@ public class GameManager { ...@@ -414,15 +594,51 @@ public class GameManager {
// if the player has a BlackJack // if the player has a BlackJack
// AND // AND
// if the strength of the hand is more than 21 // if the strength of the hand is more than 21
if (!(this.Players.get(0).HasDoubled(0) && this.Players.get(0).GetNbCards(0) == 3) if (!(this.Players.get(0).HasDoubled(this.CurrentHand) && this.Players.get(0).GetNbCards(this.CurrentHand) == 3)
&& !(this.Players.get(0).HasSplit(0) && this.Players.get(0).GetCardStrength(0, 0) == 1) && !(this.Players.get(0).HasSplit(this.CurrentHand)
&& this.Players.get(0).GetStrength(0) < 21) { && this.Players.get(0).GetCardStrength(this.CurrentHand, 0) == 1)
Button hitButton = createButtonWithText("Hit", "file:img/light_green_button.png", 175, 4.0); && this.Players.get(0).GetStrength(this.CurrentHand) < 21) {
actions.getChildren().add(hitButton); actions.getChildren().add(hitButton);
hitButton.setOnAction(event -> {
if (actions.getChildren().contains(splitButton)) {
actions.getChildren().remove(splitButton);
}
if (actions.getChildren().contains(insureButton)) {
actions.getChildren().remove(insureButton);
}
if (actions.getChildren().contains(doubleButton)) {
actions.getChildren().remove(doubleButton);
}
this.Players.get(0).DrawCard(this.CurrentHand, Deck);
Image playerCard = new Image(
"file:img/" + this.Players.get(0).GetCard(this.CurrentHand,
this.Players.get(0).GetNbCards(this.CurrentHand) - 1) + ".png");
ImageView playerCardView = new ImageView(playerCard);
playerCardView.setFitHeight(150);
playerCardView.setPreserveRatio(true);
playerCardsBox[this.CurrentHand].getChildren().add(playerCardView);
if (this.Players.get(0).GetStrength(this.CurrentHand) > 21) {
strengthHand[this.CurrentHand].setText("BUSTED");
strengthHand[this.CurrentHand].setFill(Color.RED);
actions.getChildren().clear();
actions.getChildren().add(keepButton);
} else {
strengthHand[this.CurrentHand]
.setText(String.valueOf(this.Players.get(0).GetStrength(this.CurrentHand)));
}
});
} }
// Keep (Stand) // Keep (Stand)
Button keepButton = createButtonWithText("Stand", "file:img/light_blue_button.png", 175, 4.0);
actions.getChildren().add(keepButton); actions.getChildren().add(keepButton);
StackPane deckMoney = new StackPane(); StackPane deckMoney = new StackPane();
...@@ -436,16 +652,43 @@ public class GameManager { ...@@ -436,16 +652,43 @@ public class GameManager {
StackPane computer = new StackPane(); StackPane computer = new StackPane();
keepButton.setOnAction(event -> { keepButton.setOnAction(event -> {
if (this.Players.get(0).GetNbHands() == 1) {
if (this.CurrentHand == this.Players.get(0).GetNbHands() - 1) {
actions.getChildren().clear(); actions.getChildren().clear();
ResolveTurn(primaryStage, cardsInDeck, dealerCardsBox, strengthDealer, computers, actions, player, ResolveTurn(primaryStage, cardsInDeck, dealerCardsBox, strengthDealer, computers, actions, player,
moneyPlayer); moneyPlayer, insured);
} else {
actions.getChildren().remove(keepButton);
if (actions.getChildren().contains(hitButton)) {
actions.getChildren().remove(hitButton);
}
this.CurrentHand++;
if (this.Players.get(0).GetNbHands() < 3 && this.Players.get(0).CanSplit(this.CurrentHand)) {
actions.getChildren().add(splitButton);
}
if (this.Players.get(0).GetStrength(this.CurrentHand) < 21) {
actions.getChildren().add(hitButton);
}
actions.getChildren().add(keepButton);
for (int x = 0; x < this.Players.get(0).GetNbHands(); x++) {
playerCardsStrengthBox[x].setTranslateY(0);
}
playerCardsStrengthBox[this.CurrentHand].setTranslateY(-20);
} }
}); });
playerCardBox.getChildren().add(playerCardsStrengthBox[0]);
dealer.getChildren().add(dealerCardsStrengthBox); dealer.getChildren().add(dealerCardsStrengthBox);
player.getChildren().addAll(playerCardsStrengthBox); player.getChildren().addAll(playerCardBox);
action.getChildren().addAll(actions); action.getChildren().addAll(actions);
deckMoney.getChildren().add(moneyDeckInsuredBox); deckMoney.getChildren().add(moneyDeckInsuredBox);
computer.getChildren().add(computers); computer.getChildren().add(computers);
...@@ -461,38 +704,6 @@ public class GameManager { ...@@ -461,38 +704,6 @@ public class GameManager {
root.getChildren().addAll(deckMoney, dealer, player, computer, action); root.getChildren().addAll(deckMoney, dealer, player, computer, action);
// 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;
// }
Scene scene_4 = new Scene(root, 1400, 800); Scene scene_4 = new Scene(root, 1400, 800);
primaryStage.setScene(scene_4); primaryStage.setScene(scene_4);
...@@ -503,7 +714,7 @@ public class GameManager { ...@@ -503,7 +714,7 @@ public class GameManager {
// Do all the math for the player gains and losses // Do all the math for the player gains and losses
// Check if the player can continue et prepare for the next round // Check if the player can continue et prepare for the next round
public void ResolveTurn(Stage primaryStage, Text cardsInDeck, HBox dealerCardsBox, Text strengthDealer, public void ResolveTurn(Stage primaryStage, Text cardsInDeck, HBox dealerCardsBox, Text strengthDealer,
VBox computers, HBox actions, StackPane player, Text moneyPlayer) { VBox computers, HBox actions, StackPane player, Text moneyPlayer, Text insured) {
// Computer Players take turn to play // Computer Players take turn to play
for (int x = 1; x <= this.ComputerPlayers; x++) { for (int x = 1; x <= this.ComputerPlayers; x++) {
...@@ -726,9 +937,15 @@ public class GameManager { ...@@ -726,9 +937,15 @@ public class GameManager {
if (this.Dealer.GetStrength(0) == 99) { if (this.Dealer.GetStrength(0) == 99) {
strengthDealer.setText("BlackJack"); strengthDealer.setText("BlackJack");
strengthDealer.setFill(Color.GOLD);
} else {
if (this.Dealer.GetStrength(0) > 21) {
strengthDealer.setText("BUSTED");
strengthDealer.setFill(Color.RED);
} else { } else {
strengthDealer.setText(String.valueOf(this.Dealer.GetStrength(0))); strengthDealer.setText(String.valueOf(this.Dealer.GetStrength(0)));
} }
}
dealerCardsBox.getChildren().clear(); dealerCardsBox.getChildren().clear();
computers.getChildren().clear(); computers.getChildren().clear();
...@@ -826,21 +1043,42 @@ public class GameManager { ...@@ -826,21 +1043,42 @@ public class GameManager {
for (int HandNb = 0; HandNb < this.Players.get(0).GetNbHands(); HandNb++) { for (int HandNb = 0; HandNb < this.Players.get(0).GetNbHands(); HandNb++) {
hand[HandNb] = new VBox(20); hand[HandNb] = new VBox(20);
HBox cards = new HBox(-70);
hand[HandNb].setAlignment(Pos.TOP_CENTER); hand[HandNb].setAlignment(Pos.TOP_CENTER);
Text strengthHand = new Text(); Text strengthHand = new Text();
strengthHand.setFill(Color.WHITE);
if (this.Players.get(0).GetStrength(HandNb) == 99) { if (this.Players.get(0).GetStrength(HandNb) == 99) {
strengthHand.setText("BlackJack"); strengthHand.setText("BlackJack");
strengthHand.setFill(Color.GOLD);
} else { } else {
strengthHand.setText(String.valueOf(this.Players.get(0).GetStrength(0))); if (this.Players.get(0).GetStrength(HandNb) > 21) {
strengthHand.setText("BUSTED");
strengthHand.setFill(Color.RED);
} else {
strengthHand.setText(String.valueOf(this.Players.get(0).GetStrength(HandNb)));
} }
strengthHand.setFill(Color.WHITE); }
strengthHand.setTextAlignment(TextAlignment.CENTER); strengthHand.setTextAlignment(TextAlignment.CENTER);
strengthHand.setFont(Font.font("Courier New", FontWeight.BOLD, 30)); strengthHand.setFont(Font.font("Courier New", FontWeight.BOLD, 30));
ImageView[] card = new ImageView[this.Players.get(0).GetNbCards(HandNb)];
for (int z = 0; z < this.Players.get(0).GetNbCards(HandNb); z++) {
Image cardImage = new Image("file:img/" + this.Players.get(0).GetCard(HandNb, z) + ".png");
card[z] = new ImageView(cardImage);
card[z].setFitHeight(150);
card[z].setPreserveRatio(true);
cards.getChildren().add(card[z]);
}
Text betHand = new Text(); Text betHand = new Text();
betHand.setTextAlignment(TextAlignment.CENTER); betHand.setTextAlignment(TextAlignment.CENTER);
betHand.setFont(Font.font("Courier New", FontWeight.BOLD, 30)); betHand.setFont(Font.font("Courier New", FontWeight.BOLD, 25));
// If the player is Busted (strength > 21 but not BlackJack (99)) // If the player is Busted (strength > 21 but not BlackJack (99))
if (this.Players.get(0).GetStrength(HandNb) > 21 && this.Players.get(0).GetStrength(HandNb) != 99) { if (this.Players.get(0).GetStrength(HandNb) > 21 && this.Players.get(0).GetStrength(HandNb) != 99) {
...@@ -887,7 +1125,7 @@ public class GameManager { ...@@ -887,7 +1125,7 @@ public class GameManager {
betHand.setFill(Color.LIGHTGREEN); betHand.setFill(Color.LIGHTGREEN);
} }
hand[HandNb].getChildren().addAll(strengthHand, betHand); hand[HandNb].getChildren().addAll(strengthHand, cards, betHand);
hands.getChildren().add(hand[HandNb]); hands.getChildren().add(hand[HandNb]);
} }
...@@ -902,6 +1140,13 @@ public class GameManager { ...@@ -902,6 +1140,13 @@ public class GameManager {
if (this.Dealer.GetStrength(0) == 99) { if (this.Dealer.GetStrength(0) == 99) {
this.Players.get(0).AddMoney(this.Players.get(0).GetInsured() * 3); this.Players.get(0).AddMoney(this.Players.get(0).GetInsured() * 3);
insured.setText("+" + String.valueOf(this.Players.get(0).GetInsured() * 3));
insured.setFill(Color.LIGHTGREEN);
} else {
insured.setText(String.valueOf(this.Players.get(0).GetInsured() * -1));
insured.setFill(Color.RED);
} }
} }
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment