Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Killian
Pokemon battle simulator
Commits
8d814d22
Commit
8d814d22
authored
Feb 17, 2020
by
Killian
💬
Browse files
Adding weakness / resistance system for more realism.
parent
8d95932f
Changes
1
Hide whitespace changes
Inline
Side-by-side
pokemon.ts
View file @
8d814d22
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment