-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
class Personnage { | ||
constructor(pseudo, classe, sante, attaque) { | ||
this.pseudo = pseudo; | ||
this.classe = classe; | ||
this.sante = sante; | ||
this.attaque = attaque; | ||
this.niveau = 1; | ||
} | ||
|
||
evoluer() { | ||
this.niveau++; | ||
console.log(this.pseudo + " passe au niveau " + this.niveau); | ||
} | ||
|
||
verifierSante() { | ||
if (this.sante <= 0) { | ||
this.sante = 0; | ||
console.log(this.pseudo + " a perdu !"); | ||
} | ||
} | ||
|
||
get informations() { | ||
return this.pseudo + " (" + this.classe + ") a " + this.sante + " points de vie est au niveau " + this.niveau; | ||
} | ||
} | ||
|
||
class Magicien extends Personnage { | ||
constructor(pseudo) { | ||
super(pseudo, "magicien", 170, 90); | ||
} | ||
|
||
attaquer(personnage) { | ||
personnage.sante -= this.attaque; | ||
console.log(this.pseudo + " attaque " + personnage.pseudo + " en lançant un sort (" + this.attaque + " dégâts)"); | ||
this.evoluer(); | ||
personnage.verifierSante(); | ||
} | ||
|
||
coupSpecial(personnage) { | ||
personnage.sante -= this.attaque * 5; | ||
console.log(this.pseudo + " attaque avec son coup spécial puissance des arcanes " + personnage.pseudo + " (" + this.attaque*5 + " dégâts)"); | ||
this.evoluer(); | ||
personnage.verifierSante(); | ||
} | ||
} | ||
|
||
class Guerrier extends Personnage { | ||
constructor(pseudo) { | ||
super(pseudo, "guerrier", 350, 50); | ||
} | ||
|
||
attaquer(personnage) { | ||
personnage.sante -= this.attaque; | ||
console.log(this.pseudo + " attaque " + personnage.pseudo + " son épée (" + this.attaque + " dégâts)"); | ||
this.evoluer(); | ||
personnage.verifierSante(); | ||
} | ||
|
||
coupSpecial(personnage) { | ||
personnage.sante -= this.attaque * 5; | ||
console.log(this.pseudo + " attaque son coup spécial haches de guerre " + personnage.pseudo + " (" + this.attaque*5 + " dégâts)"); | ||
this.evoluer(); | ||
personnage.verifierSante(); | ||
} | ||
} | ||
|
||
var gandalf = new Magicien('Gandalf'); | ||
var thor = new Guerrier('Thor'); | ||
console.log(thor.informations); | ||
console.log(gandalf.informations); | ||
gandalf.attaquer(thor); | ||
console.log(thor.informations); | ||
thor.attaquer(gandalf); | ||
console.log(gandalf.informations); | ||
gandalf.coupSpecial(thor); |