Skip to content

Commit

Permalink
MNG-113 Add game logs (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandraCyp authored Feb 12, 2021
1 parent 1ef7da3 commit 243c24b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 26 deletions.
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

17 changes: 1 addition & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,7 @@ <h2>HP:</h2>
</div>
</div>
<div class="gameActions">
<div class="gameLogs">
<p>Pikachu used Thunder Shock!</p>
<p>Bulbasaur used Mango</p>
<p>Pikachu used Thunder Shock!</p>
<p>Bulbasaur used Mango</p>
<p>Pikachu used Thunder Shock!</p>
<p>Bulbasaur used Mango</p>
<p>Pikachu used Thunder Shock!</p>
<p>Bulbasaur used Mango</p>
<p>Pikachu used Thunder Shock!</p>
<p>Bulbasaur used Mango</p>
<p>Pikachu used Thunder Shock!</p>
<p>Bulbasaur used Mango</p>
<p>Pikachu used Thunder Shock!</p>
<p>Bulbasaur used Mango</p>
</div>
<div class="gameLogs"></div>
<div class="buttonsContainer" id="actionModals">
<!-- <div class="button battleButton">attack</div>
<div class="button battleButton">switch</div>
Expand Down
8 changes: 5 additions & 3 deletions src/fightPage/buttonsEventListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createActivePokemon } from "./createActivePokemon";
import { createActivePlayer } from "./createActivePlayer";
import { createHPBars } from "./createHPBars";
import { createFightPagePokeballs } from "./createFightPagePokeballs";
import { updateMovesList } from "./updateMovesList";

export const actionsButtonEventListener = (
//player: Player,
Expand Down Expand Up @@ -91,6 +92,7 @@ const magicFunction = (
console.log(`${button.innerText} used!`);
if (functionToCall) {
functionToCall(gameHandler, e);
updateMovesList(gameHandler, functionToCall, e);
createActivePokemon(gameHandler);
createHPBars(gameHandler.playerOne, gameHandler.playerTwo);
createFightPagePokeballs(gameHandler);
Expand Down Expand Up @@ -122,17 +124,17 @@ const animationButtonsExit = (buttons: HTMLCollectionOf<HTMLElement>) => {
}
};

const attack = (gameHandler: GameHandler) => {
export const attack = (gameHandler: GameHandler) => {
console.log("bum bum bach!");
};

const switchPoke = (gameHandler: GameHandler, event: Event) => {
export const switchPoke = (gameHandler: GameHandler, event: Event) => {
const nameOfChosenPokemon = (event.currentTarget as HTMLDivElement)
.textContent;
gameHandler.switchPokemon(nameOfChosenPokemon!);
};

const eatMango = (gameHandler: GameHandler) => {
export const eatMango = (gameHandler: GameHandler) => {
const mangoButton = document.querySelector("#mangoButton")! as HTMLDivElement;
const mango = document.querySelector("#mango")! as HTMLDivElement;
gameHandler.currentPlayer.useMango();
Expand Down
32 changes: 32 additions & 0 deletions src/fightPage/updateMovesList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { GameHandler } from "../gameHandlerClass";
import { attack, switchPoke, eatMango } from "./buttonsEventListeners";

export const updateMovesList = (
gameHandler: GameHandler,
calledFunction: any,
event: Event
) => {
const moveList = document.querySelector(".gameLogs")!;
const newMove = document.createElement("p");
let newMoveText = document.createTextNode("No move found");
const pokemonName = gameHandler.currentPlayer.getActivePokemon.name;
const buttonContent = (event.currentTarget as HTMLDivElement).textContent;
const playerName = gameHandler.currentPlayer.name;
console.log();
switch (calledFunction) {
case attack:
newMoveText.nodeValue = `${playerName}: ${pokemonName} used ${buttonContent}!`;
break;
case switchPoke:
newMoveText.nodeValue = `${playerName} changed Pokemon: ${pokemonName} comes into play!`;
break;
case eatMango:
newMoveText.nodeValue = `${playerName} used mango: ${pokemonName} is healed!`;
break;
default:
console.log("No move found");
}
console.log(newMove);
newMove.append(newMoveText);
moveList.insertBefore(newMove, moveList.firstChild);
};
3 changes: 1 addition & 2 deletions styles/SASS/_responsive.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@
justify-content: space-evenly;

.gameLogs {
height: auto;
max-height: 30vh;
height: 30vh;
width: 45%;
order: 2;
}
Expand Down
3 changes: 1 addition & 2 deletions styles/app.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion styles/app.css.map

Large diffs are not rendered by default.

0 comments on commit 243c24b

Please sign in to comment.