Tutu
This commit is contained in:
parent
ecd5504100
commit
6de383d5f0
@ -9,15 +9,15 @@ import java.util.HashMap;
|
||||
|
||||
public abstract class CaseAbstraite {
|
||||
|
||||
protected Personnage occupant;
|
||||
protected ObjetAbstrait objetOccupant;
|
||||
private Personnage occupant;
|
||||
private ObjetAbstrait objetOccupant;
|
||||
|
||||
|
||||
HashMap<PointsCardinaux, CaseAbstraite> voisins;
|
||||
private HashMap<PointsCardinaux, CaseAbstraite> voisins;
|
||||
|
||||
Coordonnees coord;
|
||||
private Coordonnees coord;
|
||||
|
||||
public CaseAbstraite(int vert, int hor) {
|
||||
CaseAbstraite(int vert, int hor) {
|
||||
coord = new Coordonnees(vert, hor);
|
||||
|
||||
voisins = new HashMap<PointsCardinaux, CaseAbstraite>();
|
||||
@ -52,18 +52,10 @@ public abstract class CaseAbstraite {
|
||||
}
|
||||
}
|
||||
|
||||
public void ajouterVoisin(PointsCardinaux p, CaseAbstraite c) {
|
||||
voisins.put(p, c);
|
||||
}
|
||||
|
||||
public void ajouterOccupant(Personnage occ) {
|
||||
this.occupant = occ;
|
||||
}
|
||||
|
||||
public void ajouterObjet(ObjetAbstrait objet) {
|
||||
this.objetOccupant = objet;
|
||||
}
|
||||
|
||||
public Personnage getOccupant() {
|
||||
return occupant;
|
||||
}
|
||||
@ -84,19 +76,7 @@ public abstract class CaseAbstraite {
|
||||
return voisins;
|
||||
}
|
||||
|
||||
public void setVoisins(HashMap<PointsCardinaux, CaseAbstraite> voisins) {
|
||||
this.voisins = voisins;
|
||||
}
|
||||
|
||||
public String affichageSpecial() {
|
||||
return " ";
|
||||
}
|
||||
|
||||
public Coordonnees getCoord() {
|
||||
return coord;
|
||||
}
|
||||
|
||||
public void setCoord(Coordonnees coord) {
|
||||
this.coord = coord;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package Cases;
|
||||
import java.awt.*;
|
||||
|
||||
public class CaseColore extends CaseAbstraite {
|
||||
Color couleur;
|
||||
private Color couleur;
|
||||
|
||||
public CaseColore(int vert, int hor) {
|
||||
super(vert, hor);
|
||||
|
@ -13,18 +13,10 @@ public class Coordonnees {
|
||||
return ligne;
|
||||
}
|
||||
|
||||
public void setLigne(int ligne) {
|
||||
this.ligne = ligne;
|
||||
}
|
||||
|
||||
public int getCol() {
|
||||
return col;
|
||||
}
|
||||
|
||||
public void setCol(int col) {
|
||||
this.col = col;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "col " + getCol() + " ligne " + getLigne();
|
||||
|
@ -2,7 +2,7 @@ package Cases.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomPointCardinal<E extends Enum> {
|
||||
class RandomPointCardinal<E extends Enum> {
|
||||
|
||||
private static final Random RND = new Random();
|
||||
private final E[] values;
|
||||
|
@ -9,7 +9,7 @@ import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class ComportementActionSeDeplacer implements ComportementAction {
|
||||
CaseAbstraite destination;
|
||||
private CaseAbstraite destination;
|
||||
|
||||
@Override
|
||||
public void executerAction(Personnage perso, Tuple<ArrayList<Personnage>, ArrayList<ObjetAbstrait>, ArrayList<CaseAbstraite>> t) {
|
||||
@ -27,7 +27,9 @@ public class ComportementActionSeDeplacer implements ComportementAction {
|
||||
} else {
|
||||
recupererObjets(objs, perso);
|
||||
}
|
||||
destination.setOccupant(perso);
|
||||
if (destination != null) {
|
||||
destination.setOccupant(perso);
|
||||
}
|
||||
perso.setCaseCourante(destination);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import java.util.ArrayList;
|
||||
|
||||
public class EquipeDeFoot extends GroupeAbstrait {
|
||||
|
||||
public String nom;
|
||||
private final String nom;
|
||||
|
||||
public EquipeDeFoot(ArrayList<Personnage> list) {
|
||||
super(list);
|
||||
|
@ -5,9 +5,9 @@ import Person.Personnage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GroupeAbstrait extends PersonnagesAbstraits {
|
||||
ArrayList<Personnage> list = new ArrayList<Personnage>();
|
||||
private ArrayList<Personnage> list = new ArrayList<Personnage>();
|
||||
|
||||
public GroupeAbstrait(ArrayList<Personnage> list) {
|
||||
GroupeAbstrait(ArrayList<Personnage> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,10 @@ import Person.Personnage;
|
||||
|
||||
public abstract class EtatPersonnageAbstrait {
|
||||
|
||||
protected Personnage joueur;
|
||||
final Personnage joueur;
|
||||
|
||||
protected EtatPersonnageAbstrait(Personnage perso){
|
||||
this.joueur = perso;
|
||||
EtatPersonnageAbstrait(Personnage perso) {
|
||||
this.joueur = perso;
|
||||
}
|
||||
|
||||
protected abstract void execute();
|
||||
|
@ -4,8 +4,6 @@ import Person.Personnage;
|
||||
|
||||
public class EtatPersonnageKO extends EtatPersonnageAbstrait {
|
||||
|
||||
private int nbTourKO;
|
||||
|
||||
public EtatPersonnageKO(Personnage perso) {
|
||||
super(perso);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import java.util.Random;
|
||||
abstract public class FabriquePersonnagesAbstraite {
|
||||
public abstract ArrayList<Personnage> CreerPersonages(CaseAbstraite[][] plateau);
|
||||
|
||||
protected void placement(ArrayList<Personnage> personnages, CaseAbstraite[][] plateau) {
|
||||
void placement(ArrayList<Personnage> personnages, CaseAbstraite[][] plateau) {
|
||||
Random rand = new Random();
|
||||
for (Personnage p : personnages) {
|
||||
int x = rand.nextInt(plateau.length);
|
||||
|
@ -10,8 +10,8 @@ import Person.PersonnageBattleSnow;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FabriquePersonnagesBattleSnow extends FabriquePersonnagesAbstraite {
|
||||
private final ComportementAction parDefaut = new ComportementActionTirerBouleDeNeige();
|
||||
public Arbitre a;
|
||||
protected ComportementAction parDefaut = new ComportementActionTirerBouleDeNeige();
|
||||
|
||||
@Override
|
||||
public ArrayList<Personnage> CreerPersonages(CaseAbstraite[][] plateau) {
|
||||
|
@ -9,7 +9,7 @@ import Person.PersonnageBattleZone;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FabriquePersonnagesBattleZone extends FabriquePersonnagesAbstraite {
|
||||
protected ComportementAction parDefaut = new ComportementActionChangerCouleurCase();
|
||||
private final ComportementAction parDefaut = new ComportementActionChangerCouleurCase();
|
||||
|
||||
@Override
|
||||
public ArrayList<Personnage> CreerPersonages(CaseAbstraite[][] plateau) {
|
||||
|
@ -12,8 +12,8 @@ import Person.PersonnageFootball;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FabriquePersonnagesFootball extends FabriquePersonnagesAbstraite {
|
||||
private final ComportementAction parDefaut = new ComportementActionTirerBalon();
|
||||
public Arbitre a;
|
||||
ComportementAction parDefaut = new ComportementActionTirerBalon();
|
||||
|
||||
@Override
|
||||
public ArrayList<Personnage> CreerPersonages(CaseAbstraite[][] plateau) {
|
||||
|
@ -10,11 +10,11 @@ import Person.Personnage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class FabriqueScenarioAbstraite {
|
||||
FabriquePlateauAbstraite fPlateau;
|
||||
FabriquePersonnagesAbstraite fPersonnages;
|
||||
FabriqueObjetAbstraite fObjs;
|
||||
private final FabriquePlateauAbstraite fPlateau;
|
||||
private final FabriquePersonnagesAbstraite fPersonnages;
|
||||
private final FabriqueObjetAbstraite fObjs;
|
||||
|
||||
public FabriqueScenarioAbstraite(FabriquePlateauAbstraite pl, FabriquePersonnagesAbstraite pr, FabriqueObjetAbstraite fObjs) {
|
||||
FabriqueScenarioAbstraite(FabriquePlateauAbstraite pl, FabriquePersonnagesAbstraite pr, FabriqueObjetAbstraite fObjs) {
|
||||
this.fPlateau = pl;
|
||||
this.fPersonnages = pr;
|
||||
this.fObjs = fObjs;
|
||||
|
@ -3,7 +3,7 @@ import Fabriques.Personnages.FabriquePersonnagesBattleZone;
|
||||
import Fabriques.Plateau.FabriquePlateauBattleZone;
|
||||
import Fabriques.Scenario.FabriqueScenarioBattleZone;
|
||||
|
||||
public class Main {
|
||||
class Main {
|
||||
public static void main(String[] args){
|
||||
SimulationJeu s = new SimulationJeu(new FabriqueScenarioBattleZone(new FabriquePlateauBattleZone(), new FabriquePersonnagesBattleZone(), new FabriqueObjetBattleZone()));
|
||||
s.lancerJeu();
|
||||
|
@ -3,11 +3,11 @@ package Objets;
|
||||
import Cases.CaseAbstraite;
|
||||
|
||||
public abstract class ObjetAbstrait {
|
||||
protected CaseAbstraite caseCourante;
|
||||
protected String nom;
|
||||
protected double pointsDeVie;
|
||||
protected double force;
|
||||
protected double vitesse;
|
||||
private CaseAbstraite caseCourante;
|
||||
private String nom;
|
||||
private double pointsDeVie;
|
||||
private double force;
|
||||
private double vitesse;
|
||||
|
||||
protected ObjetAbstrait(String name) {
|
||||
this.nom = name;
|
||||
@ -17,8 +17,8 @@ public abstract class ObjetAbstrait {
|
||||
this.caseCourante = null;
|
||||
}
|
||||
|
||||
protected ObjetAbstrait(String name, double lifePoint, double strength, double speed) {
|
||||
this.nom = name;
|
||||
ObjetAbstrait(String name, double lifePoint, double strength, double speed) {
|
||||
this.nom = name;
|
||||
this.pointsDeVie=lifePoint;
|
||||
this.force=strength;
|
||||
this.vitesse=speed;
|
||||
|
@ -2,7 +2,7 @@ package Observateur;
|
||||
|
||||
public class Arbitre extends SujetObserveAbstrait {
|
||||
|
||||
int iter = 10;
|
||||
private int iter = 10;
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
@ -4,9 +4,9 @@ import java.util.ArrayList;
|
||||
|
||||
public abstract class SujetObserveAbstrait {
|
||||
|
||||
ArrayList<ObservateurAbstrait> liste;
|
||||
final ArrayList<ObservateurAbstrait> liste;
|
||||
|
||||
protected SujetObserveAbstrait() {
|
||||
SujetObserveAbstrait() {
|
||||
liste = new ArrayList<ObservateurAbstrait>();
|
||||
}
|
||||
|
||||
|
@ -19,17 +19,17 @@ import java.util.HashSet;
|
||||
public class Personnage extends PersonnagesAbstraits implements ObservateurAbstrait {
|
||||
|
||||
|
||||
protected CaseAbstraite caseCourante;
|
||||
protected ObjetAbstrait objet;
|
||||
protected String nom;
|
||||
protected String groupe;
|
||||
protected double pointsDeVie;
|
||||
protected double force;
|
||||
protected double vitesse;
|
||||
protected double portee;
|
||||
protected EAction action;
|
||||
protected ComportementAction Action;
|
||||
HashSet<CaseAbstraite> voisinsActuels = new HashSet<CaseAbstraite>();
|
||||
private final String nom;
|
||||
private final double force;
|
||||
private final double vitesse;
|
||||
private final double portee;
|
||||
private CaseAbstraite caseCourante;
|
||||
private ObjetAbstrait objet;
|
||||
private String groupe;
|
||||
private double pointsDeVie;
|
||||
private EAction action;
|
||||
private ComportementAction Action;
|
||||
private HashSet<CaseAbstraite> voisinsActuels = new HashSet<CaseAbstraite>();
|
||||
private EtatPersonnageAbstrait etatCourant;
|
||||
private HashMap<PointsCardinaux, CaseAbstraite> voisins;
|
||||
|
||||
@ -46,7 +46,7 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
}
|
||||
|
||||
|
||||
protected Personnage(String name, double lifePoint, double strength, double speed, int portee, ComportementAction a) {
|
||||
Personnage(String name, double lifePoint, double strength, double speed, int portee, ComportementAction a) {
|
||||
this.nom = name;
|
||||
this.pointsDeVie=lifePoint;
|
||||
this.force=strength;
|
||||
@ -90,7 +90,7 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
Action.executerAction(this, t);
|
||||
}
|
||||
|
||||
public HashSet<CaseAbstraite> voisinsPortee(CaseAbstraite c, int rayon) {
|
||||
HashSet<CaseAbstraite> voisinsPortee(CaseAbstraite c, int rayon) {
|
||||
HashMap<PointsCardinaux, CaseAbstraite> v = c.getVoisins();
|
||||
if ((rayon + 1) == this.getPortee()) {
|
||||
voisinsActuels.addAll(c.getVoisins().values());
|
||||
@ -103,7 +103,7 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
return voisinsActuels;
|
||||
}
|
||||
|
||||
public ArrayList<ObjetAbstrait> rechercheObjetProche(HashSet<CaseAbstraite> voisinsDesVoisins) {
|
||||
ArrayList<ObjetAbstrait> rechercheObjetProche(HashSet<CaseAbstraite> voisinsDesVoisins) {
|
||||
ArrayList<ObjetAbstrait> objetsVoisins = new ArrayList<ObjetAbstrait>();
|
||||
|
||||
for (CaseAbstraite c : voisinsDesVoisins) {
|
||||
@ -114,14 +114,14 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
return objetsVoisins;
|
||||
}
|
||||
|
||||
protected HashSet<CaseAbstraite> getCaseAbstraitesForPortee() {
|
||||
HashSet<CaseAbstraite> getCaseAbstraitesForPortee() {
|
||||
HashSet<CaseAbstraite> voisins = voisinsPortee(this.caseCourante, 0);
|
||||
voisins.remove(getCaseCourante());
|
||||
return voisins;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Personnage> rechercheJoueur(HashSet<CaseAbstraite> voisinsDesVoisins) {
|
||||
ArrayList<Personnage> rechercheJoueur(HashSet<CaseAbstraite> voisinsDesVoisins) {
|
||||
ArrayList<Personnage> personnes = new ArrayList<Personnage>();
|
||||
for (CaseAbstraite c : voisinsDesVoisins) {
|
||||
if (c.getOccupant() != null) {
|
||||
@ -132,12 +132,7 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
return personnes;
|
||||
}
|
||||
|
||||
public void mediationConflits() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ChangerAction(EAction nouvelAction) {
|
||||
void ChangerAction(EAction nouvelAction) {
|
||||
|
||||
switch (nouvelAction) {
|
||||
case ChangerCouleurCase:
|
||||
@ -153,7 +148,7 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
Action = new ComportementActionTirerBouleDeNeige();
|
||||
break;
|
||||
case Rien:
|
||||
Action = new ComportementActionTirerBouleDeNeige();
|
||||
Action = new Rien();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -163,7 +158,7 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
this.setAction(nouvelAction);
|
||||
}
|
||||
|
||||
public ObjetAbstrait getObjet() {
|
||||
ObjetAbstrait getObjet() {
|
||||
return objet;
|
||||
}
|
||||
|
||||
@ -179,7 +174,11 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
return bonus + pointsDeVie;
|
||||
}
|
||||
|
||||
public double getForce() {
|
||||
void setPointsDeVie(double pointsDeVie) {
|
||||
this.pointsDeVie = pointsDeVie;
|
||||
}
|
||||
|
||||
double getForce() {
|
||||
double bonus = 0;
|
||||
if (getObjet() != null) {
|
||||
bonus = getObjet().getForce();
|
||||
@ -199,7 +198,6 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
return groupe;
|
||||
}
|
||||
|
||||
|
||||
public void setGroupe(String equipe) {
|
||||
groupe = equipe;
|
||||
}
|
||||
@ -218,7 +216,7 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
|
||||
}
|
||||
|
||||
public double getPortee() {
|
||||
double getPortee() {
|
||||
return portee;
|
||||
}
|
||||
|
||||
@ -226,7 +224,7 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(EAction action) {
|
||||
void setAction(EAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@ -242,4 +240,27 @@ public class Personnage extends PersonnagesAbstraits implements ObservateurAbstr
|
||||
public void update() {
|
||||
this.ChangerAction(EAction.Rien);
|
||||
}
|
||||
|
||||
public void afficherInfos() {
|
||||
System.out.println(this.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Personnage{" +
|
||||
"caseCourante=" + caseCourante +
|
||||
", objet=" + objet +
|
||||
", nom='" + nom + '\'' +
|
||||
", groupe='" + groupe + '\'' +
|
||||
", pointsDeVie=" + pointsDeVie +
|
||||
", force=" + force +
|
||||
", vitesse=" + vitesse +
|
||||
", portee=" + portee +
|
||||
", action=" + action +
|
||||
", Action=" + Action +
|
||||
", voisinsActuels=" + voisinsActuels +
|
||||
", etatCourant=" + etatCourant +
|
||||
", voisins=" + voisins +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,11 @@ public class PersonnageBattleSnow extends Personnage{
|
||||
}
|
||||
|
||||
public void attack(PersonnageBattleSnow cible) {
|
||||
double force = this.getForce();
|
||||
cible.recevoirAttack(force);
|
||||
}
|
||||
|
||||
|
||||
private void recevoirAttack(double force) {
|
||||
this.setPointsDeVie(this.getPointsDeVie() - force);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class PersonnageBattleZone extends Personnage {
|
||||
Color couleur;
|
||||
private Color couleur;
|
||||
|
||||
public PersonnageBattleZone(String name, double lifePoint, double strength, double speed, int portee, ComportementAction parDefaut) {
|
||||
super(name, lifePoint, strength, speed, portee, parDefaut);
|
||||
|
@ -7,10 +7,11 @@ import Composition.GroupeAbstrait;
|
||||
import Objets.ObjetBallon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class PersonnageFootball extends Personnage {
|
||||
|
||||
public EquipeDeFoot equipe;
|
||||
private EquipeDeFoot equipe;
|
||||
|
||||
public PersonnageFootball(String name, double lifePoint, double strength, double speed, int portee, ComportementAction parDefaut) {
|
||||
super(name, lifePoint, strength, speed, portee, parDefaut);
|
||||
@ -27,6 +28,11 @@ public class PersonnageFootball extends Personnage {
|
||||
}
|
||||
|
||||
public void lancerBallon(ObjetBallon objetOccupant, ArrayList<CaseAbstraite> cases) {
|
||||
int size = cases.size();
|
||||
int item = new Random().nextInt(size);
|
||||
CaseAbstraite dest = cases.get(item);
|
||||
|
||||
objetOccupant.setCaseCourante(dest);
|
||||
dest.setObjetOccupant(objetOccupant);
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,12 @@ import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class SimulationJeu {
|
||||
ArrayList<Personnage> personnages;
|
||||
CaseAbstraite[][] plateau;
|
||||
FabriqueScenarioAbstraite f;
|
||||
InterfaceConsole intefaceC;
|
||||
Arbitre a;
|
||||
class SimulationJeu {
|
||||
private final CaseAbstraite[][] plateau;
|
||||
private final FabriqueScenarioAbstraite f;
|
||||
private final InterfaceConsole intefaceC;
|
||||
private final Arbitre a;
|
||||
private ArrayList<Personnage> personnages;
|
||||
|
||||
public SimulationJeu(FabriqueScenarioAbstraite fb) {
|
||||
f = fb;
|
||||
@ -29,14 +29,14 @@ public class SimulationJeu {
|
||||
a = new Arbitre();
|
||||
}
|
||||
|
||||
public void afficheTous() {
|
||||
void afficheTous() {
|
||||
System.out.println("");
|
||||
intefaceC.afficherPlateau();
|
||||
}
|
||||
|
||||
public void recupererInformations() {
|
||||
void recupererInformations() {
|
||||
for (Personnage p : personnages) {
|
||||
|
||||
p.afficherInfos();
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ public class SimulationJeu {
|
||||
// bloquer le tour jusqu'a toucher une touche du clavier.
|
||||
Scanner s = new Scanner(System.in);
|
||||
String choix = s.nextLine();
|
||||
if (choix == "s") {
|
||||
if (choix.equals("s")) {
|
||||
continuer = false;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package utils;
|
||||
|
||||
public class Constants {
|
||||
|
||||
/** Define the duration for a football game (in ms) */
|
||||
public static final int TIME_FOOTBALL_GAME = 100000; // 100 secondes
|
||||
|
||||
public static final int TABLE_HEIGHT = 10;
|
||||
|
||||
public static final int TABLE_WIDTH = 10;
|
||||
|
@ -3,7 +3,7 @@ package utils;
|
||||
import Cases.CaseAbstraite;
|
||||
|
||||
public class InterfaceConsole {
|
||||
CaseAbstraite[][] plateau;
|
||||
private final CaseAbstraite[][] plateau;
|
||||
|
||||
public InterfaceConsole(CaseAbstraite[][] cases) {
|
||||
plateau = cases;
|
||||
|
Loading…
Reference in New Issue
Block a user