some work on team assignment

This commit is contained in:
Geir Okkenhaug Jerstad 2024-08-28 14:31:18 +02:00
parent 48069b01c7
commit 441d3d0120
2 changed files with 29 additions and 16 deletions

View file

@ -6,22 +6,25 @@ let petElement = document.getElementById('petId');
let frogImage = document.getElementById('tamaFrog').src = "img/default.jpg"; let frogImage = document.getElementById('tamaFrog').src = "img/default.jpg";
setInterval(foodFunction, 1000); let foodCounter = setInterval(foodFunction, 1000);
setInterval(petFunction, 1000); let petCounter = setInterval(petFunction, 1000);
// View // View
// function reset() { function reset() {
// if (foodTime < 0){ if (foodTime < 0){
// foodTime += 50; defaultImg();
// petTime += 10; foodTime = 50;
// defaultImg(); setInterval(foodFunction, 1000);
// } petTime = 10;
// } setInterval(petFunction, 1000);
}
}
function foodFunction() { function foodFunction() {
if (foodTime < 0) { if (foodTime < 0) {
//game over??? //game over???
document.getElementById('tamaFrog').src = "img/dead.jpg"; document.getElementById('tamaFrog').src = "img/dead.jpg";
// setTimeout(afterLife, 1000); clearInterval(foodCounter);
setTimeout(afterLife, 5000);
} else { } else {
foodElement.innerHTML = foodTime + " seconds remaining" foodElement.innerHTML = foodTime + " seconds remaining"
foodTime-- foodTime--
@ -34,6 +37,7 @@ function foodFunction() {
function feed() { function feed() {
if (foodTime > 0 && petTime > 5) { if (foodTime > 0 && petTime > 5) {
foodTime += 10; foodTime += 10;
petElement.innerHTML = petTime + " seconds remaining." + " Pet the frog";
document.getElementById('tamaFrog').src = "img/eating.jpg"; document.getElementById('tamaFrog').src = "img/eating.jpg";
setTimeout(defaultImg, 500) setTimeout(defaultImg, 500)
} }
@ -45,15 +49,21 @@ function defaultImg() {
} }
function petFunction() { function petFunction() {
if (petTime < 5) { if (petTime < 0) {
clearInterval(petCounter);
} else if (petTime < 5) {
document.getElementById('tamaFrog').src = "img/angry.jpg"; document.getElementById('tamaFrog').src = "img/angry.jpg";
petElement.innerHTML = petTime + " seconds remaining"
petTime--;
} }
else { else {
petElement.innerHTML = petTime + " seconds remaining" petElement.innerHTML = petTime + " seconds remaining"
petTime-- petTime--
} }
} }
function pet() { function pet() {
if (foodTime > 0) { if (foodTime > 0) {
petTime += 10; petTime += 10;

View file

@ -1,14 +1,17 @@
.FrogFace { .FrogFace {
user-select: none; user-select: none;
padding: 2px; padding: 2px;
border: solid, 5px rgb(19, 204, 19); border: solid, 15px rgb(19, 204, 19);
max-width: 650px; max-width: 650px;
} }
img{ .img{
max-width: 100%; max-width: 100%;
max-height: 100%; max-height: 100%;
} }
.square { .square {
height: 75px; height: 75px;