From 76f5d214d6bd16f07ec0c932bf31d5688924bc2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=A9o=20Ackermann?= Date: Thu, 3 Mar 2022 14:54:34 +0100 Subject: [PATCH 1/2] Attack bug merged --- pokemon.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pokemon.ts b/pokemon.ts index 699ffb9..a9f0cef 100644 --- a/pokemon.ts +++ b/pokemon.ts @@ -20,6 +20,7 @@ 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 damages : number = (p1.force / p2.armor)*5 +2 + p2.health -= damages > p2.health ? p2.health : damages return p2; } \ No newline at end of file -- GitLab From d3073ea7fd850057c7e79789e998323bc3f75594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=A9o=20Ackermann?= Date: Thu, 3 Mar 2022 15:18:32 +0100 Subject: [PATCH 2/2] Improve battle system --- pokemon.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pokemon.ts b/pokemon.ts index a9f0cef..b66d428 100644 --- a/pokemon.ts +++ b/pokemon.ts @@ -11,16 +11,28 @@ export interface Pokemon { * Affiche le nom d'un pokémon avec ses points de vie */ export function display(p : Pokemon) : string{ - return p.name + ' ('+p.health+')'; + return p.name + ' ('+p.health+')' + ' -> ' + p.type; } /* Joue une attaque du pokemon p1 vers le pokemon p2 * retourne le pokemon p2 mis à jour après l'attaque */ export function attack(p1 : Pokemon, p2 : Pokemon) : Pokemon { - console.log(display(p1)+ " attaque " + display(p2)); - //TODO Compléter cette fonction - let damages : number = (p1.force / p2.armor)*5 +2 + let coefModifier : number + + if (p2.type == 'fire') { + coefModifier = p1.type == "water" ? 2 : 0.5 + } + else if (p2.type == 'water') { + coefModifier = p1.type == "grass" ? 2 : 0.5 + } + else { // (p2.type == 'grass') + coefModifier = p1.type == "fire" ? 2 : 0.5 + } + + let damages : number = ((p1.force / p2.armor)*5 +2) * coefModifier p2.health -= damages > p2.health ? p2.health : damages + + console.log(display(p1)+ " attaque " + display(p2)); return p2; } \ No newline at end of file -- GitLab