PlateauTest2 déplacement des pions

This commit is contained in:
Paul Gross
2020-05-04 11:14:52 +02:00
parent afaef5411b
commit 80a0c89d49
7 changed files with 119 additions and 21 deletions

View File

@@ -63,8 +63,14 @@ public class GestionnaireJeu {
return joueurs.get(0);
}
public void deplacer(Joueur currentJoueur) {
Platform.runLater(() -> {
pc.deplacer(currentJoueur);
});
}
public boolean choisir(Joueur joueur) {
Platform.runLater(() -> {
try {
@@ -90,14 +96,10 @@ public class GestionnaireJeu {
try {
return query.get().booleanValue();
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Platform.runLater(() -> {
});
return false;
}
@@ -155,5 +157,12 @@ public class GestionnaireJeu {
}
public void updateVieJoueur(Joueur joueur, int damage) {
pc.updateVieJoueur(joueur, damage);
}
}

View File

@@ -65,11 +65,31 @@ public class Joueur {
}
public void setStat(String key, int valeur) {
// TODO Il faut créer des observers de mort
this.stats.put(key, valeur);
updateVictoirePlateau();
updateVie();
}
private void updateVie() {
int damage = damageTaken();
this.plateau.updateVieJoueur(this, damage);
}
public int damageTaken() {
return this.cartePersonnage.getPv() - this.getStat(PLAYER_HP);
}
private void updateVictoirePlateau() {
int result = victoire() ? 0 : 1;
this.plateau.setStat(Plateau.PARTIE_FINIE, result);
}
public boolean victoire() {
return this.cartePersonnage.victoire();
}
public int getStat(String key) {
if(stats.containsKey(key)) {
@@ -80,7 +100,6 @@ public class Joueur {
}
}
public List<Joueur> getJoueursAdjacents() {
List<Joueur> joueurs = this.carteLieu.getJoueursAdjacents();
@@ -98,7 +117,6 @@ public class Joueur {
this.gestionnaireEquipements.ajouter(equipement); }
public Equipement choisir(List<Equipement> equipements) {
// TODO Auto-generated method stub
return null;
}

View File

@@ -124,7 +124,6 @@ public class Plateau extends Thread{
public void initCartePersonnage(List<CartePersonnage> cps) throws Exception {
int nbJoueurs = this.joueurs.size();
List<CartePersonnage> lcp = new ArrayList<>(nbJoueurs);
@@ -202,6 +201,7 @@ public class Plateau extends Thread{
System.out.println("Au tour de "+currentJoueur.getNom());
System.out.println("Lancement des dés.");
deplacer(currentJoueur);
if(isPartieTerminee()) break;
System.out.println("Vous êtes désormais sur le lieu "+currentJoueur.getCarteLieu().getNom());
System.out.println("Voulez vous activer l'effet du lieu ?");
if(currentJoueur.choisir()) {
@@ -209,6 +209,7 @@ public class Plateau extends Thread{
System.out.println("Vous avez "+currentJoueur.getStat(Joueur.PLAYER_HP)+" pv");
currentJoueur.utiliserEffetLieu();
System.out.println("Vous passez a "+currentJoueur.getStat(Joueur.PLAYER_HP)+" pv");
if(isPartieTerminee()) break;
}
try {
Thread.sleep(2000);
@@ -223,6 +224,7 @@ public class Plateau extends Thread{
if(currentJoueur.hasOpponents()) {
Joueur cible = currentJoueur.choisirAdjacents();
attaquer(currentJoueur,cible);
if(isPartieTerminee()) break;
}else {
System.out.println("Il n'y a personne a attaquer.");
}
@@ -237,8 +239,24 @@ public class Plateau extends Thread{
i++;
}
List<Joueur> gagnants = new ArrayList<Joueur>();
for(Joueur j : joueurs) {
if(j.victoire()) {
gagnants.add(j);
}
}
// TODO Liste des gagnants
// TODO Evaluate every winners
}
public boolean isPartieTerminee() {
return this.getStat(PARTIE_FINIE) == 1;
}
public void deplacer(Joueur currentJoueur) {
boolean attributed = false;
@@ -255,6 +273,8 @@ public class Plateau extends Thread{
}
}
}
gj.deplacer(currentJoueur);
}
public void attaquer(Joueur joueur1, Joueur joueur2) {
@@ -279,7 +299,6 @@ public class Plateau extends Thread{
int roll4 =rollRandom(4);
int roll6 = rollRandom(6);
gj.rollDice(j, PlateauController.DICE_BOTH, roll4,roll6);
return Math.abs(roll4-roll6);
}
@@ -325,8 +344,7 @@ public class Plateau extends Thread{
}else {
return -1;
}
}
}
public void shuffleLieux(){
@@ -352,6 +370,11 @@ public class Plateau extends Thread{
this.lieux = lieux;
shuffleLieux();
}
public List<CarteLieu> getLieux() {
return this.lieux;
}
public boolean choisir(Joueur joueur) {
return gj.choisir(joueur);
@@ -377,4 +400,10 @@ public class Plateau extends Thread{
List<Joueur> joueurs = this.getJoueurs();
return gj.choisirParmisTous(joueur,joueurs);
}
public void updateVieJoueur(Joueur joueur, int damage) {
gj.updateVieJoueur(joueur,damage);
}
}