Skip to content
Snippets Groups Projects
Commit abb6523b authored by iliya's avatar iliya
Browse files

insh j'ai rien cassé, en vrai ***

parent 40fd8d16
No related branches found
No related tags found
No related merge requests found
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
<artifactId>javafx-maven-plugin</artifactId> <artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version> <version>0.0.8</version>
<configuration> <configuration>
<mainClass>hepia.BlackjackUI</mainClass> <mainClass>hepia.BlackJackApplication</mainClass>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
......
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())));
}
}
...@@ -4,27 +4,27 @@ import javafx.application.Application; ...@@ -4,27 +4,27 @@ import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.TextArea; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.scene.layout.VBox;
import java.io.OutputStream; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.io.PrintStream;
public class BlackjackUI extends Application { public class BlackJackApplication extends Application {
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws IOException {
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("blackjack-ui.fxml"))); FXMLLoader fxmlLoader = new FXMLLoader(BlackJackApplication.class.getResource("startform-view.fxml"));
Parent root = fxmlLoader.load();
Scene scene = new Scene(root); Scene scene = new Scene(root);
stage.setScene(scene); stage.setScene(scene);
stage.setTitle("Form");
stage.show(); stage.show();
} }
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch();
} }
} }
\ No newline at end of file
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
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();
}
}
}
<?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>
<?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>
<?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
<?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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment