Commit 8d814d22 authored by Killian's avatar Killian 💬
Browse files

Adding weakness / resistance system for more realism.

parent 8d95932f
......@@ -19,7 +19,22 @@ export function display(p : Pokemon) : string{
*/
export function attack(p1 : Pokemon, p2 : Pokemon) : Pokemon {
console.log(display(p1)+ " attaque " + display(p2));
//TODO Compléter cette fonction
let damage : number = 5*(p1.force/p2.armor)+2;
//Faiblesses et résistances
if ((p1.type == 'grass' && p2.type == 'fire') || (p1.type == 'fire' && p2.type=='water') || (p1.type =='water' && p2.type == 'grass')){
damage = damage/2;
console.log('Ce n\'est pas très efficace...');
}
else if((p1.type == 'grass' && p2.type == 'water') || (p1.type == 'fire' && p2.type=='grass') || (p1.type =='water' && p2.type == 'fire')){
damage = damage * 2;
console.log('C\'est super efficace!');
}
if(p2.health >= damage){ //Définir si il restera des PV au pokémon ou si ils passent à 0.
p2.health -= damage;
}
else{
p2.health = 0;
}
return p2;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment