startit/oppgaver/uke7/pokemon/script.js

111 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-09-19 12:20:48 +02:00
let pikachuName = "Pikachu"
let pikachu = {
name: "Pikachu",
health: 45,
image: "Images/pikachu.png",
level: 8,
};
let bulbasaur = {
name: "Bulbasaur",
health: 70,
image: "Images/bulbasaur.png",
level: 12,
};
let oranguru = {
name: "Oranguru",
health: 170,
image: "Images/oranguru.png",
level: 45,
};
let drowzee = {
name: "Drowzee",
health: 90,
image: "Images/drowzee.png",
level: 33,
};
2024-09-20 14:51:30 +02:00
let bjarne = {
name: "Bjarne",
image: "Images/pokemonTrainerIdle.png",
pokemon: [],
}
2024-09-19 12:20:48 +02:00
let possiblePokemon = [pikachu, bulbasaur, oranguru, drowzee];
let randomPokemon = null;
let app = document.getElementById("app");
updateView();
function updateView() {
getRandomPokemon()
2024-09-20 14:51:30 +02:00
// randomPokemon.level = Math.floor(Math.random() * 100)
// randomPokemon.health = Math.floor(Math.random() * 100)
// console.log(randomPokemon.level, randomPokemon.health);
2024-09-19 12:20:48 +02:00
app.innerHTML = /*HTML*/ `
<div class="container">
<div class="opposingPokemon">
<div>${randomPokemon.name}</div>
<div>lvl: ${randomPokemon.level}</div>
<img src="${randomPokemon.image}">
</div>
<div class="bottomScreen">
<div class="player">
2024-09-20 14:51:30 +02:00
<img src="${bjarne.image}">
<div>${bjarne.name}</div>
2024-09-19 12:20:48 +02:00
</div>
<div class="buttonContainer">
<button onclick="catchPokemon()">Fang</button>
<button onclick="updateView()">Finn en annen</button>
<button onclick="showPokemon()">Vis dine pokemon</button>
</div>
</div>
</div>
`;
}
2024-09-20 14:51:30 +02:00
function caughtPokemonView() {
2024-09-19 12:20:48 +02:00
app.innerHTML = /*HTML*/`
<div class="caughtContainer">
2024-09-20 14:51:30 +02:00
<h1>Du fanget ${bjarne.pokemon[bjarne.pokemon.length - 1].name}</h1>
2024-09-19 12:20:48 +02:00
<div class="buttonContainer">
<button onclick="updateView()">Finn en annen</button>
<button onclick="showPokemon()">Vis dine pokemon</button>
</div>
</div>
`;
}
2024-09-20 14:51:30 +02:00
function catchPokemon() {
bjarne.pokemon.push(randomPokemon);
2024-09-19 12:20:48 +02:00
caughtPokemonView();
}
2024-09-20 14:51:30 +02:00
function showPokemon() {
2024-09-20 14:54:59 +02:00
app.style = null;
2024-09-20 14:51:30 +02:00
app.innerHTML = '';
for (i = 0; i < bjarne.pokemon.length; i++){
2024-09-20 14:54:59 +02:00
app.innerHTML = /*HTML*/ `
<div>${bjarne.pokemon[i].name}</div>
2024-09-20 14:51:30 +02:00
`;
}
app.innerHTML += /*HTML*/`
<div>
<button onclick="updateView()">Finn en annen</button>
</div>
`;
2024-09-19 12:20:48 +02:00
}
2024-09-20 14:51:30 +02:00
function getRandomPokemon() {
2024-09-19 12:20:48 +02:00
let randomNum = Math.floor(Math.random() * possiblePokemon.length);
randomPokemon = possiblePokemon[randomNum];
}