Skip to content

Commit

Permalink
Merge pull request #32 from lukaszdutka/MNG-96-Poke-attack
Browse files Browse the repository at this point in the history
MNG-96 pokemon attack
  • Loading branch information
AleksandraCyp authored Feb 13, 2021
2 parents 6a13a2a + 9c76b97 commit 471ef34
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
30 changes: 15 additions & 15 deletions assets/poke_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"name": "bulbasaur",
"types": ["grass", "poison"],
"stats": {
"hp": 45,
"hp": 5,
"attack": 49,
"defense": 49
"defense": 30
},
"moves": [{
"name": "razor-wind",
Expand All @@ -32,9 +32,9 @@
"name": "charmander",
"types": ["fire"],
"stats": {
"hp": 39,
"hp": 9,
"attack": 52,
"defense": 43
"defense": 29
},
"moves": [{
"name": "mega-punch",
Expand All @@ -61,9 +61,9 @@
"name": "squirtle",
"types": ["water"],
"stats": {
"hp": 44,
"hp": 4,
"attack": 48,
"defense": 65
"defense": 31
},
"moves": [{
"name": "mega-kick",
Expand Down Expand Up @@ -121,7 +121,7 @@
"stats": {
"hp": 40,
"attack": 45,
"defense": 40
"defense": 28
},
"moves": [{
"name": "razor-wind",
Expand Down Expand Up @@ -150,7 +150,7 @@
"stats": {
"hp": 30,
"attack": 56,
"defense": 35
"defense": 30
},
"moves": [{
"name": "body-slam",
Expand Down Expand Up @@ -179,7 +179,7 @@
"stats": {
"hp": 35,
"attack": 55,
"defense": 40
"defense": 25
},
"moves": [{
"name": "slam",
Expand Down Expand Up @@ -208,7 +208,7 @@
"stats": {
"hp": 50,
"attack": 75,
"defense": 85
"defense": 36
},
"moves": [{
"name": "headbutt",
Expand Down Expand Up @@ -237,7 +237,7 @@
"stats": {
"hp": 70,
"attack": 45,
"defense": 48
"defense": 33
},
"moves": [{
"name": "fire-punch",
Expand All @@ -264,9 +264,9 @@
"name": "abra",
"types": ["psychic"],
"stats": {
"hp": 25,
"hp": 45,
"attack": 20,
"defense": 15
"defense": 25
},
"moves": [{
"name": "mega-punch",
Expand Down Expand Up @@ -295,7 +295,7 @@
"stats": {
"hp": 70,
"attack": 80,
"defense": 50
"defense": 36
},
"moves": [{
"name": "karate-chop",
Expand Down Expand Up @@ -324,7 +324,7 @@
"stats": {
"hp": 40,
"attack": 80,
"defense": 100
"defense": 40
},
"moves": [{
"name": "headbutt",
Expand Down
24 changes: 22 additions & 2 deletions src/fightPage/buttonsEventListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { createActivePlayer } from "./createActivePlayer";
import { createHPBars } from "./createHPBars";
import { createFightPagePokeballs } from "./createFightPagePokeballs";
import { updateMovesList } from "./updateMovesList";
import { Fight } from "../fightClass"
import { PokemonMove } from "../pokemonClass";
import { showResultModal } from "./resultModalPopUpFunctions";
import {
animationHittedPokemon,
Expand Down Expand Up @@ -64,7 +66,10 @@ export const attacksButtonEventListener = (gameHandler: GameHandler) => {
magicFunction(backButton, battleButtons, gameHandler);
};

export const switchButtonEventListener = (gameHandler: GameHandler) => {

export const switchButtonEventListener = (
gameHandler: GameHandler
) => {
const switchButtonOne = document.querySelector(
"#switchButtonOne"
)! as HTMLDivElement;
Expand Down Expand Up @@ -132,8 +137,23 @@ const checkIfGameIsOver = (gameHandler: GameHandler) => {
}
};

export const attack = (gameHandler: GameHandler) => {
export const attack = (gameHandler: GameHandler, e: Event) => {
animationHittedPokemon(gameHandler);

const fight = new Fight()
const pokemon = gameHandler.currentPlayer.getActivePokemon;
if (e !== null) {
const target: HTMLDivElement = e.target as HTMLDivElement

const move: PokemonMove = pokemon.moves.find(move => move.moveName === target.textContent) as PokemonMove
const attackingPoke = gameHandler.currentPlayer.getActivePokemon;
const defendingPoke = gameHandler.opponentPlayer.getActivePokemon;

console.log("Before attack ", `${defendingPoke.name} has ${defendingPoke.currentHP}`);
const damage: number = fight.fight(attackingPoke, defendingPoke, move as PokemonMove)
console.log(`${attackingPoke.name} did ${damage} with ${move.moveName} to ${defendingPoke.name}`);
console.log("After attack ", `${defendingPoke.name} has ${defendingPoke.currentHP}`);
}
};

export const switchPoke = (gameHandler: GameHandler, event: Event) => {
Expand Down

0 comments on commit 471ef34

Please sign in to comment.