text: "use strict";var MemApp=MemApp||{};MemApp.Constructor={Image:function(e,t){this.src=e,this.id=t},SourceImage:function(e,t){this.src=e,this.count=t}},MemApp.Setup={imgUrl:{PLACEHOLDER_URL:"img/000-placeholder.png",CONGRATS_URL:"img/congrats.jpg"},idList:["#tile1","#tile2","#tile3","#tile4","#tile5","#tile6","#tile7","#tile8","#tile9","#tile10","#tile11","#tile12","#tile13","#tile14","#tile15","#tile16","#tile17","#tile18","#tile19","#tile20"],sourceList:[new MemApp.Constructor.SourceImage("img/007-rooster.jpg",0),new MemApp.Constructor.SourceImage("img/026-sheep.jpg",0),new MemApp.Constructor.SourceImage("img/043-seed.jpg",0),new MemApp.Constructor.SourceImage("img/047-pig.jpg",0),new MemApp.Constructor.SourceImage("img/048-tractor.jpg",0),new MemApp.Constructor.SourceImage("img/045-wheat.jpg",0),new MemApp.Constructor.SourceImage("img/017-flower.jpg",0),new MemApp.Constructor.SourceImage("img/044-wheelbarrow.jpg",0),new MemApp.Constructor.SourceImage("img/023-radish.jpg",0),new MemApp.Constructor.SourceImage("img/029-pear.jpg",0)],audioFile:{MUSIC:new Audio("music/Countryboy-BenSound.mp3"),SOUND_BLEAT:new Audio("music/Bleat-SoundBible.mp3"),SOUND_SNORT:new Audio("music/Snorting-SoundBible.mp3"),SOUND_ROOSTER:new Audio("music/Rooster-SoundBible.mp3")},setAudioVolume:function(){MemApp.Setup.audioFile.MUSIC.volume=.03,MemApp.Setup.audioFile.SOUND_BLEAT.volume=.4,MemApp.Setup.audioFile.SOUND_SNORT.volume=.4,MemApp.Setup.audioFile.SOUND_ROOSTER.volume=.4}},MemApp.TileCreation={createAndSetupTile:function(){for(var e=MemApp.Util.sizeObj(MemApp.Setup.idList),t=0;e>t;t++){var i=MemApp.Setup.idList[t],p=MemApp.TileCreation.getRandomImageIndex();MemApp.Setup.sourceList[p].count++;for(var m=MemApp.Setup.sourceList[p].count;m>2;)p=MemApp.TileCreation.getRandomImageIndex(),MemApp.Setup.sourceList[p].count++,m=MemApp.Setup.sourceList[p].count;MemApp.TileCreation.createImage(i,MemApp.Setup.sourceList[p].src)}MemApp.Setup.setAudioVolume(),MemApp.MemoryData.isSoundOn&&MemApp.MusicHandler.getThisPartyStarted()},getRandomImageIndex:function(){return Math.floor(Math.random()*MemApp.Setup.sourceList.length)},createImage:function(e,t){var i=document.createElement("img");i.setAttribute("src",MemApp.Setup.imgUrl.PLACEHOLDER_URL),i.setAttribute("class","placeholder"),i.setAttribute("id",e),i.setAttribute("imgpath",t),document.getElementById("tileRow").appendChild(i)}},MemApp.MemoryData={img1:"",img2:"",score:0,matchCounter:0,isSoundOn:!0,areTilesMatched:function(e){if(""===this.img1)this.img1=e;else if(""===this.img2){if(this.img2=e,this.img1.src===this.img2.src)return MemApp.MemoryData.isSoundOn&&MemApp.Setup.audioFile.SOUND_BLEAT.play(),this.score+=10,this.matchCounter++,this.img1="",this.img2="",!0;MemApp.MemoryData.isSoundOn&&MemApp.Setup.audioFile.SOUND_SNORT.play(),this.score-=4,MemApp.Timer.isTimerStarted=!0,this.closeTiles(this.img1,this.img2),this.img1="",this.img2=""}return!1},closeTiles:function(e,t){setTimeout(function(){$(document.getElementById(e.id)).attr("src",MemApp.Setup.imgUrl.PLACEHOLDER_URL),$(document.getElementById(t.id)).attr("src",MemApp.Setup.imgUrl.PLACEHOLDER_URL),MemApp.Timer.isTimerStarted=!1},1100)}},MemApp.Timer={isTimerStarted:!1,isFirstClick:!0,seconds:0,minutes:0,hours:0,t:"",timer:function(){MemApp.Timer.t=setTimeout(MemApp.Timer.startCountingGameElapsedTime,1e3)},startCountingGameElapsedTime:function(){MemApp.Timer.seconds++,30===MemApp.Timer.seconds&&(MemApp.MemoryData.score-=4,$("#playerScore").text(MemApp.MemoryData.score)),MemApp.Timer.seconds>=60&&(MemApp.Timer.seconds=0,MemApp.Timer.minutes++,$("#playerScore").text(MemApp.MemoryData.score),MemApp.Timer.minutes>=60&&(MemApp.Timer.minutes=0,MemApp.Timer.hours++));var e=document.getElementById("playerTime");e=(MemApp.Timer.hours?MemApp.Timer.hours>9?MemApp.Timer.hours:"0"+MemApp.Timer.hours:"00")+":"+(MemApp.Timer.minutes?MemApp.Timer.minutes>9?MemApp.Timer.minutes:"0"+MemApp.Timer.minutes:"00")+":"+(MemApp.Timer.seconds>9?MemApp.Timer.seconds:"0"+MemApp.Timer.seconds),document.getElementById("playerTime").innerHTML=e,MemApp.Timer.timer()}},MemApp.UserInteraction={talkToUser:function(){bootbox.prompt({title:"Welcome to Memory Game! <br><br> What's your name?",inputType:"text",size:"small",maxlength:"10",callback:function(e){(null===e||""===e)&&(e="Loser"),$("#playerName").text(e),MemApp.UserInteraction.explainRules()}})},explainRules:function(){bootbox.alert({message:"<h3>Game Rules</h3><br><table class='tbl'><tr><th class='tblHeader'>Tiles match</th><th class='tblHeader'>Tiles mismatch</th><th class='tblHeader'>30 seconds elapse</th></tr><tr><td class='tblData'>+ 10 points</td><td class='tblData'>- 4 points</td><td class='tblData'>- 4 points</td></tr></table><br>Timer will start once you click your first tile. <br><br> <i>Good luck and have fun!</i>",size:"medium"})},showCongratsMsg:function(){bootbox.alert({message:"<img src='"+MemApp.Setup.imgUrl.CONGRATS_URL+"' class='img-responsive'>"})}},MemApp.MusicHandler={getThisPartyStarted:function(){MemApp.Setup.audioFile.MUSIC.play()},partyBreaker:function(){MemApp.Setup.audioFile.MUSIC.pause()}},MemApp.ResetData={resetTime:function(){clearTimeout(MemApp.Timer.t),MemApp.Timer.seconds=0,MemApp.Timer.minutes=0,MemApp.Timer.hours=0,document.getElementById("playerTime").innerHTML="00:00:00"},removeRowContent:function(){$("#tileRow").empty()},resetSrcListCount:function(){for(var e=MemApp.Util.sizeObj(MemApp.Setup.sourceList)-1,t=0;e>=t;t++)MemApp.Setup.sourceList[t].count=0}},MemApp.OnClick={placeholderClicked:function(){if($("#checkPauseBtn").hasClass("glyphicon-play"))return void bootbox.alert({message:"To continue the game, start the timer again (click on play button)."});var e=$(this).attr("src");if(e===MemApp.Setup.imgUrl.PLACEHOLDER_URL&&!MemApp.Timer.isTimerStarted){var t=$(this).attr("imgpath"),i=$(this).attr("id");if($(this).attr("src",t),MemApp.MemoryData.areTilesMatched(new MemApp.Constructor.Image(t,i)),$("#playerScore").text(MemApp.MemoryData.score),MemApp.Timer.isFirstClick&&(MemApp.Timer.isFirstClick=!1,MemApp.Timer.startCountingGameElapsedTime()),10===MemApp.MemoryData.matchCounter){clearTimeout(MemApp.Timer.t),MemApp.MemoryData.isSoundOn&&MemApp.Setup.audioFile.SOUND_ROOSTER.play(),MemApp.UserInteraction.showCongratsMsg();var p={player_name:$("#playerName").text(),player_score:$("#playerScore").text(),player_time:$("#playerTime").text()};$.ajax({url:"./php/insertScore.php",type:"POST",data:p,dataType:"html",contentType:"application/x-www-form-urlencoded;charset=UTF-8"}),setTimeout(function(){$("#tblScore").load("./php/getHighscores.php")},1e3)}}},replayClicked:function(){bootbox.confirm({message:"Your current progress <i>will be lost</i>. <br><br> Are you sure you want to restart? ",size:"small",buttons:{confirm:{label:"Yes",className:"btn-success"},cancel:{label:"No",className:"btn-danger"}},callback:function(e){e&&($("#playerScore").text("0"),MemApp.MemoryData.img1="",MemApp.MemoryData.img2="",MemApp.MemoryData.score=0,MemApp.MemoryData.matchCounter=0,MemApp.Timer.isFirstClick=!0,$("#checkPauseBtn").hasClass("glyphicon-play")&&($("#checkPauseBtn").removeClass("glyphicon-play"),$("#checkPauseBtn").addClass("glyphicon-pause")),MemApp.ResetData.resetTime(),MemApp.ResetData.removeRowContent(),MemApp.ResetData.resetSrcListCount(),MemApp.TileCreation.createAndSetupTile())}})},pausePlayClicked:function(){MemApp.Timer.isFirstClick||($("#checkPauseBtn").hasClass("glyphicon-pause")?(clearTimeout(MemApp.Timer.t),$("#checkPauseBtn").removeClass("glyphicon-pause"),$("#checkPauseBtn").addClass("glyphicon-play")):$("#checkPauseBtn").hasClass("glyphicon-play")&&(MemApp.Timer.timer(),$("#checkPauseBtn").removeClass("glyphicon-play"),$("#checkPauseBtn").addClass("glyphicon-pause")))},musicClicked:function(){$("#checkMusicBtn").hasClass("glyphicon-volume-up")?($("#checkMusicBtn").removeClass("glyphicon-volume-up"),$("#checkMusicBtn").addClass("glyphicon-volume-off"),MemApp.MusicHandler.partyBreaker(),MemApp.MemoryData.isSoundOn=!1):$("#checkMusicBtn").hasClass("glyphicon-volume-off")&&($("#checkMusicBtn").removeClass("glyphicon-volume-off"),$("#checkMusicBtn").addClass("glyphicon-volume-up"),MemApp.MusicHandler.getThisPartyStarted(),MemApp.MemoryData.isSoundOn=!0)}},MemApp.Util={sizeObj:function(e){return Object.keys(e).length}},$(window).on("load",w3.includeHTML()),$(window).on("load",MemApp.TileCreation.createAndSetupTile),$(document).ready(MemApp.UserInteraction.talkToUser),$(document).on("click",".placeholder",MemApp.OnClick.placeholderClicked),$("#btnReplay").click(MemApp.OnClick.replayClicked),$("#btnPause").click(MemApp.OnClick.pausePlayClicked),$("#btnMusic").click(MemApp.OnClick.musicClicked);