Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add game logs #26

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.