Initial commit

This commit is contained in:
aminecmi
2014-10-03 15:34:03 +02:00
commit 9e71bf4114
21 changed files with 418 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
package Comportements;
public class ComportementAPiedAvecHache implements ComportementCombat {
@Override
public String combattre() {
return "Par ma hache !";
}
}

View File

@@ -0,0 +1,5 @@
package Comportements;
public interface ComportementCombat {
String combattre();
}

View File

@@ -0,0 +1,8 @@
package Comportements;
public class ComportementCombatAvecCheval implements ComportementCombat {
@Override
public String combattre() {
return "Huu ! Attaque";
}
}

View File

@@ -0,0 +1,9 @@
package Comportements;
public class ComportementCrier implements ComportementEmmetreSon {
@Override
public String emmetreSon() {
return "Bwaaaaaa";
}
}

View File

@@ -0,0 +1,5 @@
package Comportements;
public interface ComportementEmmetreSon {
public String emmetreSon();
}

View 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
View 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";
}
}

View 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";
}
}

View 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
View 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
View 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());
}
}