1 line
4.2 KiB
JavaScript
1 line
4.2 KiB
JavaScript
var room_level,viewspeed=500,timeout=500,health=5,newPlayground=3,level=newPlayground*newPlayground,difficulty=1,showcontent=!1,allow_spin=!0,allow_click=0,play_array=[],anim=0,y=1,correct_answers=0,avoid_repeat=[],randoms=0,no_fail_round=0,round_values=0;function initiate(){setInterval(setTime,1e3),round_value(),lifes(),prep(),calc_difficulty(),console.log(level),make_playground(),randomized(),animation(),console.log(difficulty)}function nextRound(){round_value(),clear_playground(),clear_values(),calc_difficulty(),console.log(level),make_playground(),randomized(),animation(),console.log(difficulty)}function prep(){document.getElementById("start-the-game").style.visibility="hidden"}function round_value(){round_values++,document.getElementById("round").innerHTML=round_values}function animation(){setTimeout(function(){$("#"+play_array[anim]).addClass("animations"),anim++,play_array.length>anim?animation():(basic_timeout(),allow_click=1,spin_round())},viewspeed)}function basic_timeout(){setTimeout(function(){$(".card").removeClass("animations")},timeout)}function lifes(){for(let e=0;e<health;e++)document.getElementById("health").innerHTML+='<img src="assets/textures/heart.png" alt="health">'}function clear_values(){no_fail_round=0,difficulty=1,level=Math.ceil(newPlayground*newPlayground),play_array=[],randoms=0,i=0,card_ids=0,y=0,anim=0,clicked_id=0,allow_click=0,avoid_repeat=[],correct_answers=0,console.log("level="+level+"\n difficulty="+difficulty+"\n array="+play_array+"\n clicked_id="+clicked_id+"\n NewPLaygroud="+newPlayground*newPlayground),calc_difficulty(),newPlayground+=.1}function spin_round(){if(!0===allow_spin)if(round_values>=7&&9>=round_values||round_values>=12&&round_values%3){document.getElementById("wrapper").style.transform="rotate(180deg)",document.getElementById("wrapper").style.height="unset";let e,t=document.getElementsByClassName("card");for(e=0;e<t.length;e++)t[e].style.transform="rotate(180deg)"}else document.getElementById("wrapper").style.transform="rotate(0deg)"}function calc_difficulty(){level<=9&&(level=9),difficulty=.2*level%3+difficulty,difficulty=Math.round(difficulty)}function make_playground(){for(var e=0,t=0,n=0;n<newPlayground;n++){var l=document.createElement("div");for(l.setAttribute("id","card-row"+n),l.setAttribute("class","card-row"),document.getElementById("test-group").appendChild(l),e=0;e<newPlayground;e++){t++;var a=document.createElement("div");a.setAttribute("class","card noSelect"),a.setAttribute("id",t),a.setAttribute("onClick","reply_click(this.id)"),document.getElementById("card-row"+n).appendChild(a),1==showcontent&&document.getElementById(t).classList.add("printid")}}}function clear_playground(){document.getElementById("test-group").innerHTML="",clear_values()}function randomized(){for(;play_array.length<difficulty;)0!=(randoms=Math.floor(Math.random()*level))&&-1===play_array.indexOf(randoms)&&play_array.push(randoms)}function reply_click(e){if(e=Number(e),console.log("level="+level+"\n difficulty="+difficulty+"\n array="+play_array+"\n clicked_id="+e),play_array.includes(e)){if(1===allow_click&&!avoid_repeat.includes(e)){document.getElementById(e).style.backgroundColor="green",document.getElementById(e).style.backgroundImage="url(assets/textures/crate-green.png)",avoid_repeat.push(e),correct_answers++;let t=document.getElementById("score").textContent;play_array.length===correct_answers&&(document.getElementById("score").innerHTML=0!=no_fail_round?1*parseInt(t)+13:2*parseInt(t)+30,nextRound())}}else if(1===allow_click&&!avoid_repeat.includes(e)){document.getElementById(e).style.backgroundColor="red",document.getElementById(e).style.backgroundImage="url(assets/textures/crate_bad.png)",avoid_repeat.push(e),health--;let n=document.getElementById("health");if(n.removeChild(n.childNodes[0]),no_fail_round=1,console.log("Liv: "+health),0==health){allow_click=0,document.getElementById("start-the-game-loose").style.display="flex",card_ids+=1;for(var t=1;card_ids<=t;t++)play_array.includes(t)?(document.getElementById(t).style.backgroundColor="green",document.getElementById(t).style.backgroundImage="url(assets/textures/crate-green.png)"):(document.getElementById(t).style.backgroundColor="red",document.getElementById(t).style.backgroundImage="url(assets/textures/crate_bad.png)")}}document.getElementById("alerted").innerHTML=e} |