var w,h,my={};function hangmanMain(){let version='0.52';w=360;h=430;my.activeQ=true my.bdSz=9 my.score=0 my.opt={dict:'math'} my.apples=[{id:"apple0",x:74,y:111},{id:"apple1",x:81,y:49},{id:"apple2",x:110,y:89},{id:"apple4",x:155,y:78},{id:"apple5",x:183,y:58},{id:"apple6",x:215,y:52},{id:"apple7",x:242,y:92},{id:"apple8",x:264,y:115},{id:"apple10",x:310,y:88}] my.alphas=[] for(let i=0;i<26;i++){my.alphas.push(String.fromCharCode(65+i))} my.wordStr='angle,area,Apex,Calculate,centimetre,Circle,Cone,decimal,degrees,diameter,Digit,equation,equilateral,Estimate,factor,Fraction,Hexagon,integer,isosceles,litre,multiple,negative,Pentagon,positive,prime,Prism,quotient,radius,Random,Spiral,times,Volume,Zero' my.dicts={math:{name:'Mathematics',type:'file',url:'math-large.txt',words:''},measure:{name:'Measurement',type:'file',url:'measure.txt',words:''},time:{name:'Time',type:'file',url:'time.txt',words:''},seasons:{name:'Seasons',type:'file',url:'seasons.txt',words:''},money:{name:'Money',type:'file',url:'money.txt',words:''},shapes:{name:'Shapes',type:'file',url:'shapes.txt',words:''},comp:{name:'Computers',type:'file',url:'computers.txt',words:''},energy:{name:'Energy',type:'file',url:'energy.txt',words:''},elements:{name:'Elements',type:'file',url:'elements.txt',words:''},science:{name:'Science',type:'file',url:'science.txt',words:''},plants:{name:'Plants',type:'file',url:'plants.txt',words:''},happy:{name:'Happy',type:'file',url:'happy.txt',words:''},positive:{name:'Positive',type:'file',url:'positive.txt',words:''},dogs:{name:'Dogs',type:'file',url:'dogs.txt',words:''},pals:{name:'Palindromes',type:'file',url:'palindromes.txt',words:''},country:{name:'Countries',type:'file',url:'country.txt',words:''},adjectives:{name:'Adjectives',type:'file',url:'adjectives.txt',words:''},adverbs:{name:'Adverbs',type:'file',url:'adverbs.txt',words:''},verbs:{name:'Verbs',type:'file',url:'verbs.txt',words:''},preps:{name:'Prepositions',type:'file',url:'prepositions.txt',words:''},prons:{name:'Pronouns',type:'file',url:'pronouns.txt',words:''},cons:{name:'Conjunctions',type:'file',url:'conjunctions.txt',words:''},} my.fmts=[{name:'play',border:'4px solid white',bg:'linear-gradient(to bottom right, rgba(156,175,251,0.5) 0%, rgba(255,255,255,0.5) 40%, rgba(156,175,241,0.5) 100%)'},{name:'win',border:'4px solid gold',bg:'#ffc'},{name:'win2',border:'4px solid white',bg:'#ffe'},{name:'fail',border:'4px solid grey',bg:'#888'},] var s='';s+='' my.imgHome=(document.domain=='localhost')?'/mathsisfun/images/':'/images/' my.sndHome=(document.domain=='localhost')?'/mathsisfun/images/sounds/':'/images/sounds/' s+='' s+='';s+='';s+='';s+='';my.snds=[];s+='
';s+='
' s+='
' s+='' s+='
';s+='
';s+='' s+='
';my.apples.map(apple=>{s+=``}) s+='
';s+='' my.soundQ=true s+=' ' s+=soundBtnHTML() s+='
';s+='
' s+='
' s+='
' s+='
0
' s+='
 
' s+='
';s+='
';s+=optPopHTML();s+='
© 2020 MathsIsFun.com v'+version+'
';s+='
';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+='
';s+='
';s+='
';s+='
';s+='
';s+=radioHTMLa('Words:','dict',my.dicts,'',0);s+='
' s+='
' s+='
';s+='';s+='';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+='
';s+='
';return s;} function radioSet(name,setValue){var divs=document.querySelectorAll('input[name="'+name+'"]') for(var i=0;i11)continue if(word==prevWord)continue if(word.indexOf(' ')>-1)continue prevWord=word word=word.toLowerCase() if(!regex.test(word))continue goods.push(word)} console.log('goods',words.length,goods.length) console.log('goods',goods.join(',')) return goods} CanvasRenderingContext2D.prototype.pieceDraw=function(x,y,size,type,hoverq){if(hoverq){this.beginPath() this.fillStyle='hsla(60,90%,10%,0.2)' this.arc(x+size*0.1,y+size*0.1,size*1.03,0,Math.PI*2,true) this.fill() this.beginPath() this.lineWidth=6 this.strokeStyle='hsla(120,100%,45%,1)' this.arc(x,y,size,0,Math.PI*2,true) this.stroke()}else{this.beginPath() this.fillStyle='hsla(120,100%,10%,0.3)' this.arc(x+size*0.1,y+size*0.1,size*1.03,0,Math.PI*2,true) this.fill()} var gradient switch(type){case 0:this.beginPath() gradient=this.createRadialGradient(x+size*0.3,y+size*0.2,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(240,10%,50%,1)');gradient.addColorStop(1,'black');this.fillStyle=gradient this.arc(x,y,size,0,Math.PI*2,true) this.fill() this.beginPath() gradient=this.createRadialGradient(x-size*0.5,y-size*0.5,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(0,0%,70%,1)');gradient.addColorStop(0.3,'hsla(0,100%,100%,0)');this.fillStyle=gradient this.arc(x,y,size*1,0,Math.PI*2,true) this.fill() break case 1:this.beginPath() gradient=this.createRadialGradient(x-size*0.4,y-size*0.6,0,x,y,size*1.4);gradient.addColorStop(0,'white');gradient.addColorStop(0.4,'hsla(240,100%,93%,1)');this.fillStyle=gradient this.arc(x,y,size,0,Math.PI*2,true) this.fill() break case 2:this.beginPath() gradient=this.createRadialGradient(x-size*0.4,y-size*0.6,0,x,y,size*1.4);gradient.addColorStop(0,'white');gradient.addColorStop(0.4,'hsla(120,70%,70%,1)');this.fillStyle=gradient this.arc(x,y,size,0,Math.PI*2,true) this.fill() this.beginPath() gradient=this.createRadialGradient(x+size*0.2,y+size*0.2,0,x,y,size);gradient.addColorStop(0,'hsla(0,0%,100%,0.7)');gradient.addColorStop(1,'hsla(0,0%,100%,0)');this.fillStyle=gradient this.arc(x,y,size*1,0,Math.PI*2,true) this.fill() break case 3:this.beginPath() gradient=this.createRadialGradient(x+size*0.3,y+size*0.2,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(240,10%,50%,1)');gradient.addColorStop(1,'hsla(240,10%,20%,1)');this.fillStyle=gradient this.arc(x,y,size,0,Math.PI*2,true) this.fill() this.beginPath() gradient=this.createRadialGradient(x-size*0.5,y-size*0.5,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(0,0%,70%,1)');gradient.addColorStop(0.3,'hsla(0,100%,100%,0)');this.fillStyle=gradient this.arc(x,y,size*1,0,Math.PI*2,true) this.fill() break case 4:this.beginPath() gradient=this.createRadialGradient(x+size*0.3,y+size*0.2,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(120,20%,50%,1)');gradient.addColorStop(1,'hsla(120,20%,10%,1)');this.fillStyle=gradient this.arc(x,y,size,0,Math.PI*2,true) this.fill() this.beginPath() gradient=this.createRadialGradient(x-size*0.5,y-size*0.5,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(0,0%,70%,1)');gradient.addColorStop(0.3,'hsla(0,100%,100%,0)');this.fillStyle=gradient this.arc(x,y,size*1,0,Math.PI*2,true) this.fill() break default:}}