Initial commit
This commit is contained in:
8
src/Comportements/ComportementAPiedAvecHache.java
Normal file
8
src/Comportements/ComportementAPiedAvecHache.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package Comportements;
|
||||
|
||||
public class ComportementAPiedAvecHache implements ComportementCombat {
|
||||
@Override
|
||||
public String combattre() {
|
||||
return "Par ma hache !";
|
||||
}
|
||||
}
|
||||
5
src/Comportements/ComportementCombat.java
Normal file
5
src/Comportements/ComportementCombat.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package Comportements;
|
||||
|
||||
public interface ComportementCombat {
|
||||
String combattre();
|
||||
}
|
||||
8
src/Comportements/ComportementCombatAvecCheval.java
Normal file
8
src/Comportements/ComportementCombatAvecCheval.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package Comportements;
|
||||
|
||||
public class ComportementCombatAvecCheval implements ComportementCombat {
|
||||
@Override
|
||||
public String combattre() {
|
||||
return "Huu ! Attaque";
|
||||
}
|
||||
}
|
||||
9
src/Comportements/ComportementCrier.java
Normal file
9
src/Comportements/ComportementCrier.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package Comportements;
|
||||
|
||||
public class ComportementCrier implements ComportementEmmetreSon {
|
||||
|
||||
@Override
|
||||
public String emmetreSon() {
|
||||
return "Bwaaaaaa";
|
||||
}
|
||||
}
|
||||
5
src/Comportements/ComportementEmmetreSon.java
Normal file
5
src/Comportements/ComportementEmmetreSon.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package Comportements;
|
||||
|
||||
public interface ComportementEmmetreSon {
|
||||
public String emmetreSon();
|
||||
}
|
||||
10
src/Comportements/ComportementParlerCommeUnePrincesse.java
Normal file
10
src/Comportements/ComportementParlerCommeUnePrincesse.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Comportements;
|
||||
|
||||
public class ComportementParlerCommeUnePrincesse implements ComportementEmmetreSon {
|
||||
|
||||
@Override
|
||||
public String emmetreSon() {
|
||||
return "La la la la la";
|
||||
}
|
||||
|
||||
}
|
||||
19
src/Person/Chevalier.java
Normal file
19
src/Person/Chevalier.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package Person;
|
||||
|
||||
import Comportements.ComportementCrier;
|
||||
import Comportements.ComportementCombatAvecCheval;
|
||||
|
||||
public class Chevalier extends Personnage {
|
||||
|
||||
|
||||
public Chevalier(String nom) {
|
||||
super(nom);
|
||||
this.comportementCombat = new ComportementCombatAvecCheval();
|
||||
this.comportementEmmetreSon = new ComportementCrier();
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return "Chevalier " + this.nom + " à votre service";
|
||||
}
|
||||
|
||||
}
|
||||
17
src/Person/Fantasssin.java
Normal file
17
src/Person/Fantasssin.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Person;
|
||||
|
||||
import Comportements.ComportementAPiedAvecHache;
|
||||
import Comportements.ComportementCrier;
|
||||
|
||||
public class Fantasssin extends Personnage {
|
||||
public Fantasssin(String nom) {
|
||||
super(nom);
|
||||
this.comportementCombat = new ComportementAPiedAvecHache();
|
||||
this.comportementEmmetreSon = new ComportementCrier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNom() {
|
||||
return "Seraffin " + this.nom + ". A vos ordres";
|
||||
}
|
||||
}
|
||||
42
src/Person/Personnage.java
Normal file
42
src/Person/Personnage.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package Person;
|
||||
|
||||
import Comportements.ComportementCombat;
|
||||
import Comportements.ComportementEmmetreSon;
|
||||
|
||||
public abstract class Personnage {
|
||||
protected String nom;
|
||||
protected ComportementCombat comportementCombat;
|
||||
protected ComportementEmmetreSon comportementEmmetreSon;
|
||||
|
||||
protected Personnage(String nom) {
|
||||
this.nom = nom;
|
||||
this.comportementCombat = null;
|
||||
this.comportementEmmetreSon = null;
|
||||
}
|
||||
|
||||
public abstract String getNom();
|
||||
|
||||
public void setComportementCombat(ComportementCombat comportementCombat) {
|
||||
this.comportementCombat = comportementCombat;
|
||||
}
|
||||
|
||||
public void setComportementEmmetreSon(ComportementEmmetreSon comportementEmmetreSon) {
|
||||
this.comportementEmmetreSon = comportementEmmetreSon;
|
||||
}
|
||||
|
||||
public ComportementEmmetreSon getComportementEmmetreSon() {
|
||||
return comportementEmmetreSon;
|
||||
}
|
||||
|
||||
public String EmmetreSon() {
|
||||
return this.comportementEmmetreSon.emmetreSon();
|
||||
}
|
||||
|
||||
public String Combattre() {
|
||||
if (this.comportementCombat != null)
|
||||
return this.comportementCombat.combattre();
|
||||
else {
|
||||
return "Ohhh, je suis trop faible pour combattre !";
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Person/Princesse.java
Normal file
17
src/Person/Princesse.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Person;
|
||||
|
||||
import Comportements.ComportementParlerCommeUnePrincesse;
|
||||
|
||||
public class Princesse extends Personnage {
|
||||
|
||||
public Princesse(String nom) {
|
||||
super(nom);
|
||||
this.comportementEmmetreSon = new ComportementParlerCommeUnePrincesse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNom() {
|
||||
return "Je suis " + this.nom + " princesse des princesses";
|
||||
}
|
||||
|
||||
}
|
||||
76
src/SimulationJeu.java
Normal file
76
src/SimulationJeu.java
Normal file
@@ -0,0 +1,76 @@
|
||||
import Comportements.ComportementAPiedAvecHache;
|
||||
import Comportements.ComportementCombat;
|
||||
import Comportements.ComportementEmmetreSon;
|
||||
import Comportements.ComportementParlerCommeUnePrincesse;
|
||||
import Person.Chevalier;
|
||||
import Person.Fantasssin;
|
||||
import Person.Personnage;
|
||||
import Person.Princesse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SimulationJeu {
|
||||
ArrayList<Personnage> liste;
|
||||
|
||||
public SimulationJeu() {
|
||||
liste = new ArrayList<Personnage>();
|
||||
}
|
||||
|
||||
public String afficheTous() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for(Personnage p: liste) {
|
||||
result.append(p.getNom());
|
||||
result.append(System.getProperty("line.separator"));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public void changerComportementCombat(Personnage p, ComportementCombat c){
|
||||
p.setComportementCombat(c);
|
||||
}
|
||||
|
||||
public void changerComportementEmmetreSon(Personnage p, ComportementEmmetreSon c){
|
||||
p.setComportementEmmetreSon(c);
|
||||
}
|
||||
|
||||
public void creationPersonnages() {
|
||||
Princesse p = new Princesse("Fiona");
|
||||
Chevalier z = new Chevalier("Zodiac");
|
||||
Fantasssin f = new Fantasssin("Fantastic");
|
||||
|
||||
liste.add(p);
|
||||
liste.add(z);
|
||||
liste.add(f);
|
||||
}
|
||||
|
||||
public String emmetreUnSonTous() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Personnage p: liste) {
|
||||
result.append(p.EmmetreSon());
|
||||
result.append(System.getProperty("line.separator"));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String lancerCombar() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Personnage p: liste) {
|
||||
result.append(p.Combattre());
|
||||
result.append(System.getProperty("line.separator"));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args){
|
||||
SimulationJeu s = new SimulationJeu();
|
||||
s.creationPersonnages();
|
||||
System.out.println(s.afficheTous());
|
||||
System.out.println(s.emmetreUnSonTous());
|
||||
System.out.println(s.lancerCombar());
|
||||
s.changerComportementCombat(s.liste.get(0), new ComportementAPiedAvecHache());
|
||||
s.changerComportementEmmetreSon(s.liste.get(0), new ComportementParlerCommeUnePrincesse());
|
||||
System.out.println(s.emmetreUnSonTous());
|
||||
System.out.println(s.lancerCombar());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user