var w,h,g,my={};function hiloMain(mode){var version='0.62';w=360;h=180;var s='';s+='' my.sndHome=(document.domain=='localhost')?'/mathsisfun/images/sounds/':'/images/sounds/' s+='';s+='';s+='';s+='
';s+='';s+='';s+='';s+='
';s+='
';s+='
';my.snds=[];my.soundQ=true s+=' ' s+=soundBtnHTML() s+='
© 2019 MathsIsFun.com v'+version+'
';s+='
';s+='
';s+='
0
';s+='
';s+='
';s+='
Bet:
' s+='';s+='
2
';s+='
';s+='
';s+='';s+='
';s+='';s+='
';s+='
';s+='
';s+='
';s+='';s+='
';s+='
';document.write(s);my.deck=new Deck();my.inGameQ=false;} function onBetChg(n,v){v=Math.round(v);document.getElementById('bet').innerHTML=v;my.bet=v;} function setBet(){var min=Math.round(my.score/2);var max=Math.round(my.score);var div=document.getElementById('betrange');console.log("setBet div",div.value,div.min,div.max);var ratio=(div.value-div.min)/(div.max-div.min);div.min=min;div.max=max;if(!isNaN(ratio))my.bet=Math.round(min+ratio*(max-min));console.log("setBet",min,max,ratio,my.bet);div.value=my.bet;document.getElementById('bet').innerHTML=my.bet;} function gameStart(){var div=document.getElementById('result');div.style.visibility='hidden';do{console.log("shuffle");my.deck.shuffle();}while(skipCardQ(my.deck.cards[0].val));my.cardNo=0;my.cardMax=8;my.score=100;document.getElementById('score').innerHTML=my.score;my.bet=100;setBet();drawCards();my.inGameQ=true;} function skipCardQ(cardVal){if(cardVal<=1||cardVal>=11)return true;return false;} function choose(hiQ){if(!my.inGameQ)return;var prevCard=my.deck.cards[my.cardNo];var thisCard=my.deck.cards[my.cardNo+1];console.log("choose",hiQ,prevCard.name,prevCard.val,thisCard.name,thisCard.val);var winQ=false;if(hiQ){if(thisCard.val>prevCard.val)winQ=true;}else{if(thisCard.val=my.cardMax-1){gameOver();}} function gameOver(){console.log("gameOver");my.inGameQ=false;var div=document.getElementById('result');div.style.visibility='visible';var s='';if(my.score<=0){s='Ooops,
points all gone';}else{if(my.score<200){s='You got '+my.score+' points';}else{s='Congratulations! You got '+my.score+' points';soundPlay('sndWin')}} document.getElementById('msg').innerHTML=s;} function drawCards(){var xp=20;var yp=190;for(var i=0;i=my.cardMax){card.show('none');}else{if(i<=my.cardNo){card.show('front');}else{card.show('back');} card.place(xp,yp);xp+=80;if(xp>300){xp=20;yp+=100;}}}} function soundBtnHTML(){var onClr='blue' var offClr='#bbb' var s='' s+='' s+='
' return s} function soundPlay(id,simulQ){if(!my.soundQ)return simulQ=typeof simulQ!=='undefined'?simulQ:false if(simulQ){if(id.length>0)document.getElementById(id).play()}else{my.snds.push(id) soundPlayQueue(id)}} function soundPlayQueue(){var div=document.getElementById(my.snds[0]) div.play() div.onended=function(){my.snds.shift();if(my.snds.length>0)soundPlayQueue();};} 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")}} function Deck(){this.names=['1','2','3','4','5','6','7','8','9','10','J','Q','K'];this.suits=['Hearts','Diamonds','Spades','Clubs'];this.cards=[];this.backImg=new Image();this.backImg.setAttribute('crossOrigin','anonymous');var svg=document.getElementById('svg1');var xml=(new XMLSerializer).serializeToString(svg);this.backImg.src='data:image/svg+xml;charset=utf-8,'+xml;this.frontImg=new Image();this.frontImg.setAttribute('crossOrigin','anonymous');this.frontImg.onload=this.loadCards.bind(this);my.imgHome=(document.domain=='localhost')?'/mathsisfun/data/images/':'/data/images/' this.frontImg.src=my.imgHome+'cards.png';} Deck.prototype.loadCards=function(){for(var i=0;i0;i-=1){var j=Math.floor(Math.random()*(i+1));var temp=this.cards[i];this.cards[i]=this.cards[j];this.cards[j]=temp;}} Deck.prototype.redraw=function(){for(var i=0;i