Création de la méthode attaquer de plateau et de joueur
This commit is contained in:
@ -59,6 +59,8 @@ public class Joueur {
|
||||
}
|
||||
|
||||
public void setStat(String key, int valeur) {
|
||||
|
||||
// TODO Il faut créer des observers de mort
|
||||
this.stats.put(key, valeur);
|
||||
}
|
||||
|
||||
@ -101,10 +103,34 @@ public class Joueur {
|
||||
|
||||
}
|
||||
|
||||
public void attaquer(Joueur j2) {
|
||||
// TODO Auto-generated method stub
|
||||
public void attaquer(Joueur j2, int attaqueDice) {
|
||||
|
||||
int blessure = evaluerImmunite(j2)*(this.evaluerAttaque(j2) + attaqueDice);
|
||||
|
||||
if(blessure > 0)
|
||||
{
|
||||
j2.addStat(PLAYER_HP, -blessure);
|
||||
}
|
||||
}
|
||||
|
||||
private int evaluerAttaque(Joueur j2) {
|
||||
|
||||
return this.getStat(PLAYER_DAMAGE)-j2.getStat(PLAYER_RESISTANCE);
|
||||
}
|
||||
|
||||
private int evaluerImmunite(Joueur j2) {
|
||||
|
||||
int nbToursImmune = j2.getStat(PLAYER_IMMUNITY);
|
||||
|
||||
return nbToursImmune > 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
private void addStat(String key, int valeur)
|
||||
{
|
||||
int valeurBase = this.getStat(key);
|
||||
this.setStat(Joueur.PLAYER_HP,valeurBase+valeur);
|
||||
}
|
||||
|
||||
|
||||
public Plateau getPlateau() {
|
||||
return this.plateau;
|
||||
|
@ -64,6 +64,13 @@ public class Plateau {
|
||||
|
||||
public void attaquer(Joueur joueur1, Joueur joueur2) {
|
||||
|
||||
int attaque = diffRolls();
|
||||
|
||||
if(attaque != 0) {
|
||||
|
||||
joueur1.attaquer(joueur2,attaque);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -71,15 +78,16 @@ public class Plateau {
|
||||
return new Joueur("0");
|
||||
}
|
||||
|
||||
public int sumRolls() {
|
||||
//pas necessaire?
|
||||
return 0;
|
||||
public int diffRolls() {
|
||||
return Math.abs(roll6()-roll4());
|
||||
}
|
||||
|
||||
public int roll4() {
|
||||
return (int) Math.floor(Math.random() * 3)+1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int rollDices4() {
|
||||
return Math.abs(roll4() - roll4());
|
||||
}
|
||||
@ -91,7 +99,7 @@ public class Plateau {
|
||||
public int roll6() {
|
||||
return (int) Math.floor(Math.random() * 5)+1;
|
||||
}
|
||||
|
||||
|
||||
public List<Joueur> getJoueurs() {
|
||||
return this.joueurs;
|
||||
}
|
||||
|
Reference in New Issue
Block a user