';document.write(s);my.puzN=0
my.opt.dict=my.dicts.math
gameNew()}
function gameNew(){soundPlay('sndNew')
my.activeQ=true
if(my.opt.dict.words.length==0){dictLoad()
return}
msg(my.opt.dict.name)
var myNode=document.getElementById("board");while(myNode.firstChild){myNode.removeChild(myNode.firstChild);}
my.moveN=0
document.getElementById('nextBtn').style.visibility='hidden'
my.boxWd=36
my.boxHt=my.boxWd
console.log('my',my)
bdDraw()
fmtSet(0)
my.apples.map(apple=>{apple.hangQ=true
apple.div=document.getElementById(apple.id)
apple.div.style.left=apple.x+'px'
apple.div.style.top=apple.y+'px'
apple.div.style.height='40px'
apple.div.style.transition='top 0.4s ease-out, height 0.1s ease-in-out 0.3s'})
let words=parseWords(my.opt.dict.words)
my.word=words[Math.floor(Math.random()*words.length)];my.ltrs=[]
for(let i=0;i{s+=s.length==0?'':' '
s+=ltr.foundQ?ltr.ltr:'_'
return s},'')
return s}
function bdDraw(){my.borderLt=(w-my.bdSz*my.boxWd)/2
my.borderTp=0
let x=my.borderLt
let y=my.borderTp
my.bd=[]
my.alphas.map(alpha=>{var tile=new Tile(my.boxWd,my.boxHt,x,y,alpha)
my.bd.push(tile)
x+=my.boxWd
if(x>w-my.boxWd){x=my.borderLt
y+=my.boxHt}})}
function gameCheck(c){console.log('gameCheck',c)
let blankN=0
let newQ=false
my.ltrs.map(ltr=>{if(ltr.ltr==c){ltr.foundQ=true
newQ=true}
if(!ltr.foundQ){blankN++}})
if(newQ){soundPlay('sndYes')}else{soundPlay('sndNo')
let hangs=my.apples.filter(apple=>apple.hangQ==true)
if(hangs.length>0){let hang=hangs[Math.floor(Math.random()*hangs.length)];console.log('hang',hang)
hang.hangQ=false
hang.div.style.top='400px'
hang.div.style.height='15px'
if(hangs.length==1){soundPlay('sndFail')
my.ltrs.map(ltr=>{ltr.foundQ=true})
document.getElementById('nextBtn').style.visibility='visible'
my.activeQ=false
fmtSet(3)}}}
document.getElementById('word').innerHTML=wordFmt()
console.log('blankN',blankN)
let successQ=blankN==0
if(successQ){console.log('successQ')
let hangs=my.apples.filter(apple=>apple.hangQ==true)
my.score+=hangs.length
document.getElementById('score').innerHTML=my.score
document.getElementById('nextBtn').style.visibility='visible'
soundPlay('sndWin')
fmtSet(1)}else{}}
function fmtSet(n){let fmt=my.fmts[n];console.log('fmtSet',n,fmt)
document.getElementById('main').style.border=fmt.border
document.getElementById('main').style.background=fmt.bg}
function radioHTML(prompt,id,lbls,func){var s='';s+='
';s+=prompt;for(var i=0;i';s+='';}
s+='
';return s;}
var seed=1;var seed=+new Date();function random(){var x=Math.sin(seed++)*10000;return x-Math.floor(x);}
function getRandomArbitrary(min,max){return Math.random()*(max-min)+min;}
function getRandomInt(min,max){return Math.floor(Math.random()*(max-min+1))+min;}
function optPopHTML(){var s='';s+='
';return s;}
function optPop(){var pop=document.getElementById('optpop');pop.style.transitionDuration="0.3s";pop.style.opacity=1;pop.style.zIndex=12;pop.style.left=(w-400)/2+'px';}
function optYes(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';var div=document.querySelector('input[name="'+'dict'+'"]:checked')
my.opt.dict=my.dicts[div.id];gameNew()}
function optNo(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';}
function getDropdownHTML(opts,funcName,id,chkNo){var s='';s+='';return s;}
function soundBtnHTML(){var onClr='blue'
var offClr='#bbb'
var s=''
s+=''
s+='
'
return s}
function soundPlay(id,simulQ=true){if(!my.soundQ)return
if(simulQ){if(id.length>0)document.getElementById(id).play()}else{my.snds.push(id)
soundPlayQueue(id)}}
function soundPlayQueue(id){var div=document.getElementById(my.snds[0])
div.play().then(_=>{}).catch(error=>{my.snds.shift();});div.onended=function(){my.snds.shift();if(my.snds.length>0)soundPlayQueue(my.snds[0]);};}
function soundToggle(){var btn='sound'
if(my.soundQ){my.soundQ=false
document.getElementById(btn).classList.add("mute")}else{my.soundQ=true
document.getElementById(btn).classList.remove("mute")}}
class Tile{constructor(wd,ht,lt,tp,txt){this.wd=wd;this.ht=ht;this.txt=txt
this.bgClr='#ffe';this.bdrClr='grey';this.overClr='#dc8'
this.offClr='#fff';this.onClr='#dd0';this.onQ=false
this.hiliteQ=false
var div=document.createElement("div");div.style.width=wd+'px';div.style.height=ht+'px';div.style.position='absolute';div.style.top=tp+'px';div.style.left=lt+'px';this.div=div;var me=this;div.addEventListener('mouseover',function(){if(!my.activeQ)return;me.hilite()
me.overQ=true});div.addEventListener('mouseleave',function(){if(!my.activeQ)return;me.overQ=false
me.draw();});div.addEventListener('click',function(){if(!my.activeQ)return;me.overQ=false
me.flip();my.moveN++
gameCheck(me.txt)});var can=document.createElement('canvas');can.style.position="absolute";can.style.top='0px';can.style.left='0px';can.style.width='100%';can.style.height='100%';can.width=wd;can.height=ht;this.g=can.getContext("2d");div.appendChild(can);document.getElementById('board').appendChild(div);this.draw();}
draw(){var g=this.g;g.clearRect(0,0,this.wd,this.ht);let type=this.onQ?4:2
g.pieceDraw(this.wd/2,this.wd/2,this.wd*0.45,type,this.hiliteQ)
g.fillStyle='black'
g.textAlign='center'
g.font='20px Arial'
g.fillText(this.txt,this.wd/2,this.ht/2+8)
return
if(this.onQ){if(this.overQ){g.strokeStyle=this.overClr
g.lineWidth=2;g.beginPath();g.arc(this.wd/2,this.ht/2,this.wd/3,0,2*Math.PI);g.stroke();}else{g.strokeStyle=this.onClr
g.lineWidth=2;g.beginPath();g.arc(this.wd/2,this.ht/2,this.wd/3,0,2*Math.PI);g.stroke();}}else{if(this.overQ){g.strokeStyle=this.overClr
g.lineWidth=2;g.beginPath();g.arc(this.wd/2,this.ht/2,this.wd/3,0,2*Math.PI);g.stroke();}else{g.strokeStyle=this.offClr;g.lineWidth=2;g.beginPath();g.arc(this.wd/2,this.ht/2,this.wd/3,0,2*Math.PI);g.stroke();}}}
flip(){this.onQ=!this.onQ
this.draw()}
hilite(){this.hiliteQ=true
this.draw();this.hiliteQ=false}
win(){this.bgClr='#ffe';this.draw();}
setxy(lt,tp){this.div.style.left=lt+'px';this.div.style.top=tp+'px';}}
function radioHTMLa(prompt,id,lbls,checkId){var s='';s+='
';s+='
';s+=prompt;s+='
';s+='
';for(var prop in lbls){var lbl=lbls[prop]
var idi=prop
var chkStr=(lbl.id==checkId)?' checked ':'';s+=' ';}
s+='