Skip to content
Snippets Groups Projects
Commit 9a6d3933 authored by raphael.rampf's avatar raphael.rampf
Browse files

more stuff, quasi ended

parent 506b2c0d
Branches
No related tags found
No related merge requests found
Showing
with 238 additions and 30 deletions
......@@ -44,3 +44,51 @@ miscelleanous:
Flowchart I coded :
![flowchart](flowchart.png)
## part 3
- unit test done for class dealer
- Quentin said one class with unit test was enough;
- ai for cpu is done
- they make the correct choice
- at the moment they only play in the background, but there is no crash
- no visual indication for when you are allowed or not to press a button
- if you are not allowed, nothing will happen
- no data saving / loading
- core of the game still functions like in part 2
- i used the same functions, so yeah it does
- double, split and insurance are mutually exlusiv
- double allows only one more cards
- etc ... look at part 2 rules
### ui
- color indicates current playing hand, updates accordingly
- displays your and dealer's cards, updates accordingly
- displays your money, updates accordingly
- displays total amount of money betted this turn, updates accordingly
- display score for each of your hand, updates accordingly
### buttons:
- end turn: once you stayed or busted your final hand, plays the cpus in the background and moves money
- draw: draws a card, only if you are allowed to
- split: split current hand, only if allowed to
- double: doubl down, only if allowed to
- insure: insure, only of able to
- bet initial: make ans initial bet and start your turn
- you won't see the dealer's or your cards befor.
- start new turn: reset player, dealer, cpus, clean the boards
- ready for a new turn
### to play :
- same rules as part 2
- too keep in mind if a button doesn't do anything, it's because you are not allowed to
- select number of ai and if smart or dumb
- always start by giving an amount for initial bet, then pressing the corresponding button
- you can't do anything else exept make the cpus play in the background
- play what you want and are allowed to
- don't forget to explicitly "stay" your last hand if you are not busted
- end your turn with end turn button
- start new turn with start new turn button
- don't forget your initial bet after the start of a new turn
\ No newline at end of file
......@@ -44,6 +44,39 @@
<mainClass>org.openjfx.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
org.javafx.App
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
......@@ -42,10 +42,10 @@ import java.io.File;
*/
public class App extends Application {
// number of cpu
// some global variabless
int numberOfCpu = 0;
boolean dumb = true;
GameManager gameManager = new GameManager(1000, 6, 52);
GameManager gameManager = new GameManager();
public static Scanner scan = new Scanner(System.in);
@Override
......@@ -64,6 +64,7 @@ public class App extends Application {
Scene sceneInGame = new Scene(inGameGrid, 1150, 500);
GridPane menuGrid = new GridPane();
Scene sceneMenu = new Scene(menuGrid, 300, 300);
Label argentValue = new Label();
// ***************************************************************************************************************
// start menu
......@@ -90,7 +91,18 @@ public class App extends Application {
menuGrid.add(button3, 0, 3);
button3.setOnAction(e -> numberOfCpu = 3);
button3.setToggleGroup(numberOfCpuGroup);
// textfield
TextField moneyPlayer = new TextField("1234");
// only accepts numbers, stackoverflow
moneyPlayer.textProperty()
.addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
if (!newValue.matches("\\d*")) {
moneyPlayer.setText(newValue.replaceAll("[^\\d]", ""));
}
});
menuGrid.add(moneyPlayer, 1, 3);
Label moneyAsk = new Label("Money for player");
menuGrid.add(moneyAsk, 1, 2);
// ai label
Label smartLabel = new Label("Smart ai ?");
menuGrid.add(smartLabel, 1, 0);
......@@ -111,11 +123,14 @@ public class App extends Application {
button_start.setText("start game");
menuGrid.add(button_start, 0, 4);
button_start.setOnAction(e -> {
// must have selected an amount of cpu
if (numberOfCpu != 0) {
gameManager = new GameManager(Integer.parseInt(moneyPlayer.getText()), 6, 52);
gameManager.addCpu(numberOfCpu, dumb);
gameManager.shuffleDeck();
System.out.println(smartCheckBox.isSelected());
// gameManager.shuffleDeck();
stage.setScene(sceneInGame);
//maj argent value for next scene
argentValue.setText(String.valueOf(gameManager.human.getMoney()));
}
});
......@@ -150,11 +165,11 @@ public class App extends Application {
}
// labels
Label carteDealer = new Label("Carte du dealer");
Label carteDealer = new Label("Cartes du dealer");
inGameGrid.add(carteDealer, 0, 0);
Label argent = new Label("Argent");
inGameGrid.add(argent, 0, 1);
Label argentValue = new Label("1000");
//argent value declaration needed to be in global var
inGameGrid.add(argentValue, 1, 1);
Label mise = new Label("mise");
inGameGrid.add(mise, 0, 2);
......@@ -182,7 +197,7 @@ public class App extends Application {
// textfields
TextField betAmount = new TextField("0");
// only accepts numbers
// only accepts numbers, stackoverflow
betAmount.textProperty()
.addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
if (!newValue.matches("\\d*")) {
......@@ -308,6 +323,27 @@ public class App extends Application {
// maj label mise et argent
argentValue.setText(String.valueOf(gameManager.human.getMoney()));
miseValue.setText(String.valueOf(gameManager.human.getTotalBet()));
// maj scores
// update score current hand
switch (gameManager.human.getCurrentHandValue()) {
case 0:
score1.setText(String.valueOf(gameManager.human.scoreCurrentHand()));
break;
case 1:
score2.setText(String.valueOf(gameManager.human.scoreCurrentHand()));
break;
default:
score3.setText(String.valueOf(gameManager.human.scoreCurrentHand()));
break;
}
// updates score added hand
// added hand always last in human.hands
if (gameManager.human.getNunmberOfHands() == 2) {
score2.setText(String.valueOf(gameManager.human.getHands().get(1).score()));
}
if (gameManager.human.getNunmberOfHands() == 3) {
score3.setText(String.valueOf(gameManager.human.getHands().get(2).score()));
}
}
}
});
......@@ -380,9 +416,10 @@ public class App extends Application {
// BET
Button btnBet = new Button("Bet initial amount");
btnBet.setOnAction(e -> {
// action only if human has no initial bet, amount bet always positiv because of
// action only if human has no initial bet, and et < 0, and bet < money
// textfield implementation
if (gameManager.human.getInitialBet() == 0) {
if (gameManager.human.getInitialBet() == 0 && Integer.parseInt(betAmount.getText()) > 0
&& Integer.parseInt(betAmount.getText()) < gameManager.human.getMoney()) {
gameManager.human.initialBet(Integer.parseInt(betAmount.getText()));
// maj label mise et argent
argentValue.setText(String.valueOf(gameManager.human.getMoney()));
......@@ -398,12 +435,34 @@ public class App extends Application {
imgViews.get(11).setImage(new Image(card2.getPngName()));
gameManager.giveHumanOneCard(card1);
gameManager.giveHumanOneCard(card2);
// maj score current hand (always hand 1) and dealer
score1.setText(String.valueOf(gameManager.human.getHands().get(0).score()));
scoreDealer.setText(String.valueOf(gameManager.getDealerScore()));
}
});
inGameGrid.add(btnBet, 6, 6);
// NEW TURN
Button btnNewTurn = new Button("New Turn");
btnNewTurn.setOnAction(e -> {
// only if player not playing, didn't start turn or dinished his turn
if (!gameManager.human.getPlaying()) {
// remove all cards
for (ImageView imageView : imgViews) {
imageView.setImage(voidPng);
}
// removes all scores
score1.setText("0");
score2.setText("0");
score3.setText("0");
scoreDealer.setText("0");
// reset human
gameManager.human.reset();
// reset cpus
gameManager.resetCpus();
// reset dealer
gameManager.dealerReset();
}
});
inGameGrid.add(btnNewTurn, 7, 6);
// stage.setScene(sceneMenu);
......@@ -411,14 +470,6 @@ public class App extends Application {
stage.show();
}
/*
* public void cleanView(GridPane gridPane, ArrayList<ImageView> imageViews){
* for (ImageView imageView : imageViews) {
* gridPane.getChildren().remove(imageView);
* }
* }
*/
public static void main(String[] args) {
launch();
}
......
......@@ -490,9 +490,6 @@ public class GameManager {
}
}
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// part 3
public void giveDealerOneCard(Card card) {
dealer.draw(card);
}
......@@ -500,4 +497,14 @@ public class GameManager {
public void giveHumanOneCard(Card card) {
human.drawForCurrentHand(card);
}
public void resetCpus(){
for (Cpu cpu : cpuArray) {
cpu.reset();
}
}
public void dealerReset(){
this.dealer.reset();
}
}
part_3/src/main/java/org/openjfx/two_of_clubs.png

23 KiB

No preview for this file type
No preview for this file type
File added
File added
File added
File added
File added
File added
File added
File added
artifactId=sample
groupId=org.openjfx
version=1.0.0
org/openjfx/DealetTest.class
/home/rampfun/hepia/2eme/1_poo/project_object/part_3/src/test/java/org/openjfx/DealetTest.java
File added
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="org.openjfx.DealetTest" time="0.03" tests="7" errors="0" skipped="0" failures="0">
<properties>
<property name="java.specification.version" value="21"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.class.path" value="/home/rampfun/hepia/2eme/1_poo/project_object/part_3/target/test-classes:/home/rampfun/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/rampfun/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-controls/21.0.2/javafx-controls-21.0.2.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-graphics/21.0.2/javafx-graphics-21.0.2.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-base/21.0.2/javafx-base-21.0.2.jar:"/>
<property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="sun.arch.data.model" value="64"/>
<property name="java.vendor.url" value="https://java.oracle.com/"/>
<property name="os.name" value="Linux"/>
<property name="java.vm.specification.version" value="21"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="user.country" value="US"/>
<property name="sun.boot.library.path" value="/usr/local/jdk-21/lib"/>
<property name="sun.java.command" value="org.apache.maven.surefire.booter.ForkedBooter /home/rampfun/hepia/2eme/1_poo/project_object/part_3/target/surefire 2024-02-02T22-01-22_553-jvmRun1 surefire12859069346639590549tmp surefire_0933894748556831800tmp"/>
<property name="jdk.debug" value="release"/>
<property name="surefire.test.class.path" value="/home/rampfun/hepia/2eme/1_poo/project_object/part_3/target/test-classes:/home/rampfun/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/rampfun/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-controls/21.0.2/javafx-controls-21.0.2.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-graphics/21.0.2/javafx-graphics-21.0.2.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-base/21.0.2/javafx-base-21.0.2.jar:"/>
<property name="sun.cpu.endian" value="little"/>
<property name="user.home" value="/home/rampfun"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="jdk.module.path" value="/home/rampfun/hepia/2eme/1_poo/project_object/part_3/target/classes:/home/rampfun/.m2/repository/org/openjfx/javafx-controls/21.0.2/javafx-controls-21.0.2-linux.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-graphics/21.0.2/javafx-graphics-21.0.2-linux.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-base/21.0.2/javafx-base-21.0.2-linux.jar"/>
<property name="java.version.date" value="2023-09-19"/>
<property name="java.home" value="/usr/local/jdk-21"/>
<property name="file.separator" value="/"/>
<property name="basedir" value="/home/rampfun/hepia/2eme/1_poo/project_object/part_3"/>
<property name="java.vm.compressedOopsMode" value="Zero based"/>
<property name="line.separator" value="&#10;"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="surefire.real.class.path" value="/home/rampfun/.m2/repository/org/apache/maven/surefire/surefire-booter/2.22.1/surefire-booter-2.22.1.jar:/home/rampfun/.m2/repository/org/apache/maven/surefire/surefire-api/2.22.1/surefire-api-2.22.1.jar:/home/rampfun/.m2/repository/org/apache/maven/surefire/surefire-logger-api/2.22.1/surefire-logger-api-2.22.1.jar:/home/rampfun/hepia/2eme/1_poo/project_object/part_3/target/test-classes:/home/rampfun/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/rampfun/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-controls/21.0.2/javafx-controls-21.0.2.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-graphics/21.0.2/javafx-graphics-21.0.2.jar:/home/rampfun/.m2/repository/org/openjfx/javafx-base/21.0.2/javafx-base-21.0.2.jar:/home/rampfun/.m2/repository/org/apache/maven/surefire/surefire-junit4/2.22.1/surefire-junit4-2.22.1.jar"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="java.runtime.version" value="21+35-2513"/>
<property name="user.name" value="rampfun"/>
<property name="stdout.encoding" value="UTF-8"/>
<property name="path.separator" value=":"/>
<property name="os.version" value="6.5.0-15-generic"/>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="localRepository" value="/home/rampfun/.m2/repository"/>
<property name="java.vendor.url.bug" value="https://bugreport.java.com/bugreport/"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="java.version" value="21"/>
<property name="user.dir" value="/home/rampfun/hepia/2eme/1_poo/project_object/part_3"/>
<property name="os.arch" value="amd64"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="native.encoding" value="UTF-8"/>
<property name="java.library.path" value="/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib"/>
<property name="java.vm.info" value="mixed mode"/>
<property name="stderr.encoding" value="UTF-8"/>
<property name="java.vendor" value="Oracle Corporation"/>
<property name="java.vm.version" value="21+35-2513"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="java.class.version" value="65.0"/>
</properties>
<testcase name="drawTest" classname="org.openjfx.DealetTest" time="0.005"/>
<testcase name="getFirstCardTest" classname="org.openjfx.DealetTest" time="0"/>
<testcase name="ConstructorTest" classname="org.openjfx.DealetTest" time="0"/>
<testcase name="compareHandTest" classname="org.openjfx.DealetTest" time="0"/>
<testcase name="resetTest" classname="org.openjfx.DealetTest" time="0"/>
<testcase name="getHandTest" classname="org.openjfx.DealetTest" time="0"/>
<testcase name="scoreTest" classname="org.openjfx.DealetTest" time="0"/>
</testsuite>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment