diff --git a/2020-2021/src/TD7/WeaponFactory.java b/2020-2021/src/TD7/WeaponFactory.java new file mode 100644 index 0000000..1aad7f5 --- /dev/null +++ b/2020-2021/src/TD7/WeaponFactory.java @@ -0,0 +1,24 @@ +package TD7; + +import java.util.HashMap; +import java.util.Map; + +import TD7.armes.Arme; + +public class WeaponFactory { + + private Map armes; + + public WeaponFactory() { + this.armes = new HashMap(); + } + + public Arme createWeapon(String typeArme) { + //TODO + } + + public Arme getWeapon(String nom) { + //TODO + } + +} diff --git a/2020-2021/src/TD7/personnages/Personnage.java b/2020-2021/src/TD7/personnages/Personnage.java index 4226bf5..ccd6e85 100644 --- a/2020-2021/src/TD7/personnages/Personnage.java +++ b/2020-2021/src/TD7/personnages/Personnage.java @@ -64,9 +64,9 @@ public abstract class Personnage { int damage = this.getForce() - p.getProtection(); if(damage > 0) { - System.out.print(this.getNom() + this.getHp() + " a attaqué " + p.getNom() + p.getHp() + "."); + System.out.print(this.getNom() + "(" + this.getHp() + ")" + " a attaqué " + p.getNom() + "(" + p.getHp() + ")" + "."); p.getDamage(damage); - System.out.println(" " + p.getNom() + " a perdu " + damage + " HP" + p.getHp() + "!"); + System.out.println(" " + p.getNom() + " a perdu " + damage + " HP " + "(" + p.getHp() + ")!"); } else { System.out.println(this.getNom() + " a attaqué " + p.getNom() +" et n'a pris aucun dégats."); } diff --git a/2020-2021/tests/TD7/testArmes.java b/2020-2021/tests/TD7/testArmes.java new file mode 100644 index 0000000..f0145d7 --- /dev/null +++ b/2020-2021/tests/TD7/testArmes.java @@ -0,0 +1,63 @@ +package TD7; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import TD7.personnages.Orc; +import TD7.personnages.Tauren; + + + +public class testArmes { + + @Test + public void testPartie1() { + Tauren diablon = new Tauren("Diablon", 15); + Orc azag = new Orc("Azag", 5); + + diablon.attaquer(azag); + azag.attaquer(diablon); + assertEquals(100, azag.getHp()); + assertEquals(95, diablon.getHp()); + } + + + @Test + public void test2() { + WeaponFactory wf = new WeaponFactory(); + Arme w = wf.createWeapon("SWORD", "excalibur"); + Arme w1 = wf.getWeapon("excalibur"); + assertEquals(w, w1); + Personnage azag = new Orc("Azag", 5); + try { + assertEquals(Class.forName("td5.p1.arme.Epée"), azag.getArme().getClass()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + /* + @Test + public void test3() { + WeaponFactory wp = new WeaponFactory(); + WeaponFactory wp2 = new ModernWeaponFactory(); + String nom = "Ref"; + int i = 0; + Arme a1 = wp.createWeapon("SWORD", nom + i); + i++; + Arme a2 = wp2.createWeapon("Dague", nom + i); + i++; + Arme a3 = wp2.createWeapon("Fusil", nom + i); + i++; + Arme a4 = wp2.createWeapon("Missil", nom + i); // Type non reconnu + assertTrue(a1 != null); + assertTrue(a2 != null); + assertTrue(a3 != null); + assertTrue(a4 == null); + assertEquals(a1, wp.getWeapon(nom + 0)); // On retrouve une arme créée par un autre + assertEquals(a3, wp.getWeapon(nom + 2)); + } + */ + +}