Kevin hat gecooked

This commit is contained in:
klikev
2024-09-01 19:58:05 +02:00
parent 76b4fdb33c
commit ba4bd93f03
3 changed files with 47 additions and 5 deletions

View File

@@ -43,13 +43,19 @@ const enemy = document.querySelector("#enemy");
const enemyZahl = document.querySelector("#enemyZahl");
let voreisntellungenFertig = false;
//auf welcher höhe startet der Enemy?
const enemyTopStart = -300;
const enemyTopStart = -700;
let enemyTop = enemyTopStart;
enemy.style.top = enemyTop + "px";
//speed des Enemys, wie schnell er fallen soll
const speedEnemy = 0.2;
//maximale pixel Tiefe bis der Enemy aufhört zu fallen
const maxTiefeEnemy = 100;
//Button
const restartButton = document.querySelector("#restartButton");
const winText = document.querySelector("#winText");
const loseText = document.querySelector("#loseText");
const tom = document.querySelector("#tom");
const tomImg = document.querySelector("#tom img");
//returned den int in der Rechnung, nur die zahl ohne rechenzeichen
function rechnung1Int(){
@@ -177,6 +183,23 @@ function ergebnis(zahl1,zahl2,rechenzeichen){
}
return 0;
}
function battle(){
if(parseInt(enemyZahl.innerText) > 0 && parseInt(fuchsZahl.innerText) > 0){
enemyZahl.innerText = "" + (parseInt(enemyZahl.innerText) - 1);
fuchsZahl.innerText = "" + (parseInt(fuchsZahl.innerText) - 1);
}else{
restartButton.style.display = "block";
if(gameWon){
winText.style.display = "block";
tom.style.display = "block";
tomImg.src = "pics/tom_3.png";
}else{
loseText.style.display = "block";
tom.style.display = "block";
tomImg.src = "pics/tom_1.png";
}
}
}
function playWinAnimation(){
if(gameWon){
if(!voreisntellungenFertig){
@@ -201,7 +224,7 @@ function enemyMoven(speed,maxtiefe){
let nextTop = enemyTop + 10 * speed;
if(nextTop > maxtiefe){
battle();
}else{
enemy.style.top = nextTop + "px";
enemyTop = nextTop;
@@ -225,4 +248,7 @@ function gameloopRechnungen(){
}
}
}
restartButton.addEventListener("click",()=>{
location.reload();
});
setInterval(gameloopRechnungen, 10);