diff --git a/pom.xml b/pom.xml index 43897eef6f3d51ddbe0a330fc1911a89a647d0ff..7cb8921635687777cf25035757163633f56ebad6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,10 +4,10 @@ <modelVersion>4.0.0</modelVersion> <groupId>ch.hepia</groupId> - <artifactId>template_maven</artifactId> + <artifactId>Java_Card_Game</artifactId> <version>1.0-SNAPSHOT</version> - <name>template_maven</name> + <name>Java_Card_Game</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> diff --git a/src/main/java/ch/hepia/App.java b/src/main/java/ch/hepia/App.java index c8c383dce2b60e33cfb4efec0aa3e0e69ca68195..53f16a6c9a6d2c3d9695c4068772a1260b201399 100644 --- a/src/main/java/ch/hepia/App.java +++ b/src/main/java/ch/hepia/App.java @@ -1,7 +1,14 @@ package ch.hepia; public class App { - public static void main(String args[]) { - System.out.println("Hello World depuis un template maven super cool !"); + + public static void main(String[] args) { + + JeudeCarte jeuDeCartesStandard = new JeudeCarte(32); + jeuDeCartesStandard.afficherPaquet(); + jeuDeCartesStandard.shuffle(); + System.out.println("----------------------------------------"); + jeuDeCartesStandard.afficherPaquet(); } + } diff --git a/src/main/java/ch/hepia/Carte.java b/src/main/java/ch/hepia/Carte.java new file mode 100644 index 0000000000000000000000000000000000000000..55b6d09963cb5a07660ae8c1ccac488cba6e2c9c --- /dev/null +++ b/src/main/java/ch/hepia/Carte.java @@ -0,0 +1,85 @@ +package ch.hepia; + +enum COULEUR { + coeur, + carreau, + pique, + trefle +} + +public class Carte { + + final private COULEUR couleur; + final private int rang; + private int force; + + private static final int NOMBRE_DE_RANGS = 13; + + public Carte(COULEUR couleur, int rang) { + + if (rang < 0 || rang > NOMBRE_DE_RANGS) { + throw new IllegalArgumentException("Carte invalide : rang incorrect"); + } + + this.couleur = couleur; + this.rang = rang; + + } + + public Carte(COULEUR couleur, int rang, int force) { + + if (rang < 0 || rang > NOMBRE_DE_RANGS) { + throw new IllegalArgumentException("Carte invalide : rang incorrect"); + } + + this.couleur = couleur; + this.rang = rang; + this.force = force; + + } + + public COULEUR getCouleur() { + + return this.couleur; + + } + + public int getRang() { + + return this.rang; + + } + + public int getForce() { + + return this.force; + + } + + public String getNomCouleur() { + + String[] NOMS_COULEURS = { "Coeur", "Carreau", "Pique", "Trèfle" }; + return NOMS_COULEURS[couleur.ordinal()]; + + } + + public String getNomRang() { + + String[] NOMS_RANGS = { "Joker", "As", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Valet", "Dame", "Roi" }; + return NOMS_RANGS[rang]; + + } + + public String getNomComplet() { + if (getRang() == 0) { + + return getNomRang(); + + } else { + + return getNomRang() + (getCouleur() == null ? "" : " de " + getNomCouleur()); + + } + } + +} diff --git a/src/main/java/ch/hepia/JeudeCarte.java b/src/main/java/ch/hepia/JeudeCarte.java new file mode 100644 index 0000000000000000000000000000000000000000..56a6575449a1746584e77dfb09f6ab95b50a8327 --- /dev/null +++ b/src/main/java/ch/hepia/JeudeCarte.java @@ -0,0 +1,50 @@ +package ch.hepia; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class JeudeCarte { + + private List<Carte> jeuDeCartes; + + public JeudeCarte(int nb) { + + jeuDeCartes = new ArrayList<>(); + + for (COULEUR couleur : COULEUR.values()) { + + for (int rang = 1; rang < (nb / 4) + 1; rang++) { + + jeuDeCartes.add(new Carte(couleur, rang)); + + } + + } + + if (nb % 4 != 0) { + + for (int x = 0; x < nb % 4; x++) { + + jeuDeCartes.add(new Carte(COULEUR.carreau, 0)); + + } + } + + } + + public void shuffle() { + + Collections.shuffle(jeuDeCartes); + + } + + public void afficherPaquet() { + for (Carte carte : jeuDeCartes) { + + System.out.println(carte.getNomComplet()); + + } + } + +} diff --git a/src/main/java/ch/hepia/Main.java b/src/main/java/ch/hepia/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..81b4bcb219b4475df242a0a986f4bd4be16dbbca --- /dev/null +++ b/src/main/java/ch/hepia/Main.java @@ -0,0 +1,5 @@ +package ch.hepia; + +public class Main { + +} diff --git a/src/test/java/ch/hepia/CarteTest.java b/src/test/java/ch/hepia/CarteTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f1ac133fe7f7a24190d80d303fd27399edda526f --- /dev/null +++ b/src/test/java/ch/hepia/CarteTest.java @@ -0,0 +1,49 @@ +package ch.hepia; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class CarteTest { + + @Test + public void testGetCouleur() { + Carte carte = new Carte(COULEUR.coeur, 2); + assertEquals(COULEUR.coeur, carte.getCouleur()); + } + + @Test + public void testGetRang() { + Carte carte = new Carte(COULEUR.carreau, 7); + assertEquals(7, carte.getRang()); + } + + @Test + public void testGetForce() { + Carte carte = new Carte(COULEUR.trefle, 12, 10); + assertEquals(10, carte.getForce()); + } + + @Test + public void testGetNomCouleur() { + Carte carte = new Carte(COULEUR.coeur, 0); + assertEquals("Coeur", carte.getNomCouleur()); + } + + @Test + public void testGetNomRang() { + Carte carte = new Carte(COULEUR.coeur, 2); + assertEquals("2", carte.getNomRang()); + } + + @Test + public void testGetNomComplet() { + Carte carte = new Carte(COULEUR.carreau, 12); + assertEquals("Dame de Carreau", carte.getNomComplet()); + } + + @Test + public void testGetNomComplet_2() { + Carte carte = new Carte(COULEUR.carreau, 0); + assertEquals("Joker", carte.getNomComplet()); + } +} \ No newline at end of file diff --git a/target/classes/ch/hepia/App.class b/target/classes/ch/hepia/App.class index a2321efa160fea0eb3ec223fad6172ed0a602e1a..8d3b9dbbfdc30b448e950ad51b56e38c84566f9d 100644 Binary files a/target/classes/ch/hepia/App.class and b/target/classes/ch/hepia/App.class differ diff --git a/target/classes/ch/hepia/COULEUR.class b/target/classes/ch/hepia/COULEUR.class new file mode 100644 index 0000000000000000000000000000000000000000..c38a76f38b5f56aec3100849ad749e77c1255bcd Binary files /dev/null and b/target/classes/ch/hepia/COULEUR.class differ diff --git a/target/classes/ch/hepia/Carte.class b/target/classes/ch/hepia/Carte.class new file mode 100644 index 0000000000000000000000000000000000000000..6ee4be2ec9d067b2e556b6378e20b2b2cce9dab0 Binary files /dev/null and b/target/classes/ch/hepia/Carte.class differ diff --git a/target/classes/ch/hepia/JeudeCarte.class b/target/classes/ch/hepia/JeudeCarte.class new file mode 100644 index 0000000000000000000000000000000000000000..89558dd3cdc5c06109e8aa37fbdfb5ce8deaedab Binary files /dev/null and b/target/classes/ch/hepia/JeudeCarte.class differ diff --git a/target/classes/ch/hepia/Main.class b/target/classes/ch/hepia/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..7c82095527ac8940f83aaf2b36662b4b6e481857 Binary files /dev/null and b/target/classes/ch/hepia/Main.class differ diff --git a/target/generated-sources/.DS_Store b/target/generated-sources/.DS_Store deleted file mode 100644 index 3f605b2bd21e831129c70fb6f0c19ca511195f36..0000000000000000000000000000000000000000 Binary files a/target/generated-sources/.DS_Store and /dev/null differ diff --git a/target/generated-test-sources/.DS_Store b/target/generated-test-sources/.DS_Store deleted file mode 100644 index d2d2c38519f282695c20e059b02c93474c99f40a..0000000000000000000000000000000000000000 Binary files a/target/generated-test-sources/.DS_Store and /dev/null differ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index cff3aaafcb853f5e46ea6f3d3276b08cfea66c86..0c59c3ca29800d6357a6b7d77da3e1dd76c1dbd3 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1 +1,4 @@ ch/hepia/App.class +ch/hepia/COULEUR.class +ch/hepia/Carte.class +ch/hepia/JeudeCarte.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 8e655106cc37b26a3feb265a93a6d4d6afd6ebb1..54d2d1f36725ffe421a34fca5c105411c1f5cb54 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1 +1,3 @@ +/home/padi/Git/java-card-game/src/main/java/ch/hepia/JeudeCarte.java +/home/padi/Git/java-card-game/src/main/java/ch/hepia/Carte.java /home/padi/Git/java-card-game/src/main/java/ch/hepia/App.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst deleted file mode 100644 index 7cf62729347661a696e8812d979967b9f6637bb3..0000000000000000000000000000000000000000 --- a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst +++ /dev/null @@ -1 +0,0 @@ -ch/hepia/AppTest.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/target/surefire-reports/TEST-ch.hepia.AppTest.xml b/target/surefire-reports/TEST-ch.hepia.AppTest.xml deleted file mode 100644 index 6df3645414f25459675479afba02ecc873a0086c..0000000000000000000000000000000000000000 --- a/target/surefire-reports/TEST-ch.hepia.AppTest.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?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="ch.hepia.AppTest" time="0.049" tests="1" errors="0" skipped="0" failures="0"> - <properties> - <property name="java.specification.version" value="18"/> - <property name="sun.jnu.encoding" value="UTF-8"/> - <property name="java.class.path" value="/home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17/target/test-classes:/home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17/target/classes:/home/tibonhomme/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/tibonhomme/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-controls/19/javafx-controls-19.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-controls/19/javafx-controls-19-linux.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-graphics/19/javafx-graphics-19.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-graphics/19/javafx-graphics-19-linux.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-base/19/javafx-base-19.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-base/19/javafx-base-19-linux.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="18"/> - <property name="sun.java.launcher" value="SUN_STANDARD"/> - <property name="user.country" value="US"/> - <property name="sun.boot.library.path" value="/usr/lib/jvm/jdk-18/lib"/> - <property name="sun.java.command" value="/home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17/target/surefire/surefirebooter13178483302707467755.jar /home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17/target/surefire 2023-09-22T14-26-22_654-jvmRun1 surefire4340852442493115901tmp surefire_08105387393367528216tmp"/> - <property name="jdk.debug" value="release"/> - <property name="surefire.test.class.path" value="/home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17/target/test-classes:/home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17/target/classes:/home/tibonhomme/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/tibonhomme/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-controls/19/javafx-controls-19.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-controls/19/javafx-controls-19-linux.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-graphics/19/javafx-graphics-19.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-graphics/19/javafx-graphics-19-linux.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-base/19/javafx-base-19.jar:/home/tibonhomme/.m2/repository/org/openjfx/javafx-base/19/javafx-base-19-linux.jar:"/> - <property name="sun.cpu.endian" value="little"/> - <property name="user.home" value="/home/tibonhomme"/> - <property name="user.language" value="en"/> - <property name="java.specification.vendor" value="Oracle Corporation"/> - <property name="java.version.date" value="2022-08-18"/> - <property name="java.home" value="/usr/lib/jvm/jdk-18"/> - <property name="file.separator" value="/"/> - <property name="basedir" value="/home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17"/> - <property name="java.vm.compressedOopsMode" value="Zero based"/> - <property name="line.separator" value=" "/> - <property name="java.vm.specification.vendor" value="Oracle Corporation"/> - <property name="java.specification.name" value="Java Platform API Specification"/> - <property name="surefire.real.class.path" value="/home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17/target/surefire/surefirebooter13178483302707467755.jar"/> - <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/> - <property name="java.runtime.version" value="18.0.2.1+1-1"/> - <property name="user.name" value="tibonhomme"/> - <property name="path.separator" value=":"/> - <property name="os.version" value="6.2.6-76060206-generic"/> - <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/> - <property name="file.encoding" value="UTF-8"/> - <property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/> - <property name="localRepository" value="/home/tibonhomme/.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="18.0.2.1"/> - <property name="user.dir" value="/home/tibonhomme/Documents/Hepia/poo/maven-template-jdk17"/> - <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, sharing"/> - <property name="java.vendor" value="Oracle Corporation"/> - <property name="java.vm.version" value="18.0.2.1+1-1"/> - <property name="sun.io.unicode.encoding" value="UnicodeLittle"/> - <property name="java.class.version" value="62.0"/> - </properties> - <testcase name="testFake" classname="ch.hepia.AppTest" time="0.005"/> -</testsuite> \ No newline at end of file diff --git a/target/surefire-reports/ch.hepia.AppTest.txt b/target/surefire-reports/ch.hepia.AppTest.txt deleted file mode 100644 index 51bd83a9e246a2bc35b3f98101c793a82deac24b..0000000000000000000000000000000000000000 --- a/target/surefire-reports/ch.hepia.AppTest.txt +++ /dev/null @@ -1,4 +0,0 @@ -------------------------------------------------------------------------------- -Test set: ch.hepia.AppTest -------------------------------------------------------------------------------- -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.049 s - in ch.hepia.AppTest diff --git a/target/test-classes/ch/hepia/CarteTest.class b/target/test-classes/ch/hepia/CarteTest.class new file mode 100644 index 0000000000000000000000000000000000000000..60dcda85d37ead5584d2ad54aaa8affb1935c4b2 Binary files /dev/null and b/target/test-classes/ch/hepia/CarteTest.class differ