diff --git a/pom.xml b/pom.xml index ab8a4da16904479293cb8bf4979230ba8a8ac219..4f7e67b1f60e873351357e5720cebb6a04af10b1 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ <artifactId>javafx-maven-plugin</artifactId> <version>0.0.8</version> <configuration> - <mainClass>hepia.BlackjackUI</mainClass> + <mainClass>hepia.BlackJackApplication</mainClass> </configuration> </plugin> <plugin> diff --git a/src/main/java/hepia/AskForBetController.java b/src/main/java/hepia/AskForBetController.java new file mode 100644 index 0000000000000000000000000000000000000000..5439c6b0a13b65c51ff94343cc53c2c163400f25 --- /dev/null +++ b/src/main/java/hepia/AskForBetController.java @@ -0,0 +1,37 @@ +package hepia; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.stage.Stage; + +public class AskForBetController extends BlackJackController { + @FXML + private TextField inputBet; + @FXML + private Button btnSetBet; + + @FXML + public void initialize() { + filterInputs(inputBet); + + btnSetBet.disableProperty().bind(inputBet.textProperty().isEmpty()); + } + + private void filterInputs(TextField inputField) { + inputField.addEventFilter(javafx.scene.input.KeyEvent.KEY_TYPED, event -> { + if (!event.getCharacter().matches("[0-9]")) { + event.consume(); + } + }); + } + + @FXML + protected void setHumanBet() { + Stage currentStage = (Stage) btnSetBet.getScene().getWindow(); + currentStage.close(); + + humanPlayers.add(new HumanPlayer(Integer.parseInt(inputBet.getText()))); + } +} + diff --git a/src/main/java/hepia/BlackJackApplication.java b/src/main/java/hepia/BlackJackApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..d29652f88daf7d45b762798b3d5fdaa9022cab24 --- /dev/null +++ b/src/main/java/hepia/BlackJackApplication.java @@ -0,0 +1,30 @@ +package hepia; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; +import javafx.stage.Stage; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class BlackJackApplication extends Application { + @Override + public void start(Stage stage) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(BlackJackApplication.class.getResource("startform-view.fxml")); + Parent root = fxmlLoader.load(); + Scene scene = new Scene(root); + stage.setScene(scene); + stage.setTitle("Form"); + stage.show(); + } + + public static void main(String[] args) { + launch(); + } +} \ No newline at end of file diff --git a/src/main/java/hepia/BlackJackController.java b/src/main/java/hepia/BlackJackController.java new file mode 100644 index 0000000000000000000000000000000000000000..c4d57ff9867d9bc0d9133cf9b795ff530bebd237 --- /dev/null +++ b/src/main/java/hepia/BlackJackController.java @@ -0,0 +1,70 @@ +package hepia; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class BlackJackController { + protected GameManager game; + + protected int nbHumans; + + protected int nbBasicAi; + + protected int nbAdvanced; + + protected int nbDecks; + + protected List<HumanPlayer> humanPlayers = new ArrayList<>(); + + protected List<AIPlayer> aiPlayers = new ArrayList<>(); + + protected List<AIPlayer> basicAi = new ArrayList<>(); + + protected List<AIPlayer> advancedAi = new ArrayList<>(); + + protected void initGame() { + game = new GameManager(Game.BLACKJACK, nbHumans, nbBasicAi, nbAdvanced, nbDecks); + + for (int i = 0; i < nbBasicAi; i++) { + int aiBet = new Random().nextInt((100 - GameManager.MIN_BET + 1) + GameManager.MIN_BET); + AIPlayer ai = new AIPlayer(aiBet, false); + this.aiPlayers.add(ai); + this.basicAi.add(ai); + } + + for (int i = 0; i < nbAdvanced; i++) { + int aiBet = new Random().nextInt((100 - GameManager.MIN_BET + 1) + GameManager.MIN_BET); + AIPlayer ai = new AIPlayer(aiBet, true); + this.aiPlayers.add(ai); + this.advancedAi.add(ai); + } + } + + + @FXML + private void dealCards() { + + } + + + @FXML + private void hit() { + + } + + + @FXML + private void stand() { + + } + + @FXML + private void newGame() { + + } +} \ No newline at end of file diff --git a/src/main/java/hepia/BlackjackUI.java b/src/main/java/hepia/BlackjackUI.java deleted file mode 100644 index 3d5218d95f4fe77e7a6a308e69bbb30b6ab0c700..0000000000000000000000000000000000000000 --- a/src/main/java/hepia/BlackjackUI.java +++ /dev/null @@ -1,30 +0,0 @@ -package hepia; - -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.control.TextArea; -import javafx.stage.Stage; -import javafx.scene.layout.VBox; - -import java.io.OutputStream; -import java.util.Objects; -import java.io.PrintStream; - -public class BlackjackUI extends Application { - @Override - public void start(Stage stage) throws Exception { - Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("blackjack-ui.fxml"))); - - Scene scene = new Scene(root); - - stage.setScene(scene); - stage.show(); - } - - public static void main(String[] args) { - launch(args); - } -} - diff --git a/src/main/java/hepia/StartFormController.java b/src/main/java/hepia/StartFormController.java new file mode 100644 index 0000000000000000000000000000000000000000..f13c52b7b5ff3e9c20c873815e24b600024419b7 --- /dev/null +++ b/src/main/java/hepia/StartFormController.java @@ -0,0 +1,69 @@ +package hepia; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.stage.Stage; + +import java.io.IOException; + +public class StartFormController extends BlackJackController { + @FXML + private TextField inputHumans; + @FXML + private TextField inputBasicAi; + @FXML + private TextField inputAdvancedAi; + @FXML + private TextField inputDecks; + @FXML + private Button btnStartGame; + + @FXML + public void initialize() { + filterInputs(inputHumans); + filterInputs(inputBasicAi); + filterInputs(inputAdvancedAi); + filterInputs(inputDecks); + + btnStartGame.disableProperty().bind(inputHumans.textProperty().isEmpty().or(inputBasicAi.textProperty().isEmpty().or(inputAdvancedAi.textProperty().isEmpty().or(inputDecks.textProperty().isEmpty())))); + } + + private void filterInputs(TextField inputField) { + inputField.addEventFilter(javafx.scene.input.KeyEvent.KEY_TYPED, event -> { + if (!event.getCharacter().matches("[0-9]")) { + event.consume(); + } + }); + } + + @FXML + protected void sendFormNewGame(ActionEvent e) throws IOException { + Stage currentStage = (Stage) btnStartGame.getScene().getWindow(); + currentStage.close(); + + this.nbHumans = Integer.parseInt(inputHumans.getText()); + this.nbBasicAi = Integer.parseInt(inputBasicAi.getText()); + this.nbAdvanced = Integer.parseInt(inputAdvancedAi.getText()); + this.nbDecks = Integer.parseInt(inputDecks.getText()); + + System.out.println("Humans = " + nbHumans); + System.out.println("Basic AIs = " + nbBasicAi); + System.out.println("Advanced AIs = " + nbAdvanced); + System.out.println("Decks = " + nbDecks); + + + for (int i = 0; i < nbHumans; i++) { + FXMLLoader fxmlLoader = new FXMLLoader(StartFormController.class.getResource("askforbet-view.fxml")); + + Stage newStage = new Stage(); + Scene scene = new Scene(fxmlLoader.load()); + + newStage.setScene(scene); + newStage.show(); + } + } +} diff --git a/src/main/resources/hepia/askforbet-view.fxml b/src/main/resources/hepia/askforbet-view.fxml new file mode 100644 index 0000000000000000000000000000000000000000..6c7812420fe36912f4a5c34424edd8b368417aff --- /dev/null +++ b/src/main/resources/hepia/askforbet-view.fxml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.TextField?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.text.Font?> + + +<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="463.0" prefWidth="407.0" xmlns="http://javafx.com/javafx/21.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hepia.AskForBetController"> + <children> + <Label fx:id="labelPlayer" layoutX="14.0" layoutY="183.0" text="Enter your bet (min 10.-) :"> + <font> + <Font size="18.0" /> + </font> + </Label> + <TextField fx:id="inputBet" layoutX="242.0" layoutY="183.0" prefHeight="26.0" prefWidth="149.0" /> + <Button fx:id="btnSetBet" layoutX="86.0" layoutY="322.0" mnemonicParsing="false" onAction="#setHumanBet" prefHeight="84.0" prefWidth="236.0" text="Confirm"> + <font> + <Font size="24.0" /> + </font> + </Button> + <Label layoutX="84.0" layoutY="40.0" text="Human Player"> + <font> + <Font size="36.0" /> + </font> + </Label> + </children> +</AnchorPane> diff --git a/src/main/resources/hepia/blackjack-ui.fxml b/src/main/resources/hepia/blackjack-ui.fxml deleted file mode 100644 index fe67a3d6b3d7a721a50224a0f07dbc766b9a45c1..0000000000000000000000000000000000000000 --- a/src/main/resources/hepia/blackjack-ui.fxml +++ /dev/null @@ -1,69 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<?import javafx.scene.control.*?> -<?import javafx.scene.layout.*?> - -<VBox xmlns="http://javafx.com/javafx/21.0.1" - xmlns:fx="http://javafx.com/fxml/1" - fx:controller="hepia.BlackjackController" - alignment="CENTER" - spacing="10" - prefWidth="600" prefHeight="400"> - - <!-- Initial Form --> - <VBox fx:id="initialForm" alignment="CENTER" spacing="10"> - <Label text="Enter Game Settings" style="-fx-font-size: 18px;"/> - - <HBox spacing="10" alignment="CENTER"> - <Label text="Number of Human Players:"/> - <TextField fx:id="humanPlayersField"/> - </HBox> - - <HBox spacing="10" alignment="CENTER"> - <Label text="Number of Basic AI Players:"/> - <TextField fx:id="basicAIPlayersField"/> - </HBox> - - <HBox spacing="10" alignment="CENTER"> - <Label text="Number of Advanced AI Players:"/> - <TextField fx:id="advancedAIPlayersField"/> - </HBox> - - <HBox spacing="10" alignment="CENTER"> - <Label text="Number of Decks of Cards:"/> - <TextField fx:id="decksField"/> - </HBox> - - <Button text="Start New Game" onAction="#startNewGame"/> - <Button text="Load Existing Game" onAction="#loadExistingGame"/> - </VBox> - - <!-- Blackjack Table UI components here --> - <VBox fx:id="blackjackTable" alignment="CENTER" spacing="10" visible="false"> - <!-- Input TextField --> - <VBox fx:id="playerBetsVBox" spacing="10"> - <!-- Player bets will be dynamically added here --> - </VBox> - - <TextField fx:id="inputTextField" onAction="#handleInput" prefWidth="400" /> - - <HBox spacing="10" alignment="CENTER"> - <!-- Dealer Hand --> - <VBox fx:id="dealerHand" spacing="5"> - <Label text="Dealer Hand"/> - <!-- Dealer's cards will be dynamically added here --> - </VBox> - - <!-- Player Hands --> - <VBox spacing="10" fx:id="playerHands"> - <!-- Player hand sections will be dynamically added here based on the number of players --> - </VBox> - </HBox> - - <!-- Game Controls --> - <HBox spacing="10" alignment="CENTER"> - <Button text="Hit" onAction="#hit"/> - <Button text="Stand" onAction="#stand"/> - </HBox> - </VBox> -</VBox> diff --git a/src/main/resources/hepia/blackjacktable-view.fxml b/src/main/resources/hepia/blackjacktable-view.fxml new file mode 100644 index 0000000000000000000000000000000000000000..70ceb33f72ce6f2818c7f33ad0945279cb04e6da --- /dev/null +++ b/src/main/resources/hepia/blackjacktable-view.fxml @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import java.lang.*?> +<?import java.util.*?> +<?import javafx.scene.*?> +<?import javafx.scene.control.*?> +<?import javafx.scene.layout.*?> + +<!--<AnchorPane xmlns="http://javafx.com/javafx"--> +<!-- xmlns:fx="http://javafx.com/fxml"--> +<!-- fx:controller="org.hepia.blackjackfx.BlackJackController"--> +<!-- prefHeight="400.0" prefWidth="600.0">--> + + +<!--</AnchorPane>--> + +<BorderPane xmlns="http://javafx.com/javafx" + xmlns:fx="http://javafx.com/fxml" + fx:controller="hepia.BlackjackController" + prefWidth="800.0" prefHeight="600.0"> + + <top> + <HBox alignment="CENTER" spacing="10"> +<!-- <Button text="Deal" onAction="#dealCards"/>--> + <Button text="Hit" onAction="#hit"/> + <Button text="Stand" onAction="#stand"/> +<!-- <Button text="New Game" onAction="#newGame"/>--> + </HBox> + </top> + + <center> + <VBox alignment="CENTER" spacing="20"> + <!-- Dealer's area --> + <HBox alignment="CENTER" spacing="10"> + <VBox spacing="5"> + <Label text="Dealer"/> + <HBox spacing="5"> + <!-- Dealer's cards will be shown here --> + </HBox> + </VBox> + </HBox> + + <!-- Player areas --> + <VBox spacing="20"> + <!-- Placeholder for up to 7 players --> + <!-- Player 1 --> + <HBox alignment="CENTER" spacing="10"> + <VBox spacing="5"> + <Label text="Player 1"/> + <HBox spacing="5"> + <!-- Player 1's cards will be shown here --> + </HBox> + </VBox> + </HBox> + + <!-- Player 2 --> + <HBox alignment="CENTER" spacing="10"> + <VBox spacing="5"> + <Label text="Player 2"/> + <HBox spacing="5"> + <!-- Player 2's cards will be shown here --> + </HBox> + </VBox> + </HBox> + + <!-- Player 3 --> + <HBox alignment="CENTER" spacing="10"> + <VBox spacing="5"> + <Label text="Player 3"/> + <HBox spacing="5"> + <!-- Player 3's cards will be shown here --> + </HBox> + </VBox> + </HBox> + + <!-- Player 4 --> + <HBox alignment="CENTER" spacing="10"> + <VBox spacing="5"> + <Label text="Player 4"/> + <HBox spacing="5"> + <!-- Player 4's cards will be shown here --> + </HBox> + </VBox> + </HBox> + + <!-- Player 5 --> + <HBox alignment="CENTER" spacing="10"> + <VBox spacing="5"> + <Label text="Player 5"/> + <HBox spacing="5"> + <!-- Player 5's cards will be shown here --> + </HBox> + </VBox> + </HBox> + + <!-- Player 6 --> + <HBox alignment="CENTER" spacing="10"> + <VBox spacing="5"> + <Label text="Player 6"/> + <HBox spacing="5"> + <!-- Player 6's cards will be shown here --> + </HBox> + </VBox> + </HBox> + + <!-- Player 7 --> + <HBox alignment="CENTER" spacing="10"> + <VBox spacing="5"> + <Label text="Player 7"/> + <HBox spacing="5"> + <!-- Player 7's cards will be shown here --> + </HBox> + </VBox> + </HBox> + </VBox> + </VBox> + </center> +</BorderPane> \ No newline at end of file diff --git a/src/main/resources/hepia/startform-view.fxml b/src/main/resources/hepia/startform-view.fxml new file mode 100644 index 0000000000000000000000000000000000000000..b8a7a762121ed81661b5f3e8bca73df0ded62f34 --- /dev/null +++ b/src/main/resources/hepia/startform-view.fxml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.control.*?> +<?import javafx.scene.layout.*?> +<?import javafx.scene.text.*?> + +<AnchorPane prefHeight="600.0" prefWidth="1000.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/11.0.14-internal" fx:controller="hepia.StartFormController"> + <children> + <Label layoutX="303.0" layoutY="53.0" text="Welcome to Blackjack simulator"> + <font> + <Font size="36.0" /> + </font> + </Label> + <TextField fx:id="inputHumans" layoutX="541.0" layoutY="188.0" promptText="nb humans" /> + <Label layoutX="249.0" layoutY="187.0" text="Number of human players :"> + <font> + <Font size="18.0" /> + </font> + </Label> + <TextField fx:id="inputBasicAi" layoutX="540.0" layoutY="243.0" promptText="nb basic AI" /> + <Label layoutX="245.0" layoutY="243.0" text="Number of basic AIs (max 2) :"> + <font> + <Font size="18.0" /> + </font> + </Label> + <TextField fx:id="inputAdvancedAi" layoutX="540.0" layoutY="304.0" promptText="nb advanced AI" /> + <Label layoutX="225.0" layoutY="304.0" text="Number of advanced AIs (max 2) :"> + <font> + <Font size="18.0" /> + </font> + </Label> + <TextField fx:id="inputDecks" layoutX="539.0" layoutY="366.0" promptText="nb decks" /> + <Label layoutX="284.0" layoutY="365.0" text="Number of decks :"> + <font> + <Font size="18.0" /> + </font> + </Label> + <Button fx:id="btnLoadGame" layoutX="154.0" layoutY="470.0" mnemonicParsing="false" prefHeight="59.0" prefWidth="194.0" text="Load existing game" /> + <Button fx:id="btnStartGame" layoutX="677.0" layoutY="470.0" mnemonicParsing="false" onAction="#sendFormNewGame" prefHeight="59.0" prefWidth="194.0" text="Start new game" /> + </children> +</AnchorPane>