fin td 12-02

This commit is contained in:
JunkJumper 2020-12-02 18:11:00 +01:00
parent b01202d60e
commit c6b3df1e09
7 changed files with 238 additions and 23 deletions

View File

@ -1,9 +1,18 @@
package TD7; package TD7;
/**
* @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline)
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 02-12-2020 13:50
*/
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import TD7.armes.Arme; import TD7.armes.Arme;
import TD7.armes.Bouclier;
import TD7.armes.Dague;
import TD7.armes.Epee;
public class WeaponFactory { public class WeaponFactory {
@ -13,12 +22,30 @@ public class WeaponFactory {
this.armes = new HashMap<String, Arme>(); this.armes = new HashMap<String, Arme>();
} }
public Arme createWeapon(String typeArme) { public Arme createWeapon(String typeArme, String nomArme) {
//TODO Arme a;
switch (typeArme) {
case "SWORD":
a = new Epee();
armes.put(nomArme, a);
break;
case "DAGGER":
a = new Dague();
armes.put(nomArme, a);
break;
case "SHIELD":
a = new Bouclier();
armes.put(nomArme, a);
break;
default:
a = null;
break;
}
return a;
} }
public Arme getWeapon(String nom) { public Arme getWeapon(String nom) {
//TODO return armes.get(nom);
} }
} }

View File

@ -0,0 +1,67 @@
package TD7.etat;
/**
* @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline)
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 02-12-2020 13:50
*/
import TD7.personnages.Personnage;
public abstract class EtatPersonnage {
private static Personnage personnage;
public EtatPersonnage(Personnage p) {
this.setPersonnage(p);
}
public double calculerDegats(Personnage p) {
//redefined into concrete class
return 0;
}
public void verifierEtatCourant(Personnage p) {
verifierMort(p);
verifierFaible(p);
verifierVivant(p);
}
private static void verifierMort(Personnage p) {
if(getPersonnage().getHp() <= 0) {
getPersonnage().setEtat(new Mort(p));
}
}
private static void verifierFaible(Personnage p) {
if((getPersonnage().getHp() <= 25) && (getPersonnage().getHp() > 0)) {
getPersonnage().setEtat(new Faible(p));
}
}
private static void verifierVivant(Personnage p) {
if(getPersonnage().getHp() >= 25) {
getPersonnage().setEtat(new Vivant(p));
}
}
public String getEtat() {
return "";
}
/**
* @return the personnage
*/
protected static Personnage getPersonnage() {
return personnage;
}
/**
* @param personnage the personnage to set
*/
private void setPersonnage(Personnage personnage) {
EtatPersonnage.personnage = personnage;
}
}

View File

@ -0,0 +1,27 @@
package TD7.etat;
/**
* @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline)
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 02-12-2020 13:50
*/
import TD7.personnages.Personnage;
public class Faible extends EtatPersonnage {
public Faible(Personnage p) {
super(p);
}
@Override
public double calculerDegats(Personnage p) {
return (getPersonnage().getForce() - (p.getProtection()*(1-(1.0/p.getHp()))));
}
@Override
public String getEtat() {
return super.getEtat() + "FAIBLE";
}
}

View File

@ -0,0 +1,30 @@
package TD7.etat;
/**
* @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline)
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 02-12-2020 13:50
*/
import TD7.personnages.Personnage;
public class Mort extends EtatPersonnage {
public Mort(Personnage p) {
super(p);
// TODO Auto-generated constructor stub
}
@Override
public double calculerDegats(Personnage p) {
return 0;
}
@Override
public String getEtat() {
return super.getEtat() + "MORT";
}
}

View File

