fin td 12-02
This commit is contained in:
parent
b01202d60e
commit
c6b3df1e09
@ -1,9 +1,18 @@
|
||||
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.Map;
|
||||
|
||||
import TD7.armes.Arme;
|
||||
import TD7.armes.Bouclier;
|
||||
import TD7.armes.Dague;
|
||||
import TD7.armes.Epee;
|
||||
|
||||
public class WeaponFactory {
|
||||
|
||||
@ -13,12 +22,30 @@ public class WeaponFactory {
|
||||
this.armes = new HashMap<String, Arme>();
|
||||
}
|
||||
|
||||
public Arme createWeapon(String typeArme) {
|
||||
//TODO
|
||||
public Arme createWeapon(String typeArme, String nomArme) {
|
||||
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) {
|
||||
//TODO
|
||||
return armes.get(nom);
|
||||
}
|
||||
|
||||
}
|
||||
|
67
2020-2021/src/TD7/etat/EtatPersonnage.java
Normal file
67
2020-2021/src/TD7/etat/EtatPersonnage.java
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
27
2020-2021/src/TD7/etat/Faible.java
Normal file
27
2020-2021/src/TD7/etat/Faible.java
Normal 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";
|
||||
|
||||
}
|
||||
}
|
30
2020-2021/src/TD7/etat/Mort.java
Normal file
30
2020-2021/src/TD7/etat/Mort.java
Normal 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";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
28
2020-2021/src/TD7/etat/Vivant.java
Normal file
28
2020-2021/src/TD7/etat/Vivant.java
Normal 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";
|
||||
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import TD7.armes.Arme;
|
||||
import TD7.etat.EtatPersonnage;
|
||||
import TD7.etat.Vivant;
|
||||
|
||||
/**
|
||||
* @ Author: CrewmateGroup (Kitabdjian Léo - Longuemare Hugo - Rizzo Michael - Srifi Pauline)
|
||||
@ -14,10 +16,11 @@ import TD7.armes.Arme;
|
||||
public abstract class Personnage {
|
||||
|
||||
private String nom;
|
||||
private int maxHp;
|
||||
private int hp;
|
||||
private double maxHp;
|
||||
private double hp;
|
||||
private List<Arme> armes;
|
||||
private Arme armeCourante;
|
||||
private EtatPersonnage etat;
|
||||
|
||||
public Personnage(String s) {
|
||||
this.setNom(s);
|
||||
@ -25,6 +28,7 @@ public abstract class Personnage {
|
||||
this.setHp(this.getMaxHp());
|
||||
this.setArmes(new ArrayList<Arme>());
|
||||
this.setArmeCourante(null);
|
||||
this.setEtat(new Vivant(this));
|
||||
}
|
||||
|
||||
public void vielli() {
|
||||
@ -50,8 +54,8 @@ public abstract class Personnage {
|
||||
return this.armeCourante.getProtection();
|
||||
}
|
||||
|
||||
private void getDamage(int a) {
|
||||
int calcul = this.hp - a;
|
||||
private void getDamage(double a) {
|
||||
double calcul = this.hp - a;
|
||||
|
||||
if(calcul <= 0) {
|
||||
this.setHp(0);
|
||||
@ -61,17 +65,16 @@ public abstract class Personnage {
|
||||
}
|
||||
|
||||
public void attaquer(Personnage p) {
|
||||
int damage = this.getForce() - p.getProtection();
|
||||
|
||||
if(damage > 0) {
|
||||
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() + ")!");
|
||||
} else {
|
||||
System.out.println(this.getNom() + " a attaqué " + p.getNom() +" et n'a pris aucun dégats.");
|
||||
}
|
||||
|
||||
|
||||
double damage = this.getEtat().calculerDegats(p);
|
||||
if(damage > 0) {
|
||||
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() + " est maintenant " + this.getEtat());
|
||||
} else {
|
||||
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
|
||||
*/
|
||||
public int getHp() {
|
||||
public double getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hp the hp to set
|
||||
*/
|
||||
private void setHp(int hp) {
|
||||
private void setHp(double hp) {
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maxHp
|
||||
*/
|
||||
public int getMaxHp() {
|
||||
public double getMaxHp() {
|
||||
return maxHp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxHp the maxHp to set
|
||||
*/
|
||||
private void setMaxHp(int maxHp) {
|
||||
private void setMaxHp(double maxHp) {
|
||||
this.maxHp = maxHp;
|
||||
}
|
||||
|
||||
@ -143,6 +146,20 @@ public abstract class Personnage {
|
||||
protected void setArmeCourante(Arme 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,19 @@
|
||||
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 org.junit.jupiter.api.Test;
|
||||
|
||||
import TD7.armes.Arme;
|
||||
import TD7.personnages.Elfe;
|
||||
import TD7.personnages.Orc;
|
||||
import TD7.personnages.Personnage;
|
||||
import TD7.personnages.Tauren;
|
||||
|
||||
|
||||
@ -31,12 +40,22 @@ public class testArmes {
|
||||
assertEquals(w, w1);
|
||||
Personnage azag = new Orc("Azag", 5);
|
||||
try {
|
||||
assertEquals(Class.forName("td5.p1.arme.Epée"), azag.getArme().getClass());
|
||||
assertEquals(Class.forName("TD7.armes.Epee"), azag.getArmeCourante().getClass());
|
||||
} catch (ClassNotFoundException e) {
|
||||
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
|
||||
public void test3() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user