From a4307920850c084c493c8ae4364560b00615c9b4 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Wed, 7 Jan 2015 09:34:10 +0100 Subject: [PATCH] Comportement pour les personnages BattleZone. --- src/Cases/CaseAbstraite.java | 4 +++ src/Cases/CaseColore.java | 20 +++++++++++++ .../ComportementActionChangerCouleurCase.java | 15 ++++++++++ src/Person/PersonnageBattleZone.java | 29 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 src/Cases/CaseColore.java create mode 100644 src/Comportements/ComportementActionChangerCouleurCase.java create mode 100644 src/Person/PersonnageBattleZone.java diff --git a/src/Cases/CaseAbstraite.java b/src/Cases/CaseAbstraite.java index 9a56c1a..780a8d1 100644 --- a/src/Cases/CaseAbstraite.java +++ b/src/Cases/CaseAbstraite.java @@ -27,4 +27,8 @@ public abstract class CaseAbstraite { public void ajouterOccupant(Personnage occ) { this.occupant = occ; } + + public Personnage getOccupant() { + return occupant; + } } \ No newline at end of file diff --git a/src/Cases/CaseColore.java b/src/Cases/CaseColore.java new file mode 100644 index 0000000..7fc05b8 --- /dev/null +++ b/src/Cases/CaseColore.java @@ -0,0 +1,20 @@ +package Cases; + +import java.awt.*; + +public class CaseColore extends CaseAbstraite { + Color couleur; + + public CaseColore(int vert, int hor) { + super(vert, hor); + this.couleur = Color.WHITE; + } + + public Color getCouleur() { + return couleur; + } + + public void setCouleur(Color couleur) { + this.couleur = couleur; + } +} diff --git a/src/Comportements/ComportementActionChangerCouleurCase.java b/src/Comportements/ComportementActionChangerCouleurCase.java new file mode 100644 index 0000000..e557853 --- /dev/null +++ b/src/Comportements/ComportementActionChangerCouleurCase.java @@ -0,0 +1,15 @@ +package Comportements; + +import Cases.CaseAbstraite; +import Cases.CaseColore; +import Person.PersonnageBattleZone; + +public class ComportementActionChangerCouleurCase implements ComportementAction { + + @Override + public void executerAction(CaseAbstraite c) { + CaseColore caseColore = (CaseColore) c; + PersonnageBattleZone personnage = (PersonnageBattleZone) c.getOccupant(); + caseColore.setCouleur(personnage.getCouleur()); + } +} diff --git a/src/Person/PersonnageBattleZone.java b/src/Person/PersonnageBattleZone.java new file mode 100644 index 0000000..11773b6 --- /dev/null +++ b/src/Person/PersonnageBattleZone.java @@ -0,0 +1,29 @@ +package Person; + +import Observateur.Organisation; + +import java.awt.*; +import java.util.Random; + +public class PersonnageBattleZone extends Personnage { + Color couleur; + + protected PersonnageBattleZone(Organisation etatMajor, String nom) { + super(etatMajor, nom); + + // Couleur Aléatoire + Random rand = new Random(); + int r = rand.nextInt(255); + int g = rand.nextInt(255); + int b = rand.nextInt(255); + this.couleur = new Color(r, g, b); + } + + public Color getCouleur() { + return couleur; + } + + public void setCouleur(Color couleur) { + this.couleur = couleur; + } +}