@ -0,0 +1,28 @@
package TD7.etat;
/**
* @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline)
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 02-12-2020 13:50
*/
import TD7.personnages.Personnage;
public class Vivant extends EtatPersonnage {
public Vivant(Personnage p) {
super(p);
// TODO Auto-generated constructor stub
}
@Override
public double calculerDegats(Personnage p) {
return getPersonnage().getForce() - p.getProtection();
}
@Override
public String getEtat() {
return super.getEtat() + "VIVANT";
}
}

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import TD7.armes.Arme; import TD7.armes.Arme;
import TD7.etat.EtatPersonnage;
import TD7.etat.Vivant;
/** /**
* @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline) * @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline)
@ -14,10 +16,11 @@ import TD7.armes.Arme;
public abstract class Personnage { public abstract class Personnage {
private String nom; private String nom;
private int maxHp; private double maxHp;
private int hp; private double hp;
private List<Arme> armes; private List<Arme> armes;
private Arme armeCourante; private Arme armeCourante;
private EtatPersonnage etat;
public Personnage(String s) { public Personnage(String s) {
this.setNom(s); this.setNom(s);
@ -25,6 +28,7 @@ public abstract class Personnage {
this.setHp(this.getMaxHp()); this.setHp(this.getMaxHp());
this.setArmes(new ArrayList<Arme>()); this.setArmes(new ArrayList<Arme>());
this.setArmeCourante(null); this.setArmeCourante(null);
this.setEtat(new Vivant(this));
} }
public void vielli() { public void vielli() {
@ -50,8 +54,8 @@ public abstract class Personnage {
return this.armeCourante.getProtection(); return this.armeCourante.getProtection();
} }
private void getDamage(int a) { private void getDamage(double a) {
int calcul = this.hp - a; double calcul = this.hp - a;
if(calcul <= 0) { if(calcul <= 0) {
this.setHp(0); this.setHp(0);
@ -61,17 +65,16 @@ public abstract class Personnage {
} }
public void attaquer(Personnage p) { public void attaquer(Personnage p) {
int damage = this.getForce() - p.getProtection(); double damage = this.getEtat().calculerDegats(p);
if(damage > 0) { 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); 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() + ")!");
System.out.println(p.getNom() + " est maintenant " + this.getEtat());
} else { } else {
System.out.println(this.getNom() + " a attaqué " + p.getNom() +" et n'a pris aucun dégats."); System.out.println(this.getNom() + " a attaqué " + p.getNom() +" et n'a pris aucun dégats.");
} }
this.getEtat().verifierEtatCourant(p);
} }
/** /**
@ -91,28 +94,28 @@ public abstract class Personnage {
/** /**
* @return the hp * @return the hp
*/ */
public int getHp() { public double getHp() {
return hp; return hp;
} }
/** /**
* @param hp the hp to set * @param hp the hp to set
*/ */
private void setHp(int hp) { private void setHp(double hp) {
this.hp = hp; this.hp = hp;
} }
/** /**
* @return the maxHp * @return the maxHp
*/ */
public int getMaxHp() { public double getMaxHp() {
return maxHp; return maxHp;
} }
/** /**
* @param maxHp the maxHp to set * @param maxHp the maxHp to set
*/ */
private void setMaxHp(int maxHp) { private void setMaxHp(double maxHp) {
this.maxHp = maxHp; this.maxHp = maxHp;
} }
@ -144,5 +147,19 @@ public abstract class Personnage {
this.armeCourante = armeCourante; this.armeCourante = armeCourante;
} }
/**
* @return the etat
*/
public EtatPersonnage getEtat() {
return etat;
}
/**
* @param etat the etat to set
*/
public void setEtat(EtatPersonnage etat) {
this.etat = etat;
}
} }

View File

@ -1,10 +1,19 @@
package TD7; package TD7;
/**
* @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline)
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 25-11-2020 13:50
*/
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import TD7.armes.Arme;
import TD7.personnages.Elfe;
import TD7.personnages.Orc; import TD7.personnages.Orc;
import TD7.personnages.Personnage;
import TD7.personnages.Tauren; import TD7.personnages.Tauren;
@ -31,12 +40,22 @@ public class testArmes {
assertEquals(w, w1); assertEquals(w, w1);
Personnage azag = new Orc("Azag", 5); Personnage azag = new Orc("Azag", 5);
try { try {
assertEquals(Class.forName("td5.p1.arme.Epée"), azag.getArme().getClass()); assertEquals(Class.forName("TD7.armes.Epee"), azag.getArmeCourante().getClass());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test
public void test3() {
Elfe a = new Elfe("a", "3");
Elfe b = new Elfe("b", "3");
for (int i = 0; i < 5; ++i) {
a.attaquer(b);
}
}
/* /*
@Test @Test
public void test3() { public void test3() {