From 9e71bf411470306b70268e3ceefbc1bf15503e7b Mon Sep 17 00:00:00 2001 From: aminecmi Date: Fri, 3 Oct 2014 15:34:03 +0200 Subject: [PATCH] Initial commit --- .idea/.name | 1 + .idea/compiler.xml | 23 ++++ .idea/copyright/profiles_settings.xml | 3 + .idea/encodings.xml | 5 + .idea/misc.xml | 11 ++ .idea/modules.xml | 9 ++ .idea/scopes/scope_settings.xml | 5 + .idea/uiDesigner.xml | 125 ++++++++++++++++++ .idea/vcs.xml | 8 ++ LesSyms4.iml | 12 ++ .../ComportementAPiedAvecHache.java | 8 ++ src/Comportements/ComportementCombat.java | 5 + .../ComportementCombatAvecCheval.java | 8 ++ src/Comportements/ComportementCrier.java | 9 ++ src/Comportements/ComportementEmmetreSon.java | 5 + .../ComportementParlerCommeUnePrincesse.java | 10 ++ src/Person/Chevalier.java | 19 +++ src/Person/Fantasssin.java | 17 +++ src/Person/Personnage.java | 42 ++++++ src/Person/Princesse.java | 17 +++ src/SimulationJeu.java | 76 +++++++++++ 21 files changed, 418 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 LesSyms4.iml create mode 100644 src/Comportements/ComportementAPiedAvecHache.java create mode 100644 src/Comportements/ComportementCombat.java create mode 100644 src/Comportements/ComportementCombatAvecCheval.java create mode 100644 src/Comportements/ComportementCrier.java create mode 100644 src/Comportements/ComportementEmmetreSon.java create mode 100644 src/Comportements/ComportementParlerCommeUnePrincesse.java create mode 100644 src/Person/Chevalier.java create mode 100644 src/Person/Fantasssin.java create mode 100644 src/Person/Personnage.java create mode 100644 src/Person/Princesse.java create mode 100644 src/SimulationJeu.java diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..721dd2f --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +LesSyms4 \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..be02ef9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d5759cb --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..9d32e50 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/LesSyms4.iml b/LesSyms4.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/LesSyms4.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/Comportements/ComportementAPiedAvecHache.java b/src/Comportements/ComportementAPiedAvecHache.java new file mode 100644 index 0000000..939cd9f --- /dev/null +++ b/src/Comportements/ComportementAPiedAvecHache.java @@ -0,0 +1,8 @@ +package Comportements; + +public class ComportementAPiedAvecHache implements ComportementCombat { + @Override + public String combattre() { + return "Par ma hache !"; + } +} diff --git a/src/Comportements/ComportementCombat.java b/src/Comportements/ComportementCombat.java new file mode 100644 index 0000000..63b4f94 --- /dev/null +++ b/src/Comportements/ComportementCombat.java @@ -0,0 +1,5 @@ +package Comportements; + +public interface ComportementCombat { + String combattre(); +} diff --git a/src/Comportements/ComportementCombatAvecCheval.java b/src/Comportements/ComportementCombatAvecCheval.java new file mode 100644 index 0000000..fda4d75 --- /dev/null +++ b/src/Comportements/ComportementCombatAvecCheval.java @@ -0,0 +1,8 @@ +package Comportements; + +public class ComportementCombatAvecCheval implements ComportementCombat { + @Override + public String combattre() { + return "Huu ! Attaque"; + } +} diff --git a/src/Comportements/ComportementCrier.java b/src/Comportements/ComportementCrier.java new file mode 100644 index 0000000..90a25af --- /dev/null +++ b/src/Comportements/ComportementCrier.java @@ -0,0 +1,9 @@ +package Comportements; + +public class ComportementCrier implements ComportementEmmetreSon { + + @Override + public String emmetreSon() { + return "Bwaaaaaa"; + } +} diff --git a/src/Comportements/ComportementEmmetreSon.java b/src/Comportements/ComportementEmmetreSon.java new file mode 100644 index 0000000..6fce7f1 --- /dev/null +++ b/src/Comportements/ComportementEmmetreSon.java @@ -0,0 +1,5 @@ +package Comportements; + +public interface ComportementEmmetreSon { + public String emmetreSon(); +} diff --git a/src/Comportements/ComportementParlerCommeUnePrincesse.java b/src/Comportements/ComportementParlerCommeUnePrincesse.java new file mode 100644 index 0000000..f718ad2 --- /dev/null +++ b/src/Comportements/ComportementParlerCommeUnePrincesse.java @@ -0,0 +1,10 @@ +package Comportements; + +public class ComportementParlerCommeUnePrincesse implements ComportementEmmetreSon { + + @Override + public String emmetreSon() { + return "La la la la la"; + } + +} diff --git a/src/Person/Chevalier.java b/src/Person/Chevalier.java new file mode 100644 index 0000000..acb08f3 --- /dev/null +++ b/src/Person/Chevalier.java @@ -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"; + } + +} diff --git a/src/Person/Fantasssin.java b/src/Person/Fantasssin.java new file mode 100644 index 0000000..dbe73bf --- /dev/null +++ b/src/Person/Fantasssin.java @@ -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"; + } +} diff --git a/src/Person/Personnage.java b/src/Person/Personnage.java new file mode 100644 index 0000000..d26c08e --- /dev/null +++ b/src/Person/Personnage.java @@ -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 !"; + } + } +} diff --git a/src/Person/Princesse.java b/src/Person/Princesse.java new file mode 100644 index 0000000..f01c8c7 --- /dev/null +++ b/src/Person/Princesse.java @@ -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"; + } + +} diff --git a/src/SimulationJeu.java b/src/SimulationJeu.java new file mode 100644 index 0000000..996af01 --- /dev/null +++ b/src/SimulationJeu.java @@ -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 liste; + + public SimulationJeu() { + liste = new ArrayList(); + } + + 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()); + } +}