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

Part 3 Main Menu

parent f4b82ecb
No related branches found
No related tags found
No related merge requests found
Showing
with 219 additions and 13 deletions
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"type": "java",
"name": "BlackjackGUI",
"request": "launch",
"mainClass": "ch.hepia.BlackjackGUI",
"projectName": "Java_Card_Game"
},
{ {
"name": "C/C++ Runner: Debug Session", "name": "C/C++ Runner: Debug Session",
"type": "cppdbg", "type": "cppdbg",
......
Image diff could not be displayed: it is too large. Options to address this: view the blob.
Partie_3_GUI/img/blackjack.png

52.7 KiB

Partie_3_GUI/img/gray_button.png

10.7 KiB

Partie_3_GUI/img/light_blue_button.png

10.7 KiB

Partie_3_GUI/img/light_green_button.png

10.6 KiB

Partie_3_GUI/img/red_button.png

10.4 KiB

...@@ -28,16 +28,16 @@ ...@@ -28,16 +28,16 @@
<version>5.9.1</version> <version>5.9.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19</version>
</dependency>
<dependency> <dependency>
<groupId>com.opencsv</groupId> <groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId> <artifactId>opencsv</artifactId>
<version>5.9</version> <version>5.9</version>
</dependency> </dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21.0.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
...@@ -61,6 +61,14 @@ ...@@ -61,6 +61,14 @@
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version> <version>3.4.1</version>
</plugin> </plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>ch.hepia.BlackjackGUI</mainClass>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId> <artifactId>exec-maven-plugin</artifactId>
......
package ch.hepia;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import java.io.File;
import javafx.animation.ScaleTransition;
import javafx.animation.TranslateTransition;
import javafx.util.Duration;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.paint.Color;
public class BlackjackGUI extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
String filePath = "save.csv";
File f = new File(filePath);
primaryStage.setTitle("Blackjack");
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));
Image blackjackImage = new Image("file:img/blackjack.png");
ImageView blackjackImageView = new ImageView(blackjackImage);
blackjackImageView.setFitHeight(400);
blackjackImageView.setPreserveRatio(true);
Button lightGreenButton = createButtonWithText("New Game", "file:img/light_green_button.png", 300);
Button lightBlueButton = createButtonWithText("Load Save", "file:img/light_blue_button.png", 300);
// Create HBox for the bottom images
HBox bottomImagesBox = new HBox(20);
bottomImagesBox.setAlignment(Pos.CENTER);
// Create VBox for the entire layout
VBox layout = new VBox(100);
layout.getChildren().addAll(blackjackImageView, bottomImagesBox);
layout.setAlignment(Pos.CENTER);
// Set Background Image
layout.setBackground(new Background(background));
// Create the scene and set it to the stage
Scene scene = new Scene(layout, 1400, 800);
primaryStage.setScene(scene);
primaryStage.setResizable(false);
// Show the stage
primaryStage.show();
if (!f.exists()) {
lightBlueButton.setVisible(false);
bottomImagesBox.getChildren().add(lightGreenButton);
} else {
bottomImagesBox.getChildren().addAll(lightGreenButton, lightBlueButton);
}
TranslateTransition blackjackTransition = new TranslateTransition(Duration.seconds(2), blackjackImageView);
blackjackTransition.setByX(0);
blackjackTransition.setByY(30);
blackjackTransition.setCycleCount(TranslateTransition.INDEFINITE);
blackjackTransition.setAutoReverse(true);
TranslateTransition lightGreenButtonTransition = new TranslateTransition(Duration.seconds(1),
lightGreenButton);
lightGreenButtonTransition.setByX(0);
lightGreenButtonTransition.setByY(5);
lightGreenButtonTransition.setCycleCount(TranslateTransition.INDEFINITE);
lightGreenButtonTransition.setAutoReverse(true);
TranslateTransition lightBlueButtonTransition = new TranslateTransition(Duration.seconds(1),
lightBlueButton);
lightBlueButtonTransition.setByX(0);
lightBlueButtonTransition.setByY(5);
lightBlueButtonTransition.setCycleCount(TranslateTransition.INDEFINITE);
lightBlueButtonTransition.setAutoReverse(true);
// Start the animation
lightBlueButtonTransition.play();
lightGreenButtonTransition.play();
blackjackTransition.play();
lightGreenButton.setOnAction(event -> {
lightGreenButtonTransition.stop();
lightBlueButtonTransition.stop();
blackjackTransition.stop();
ScaleTransition scaleTransition = new ScaleTransition(Duration.seconds(1), blackjackImageView);
scaleTransition.setToX(0.3);
scaleTransition.setToY(0.3);
blackjackTransition.setAutoReverse(false);
blackjackTransition.setCycleCount(1);
blackjackTransition.setByX(-640);
blackjackTransition.setByY(-250);
blackjackTransition.setDuration(Duration.seconds(1));
lightBlueButtonTransition.setAutoReverse(false);
lightBlueButtonTransition.setCycleCount(1);
lightBlueButtonTransition.setByY(300);
lightGreenButtonTransition.setAutoReverse(false);
lightGreenButtonTransition.setCycleCount(1);
lightGreenButtonTransition.setByY(300);
blackjackTransition.setOnFinished(e -> {
blackjackTransition.setByX(0);
blackjackTransition.setByY(10);
blackjackTransition.setCycleCount(TranslateTransition.INDEFINITE);
blackjackTransition.setAutoReverse(true);
blackjackTransition.play();
});
blackjackTransition.play();
lightBlueButtonTransition.play();
lightGreenButtonTransition.play();
scaleTransition.play();
});
}
private Button createButtonWithText(String buttonText, String imagePath, int size) {
Image buttonImage = new Image(imagePath);
ImageView buttonImageView = new ImageView(buttonImage);
buttonImageView.setFitWidth(size);
buttonImageView.setPreserveRatio(true);
Button button = new Button(buttonText, buttonImageView);
button.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
button.setPadding(Insets.EMPTY);
Font font = Font.font("Courier New", FontWeight.BOLD, 25);
button.setFont(font);
button.setTextFill(Color.WHITE);
double translateYValue = 7.0;
buttonImageView.setTranslateY(translateYValue);
button.setStyle("-fx-background-color: transparent; -fx-border-color: transparent;");
button.setOnMouseEntered(e -> button.setStyle(
"-fx-cursor: hand; -fx-background-color: transparent; -fx-border-color: transparent;"));
button.setOnMouseExited(e -> button
.setStyle("-fx-background-color: transparent; -fx-border-color: transparent;"));
return button;
}
}
No preview for this file type
File added
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
ch/hepia/Hand.class ch/hepia/Hand.class
ch/hepia/JeudeCarte.class ch/hepia/JeudeCarte.class
ch/hepia/Carte.class ch/hepia/Carte.class
ch/hepia/Save.class
ch/hepia/JoueurOrdinateur.class
ch/hepia/Joueur.class
ch/hepia/App.class ch/hepia/App.class
ch/hepia/COULEUR.class ch/hepia/COULEUR.class
ch/hepia/Hand$1.class ch/hepia/Hand$1.class
ch/hepia/Paquet.class ch/hepia/Paquet.class
ch/hepia/JoueurCroupier.class
ch/hepia/BlackjackGUI.class
ch/hepia/JeudeCarte$1.class
ch/hepia/GameManager.class
ch/hepia/JoueurHumain.class
/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Paquet.java /home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/JeudeCarte.java
/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Joueur.java /home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/Save.java
/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/App.java /home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/Joueur.java
/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Hand.java /home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/GameManager.java
/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Carte.java /home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/Paquet.java
/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/GameManager.java /home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/Carte.java
/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/JeudeCarte.java /home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/Hand.java
/home/padi/Git/java-card-game/Partie_3/src/main/java/ch/hepia/Save.java /home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/App.java
/home/padi/Git/java-card-game/Partie_3_GUI/src/main/java/ch/hepia/BlackjackGUI.java
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment