Last active
February 7, 2023 19:49
-
-
Save vlazar-/e37d29b8e1a7149432edd431fae7d81b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let boje = ["red", "blue", "green", "yellow"]; | |
let uzorakIgre = []; | |
let uzorakIgrac = []; | |
let igraAktivna = false; | |
let nivo = 0; | |
$(document).keypress(function(){ | |
if(!igraAktivna){ //isto kao igraAktivna == false | |
$("#level-title").text("Level " + nivo); | |
novaBoja(); | |
igraAktivna = true; | |
} | |
}); | |
$(".btn").click(function(){ | |
let odabranaBoja = $(this).attr("id"); | |
uzorakIgrac.push(odabranaBoja); | |
sviraj(odabranaBoja); | |
animiraj(odabranaBoja); | |
provjeriOdgovor(uzorakIgrac.length-1); | |
}); | |
function provjeriOdgovor(nivo){ | |
if(uzorakIgre[nivo] === uzorakIgrac[nivo]){ | |
console.log("tocno"); | |
if(uzorakIgre.length === uzorakIgrac.length){ | |
setTimeout(function(){ | |
novaBoja(); | |
}, 1000); | |
} | |
} else { | |
console.log("pogresno"); | |
sviraj("wrong"); | |
$("body").addClass("game-over"); | |
setTimeout(function(){ | |
$("body").removeClass("game-over"); | |
}, 200); | |
$("#level-title").text("Game Over! Press A Key to Restart"); | |
pokreniPonovno(); | |
} | |
} | |
function novaBoja(){ | |
uzorakIgrac = []; | |
nivo++; // nivo = nivo + 1; | |
$("#level-title").text("Level " + nivo); | |
let broj = Math.floor(Math.random() * 4); | |
console.log(broj); | |
let boja = boje[broj]; | |
console.log(boja); | |
uzorakIgre.push(boja); | |
$("#"+boja).fadeIn(100).fadeOut(100).fadeIn(100); | |
sviraj(boja); | |
} | |
function sviraj(boja){ | |
let audio = new Audio("sounds/"+boja+".mp3"); | |
audio.play(); | |
} | |
function animiraj(boja){ | |
$("#"+boja).addClass("pressed"); | |
setTimeout(function(){ | |
$("#"+boja).removeClass("pressed"); | |
}, 100); | |
} | |
function pokreniPonovno(){ | |
nivo = 0; | |
uzorakIgre = []; | |
igraAktivna = false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment