// war5.js.txt - use with sink.html, fire.html or space.html // All code and interface design are copyright Mike Capstick // 170625 - rewrite of loadquestions and assess to display correct answer // 250717 - set no. of ships // 110717 - bug fixed on restart images not clearing // 210317 - added doafterclose for pulser // 070117 - randomise question locations // 211216 - Places ojects at random locations in grid // 171216 - increase flexibility to allow non war themes and images // 210611 added sounds // 300511 1. allows questions to contain a mixture of 4 or 5 distractors // 2. simplified html files by moving code into this file // 3. number of questions now unrestricted // 4. test for empty tails to allow for other question banks to be used // 210411 - added support for quiz title if(typeof title!='string'){title=''} // use quiz title if available maxterms=questions.length-1; // how many questions in bank distractornum=0; // allows 4 or 5 distractors in a question //initialise parts of a question as a set of arrays stemarray=new Array(); answer=new Array(); adistract=new Array(); bdistract=new Array(); cdistract=new Array(); ddistract=new Array(); edistract=new Array(); //added to allow 5 distractors tail=new Array(); var thisquestion=0; //populate the questions arrays for (i=0;i to shuffle the answers in some QGM games // input array testsplit[], [0]=Question, [1]-[4]=possible answers, [5]=key A-D to correct answer var abcde="ABCDE"; var i // need to declare this to protect other counters for(i=1; i<=distractornum; i++) { var aa=testsplit[distractornum+1]; //the original answer position var x=aa.charCodeAt(0)-64; // convert ASCII code for answer into number in range 1-4 var newplace=Math.ceil(Math.random()*distractornum); var temp=testsplit[newplace]; testsplit[newplace]=testsplit[i]; testsplit[i]=temp; //swap index with newplace if(i==x){testsplit[distractornum+1]=abcde.substring(newplace-1,newplace);} // if moving the answer, correct the answer flag if(newplace==x){testsplit[distractornum+1]=abcde.substring(i-1,i);} } } function loadquestions(){ // build questions and distractors into a string and randomise location of correct answer // 160625 - rewrite to match revelation game selectstring=''; for (var i=0;i"+stemarray[i]+" "; selectstring=selectstring+" "+tail[i]+"
\n"; } document.getElementById('questionsdiv').innerHTML=selectstring; } function uniques(){ //generate unique randoms between 1 and maxterms and stores them in an array called numbers[] for(var i=1; i<=maxterms; i++) {randomnumber=Math.ceil(Math.random()*maxterms) match=0; for (j=-1;jInformation

You must Click a Cell on the Map to continue.

'); } else{ if (x.selectedIndex !=0) {document.getElementById('resetbutton').focus(); //make drop box lose focus by focussing elsewhere alertboxer('

Information

Your Answer is Locked in and cannot be changed !

'); } } } function assess(answer){ // assess a selected response // First we blur the current object to lock in the answer // we force loss of focus to prevent changes by focusing on the reset button document.getElementById('resetbutton').focus(); // answer = this, passed from onChange event by user selection // stores option value, 1 or 0 in variable response // response = answer.options[answer.selectedIndex].value; response = answer.value; var message=''; // 160525 - get correct answer option and its text actualanswer=document.getElementById(answer.id).querySelector('option[value="1"]').value; correcttext=document.getElementById(answer.id).querySelector('option[value="1"]').text; questionsanswered=questionsanswered+1; //increase number answered so far //check response, increment score if correct and display result if (response=='1') {soundplayer('correct1'); answer.style.color='green'; alertboxer("

Correct

tick
Click on a Cell on the Map

"); } else {soundplayer('wrong1'); answer.style.color='red'; alertboxer("

Incorrect

wrong

The Correct Answer was

"+correcttext+"


Try the Next Question !"); if (questionsanswered==ammo&&hits!=numships){outofammo();} // got it wrong check if out of ammo } } function outofammo(){ alertboxer('

Information

You\'re out of Shots '+gametext[1]+' !,
Hit the New Game button to Play Again

'); playagain(); } function allowplay(x){ // is player allowed a turn ? // only if question answered correctly and before another question is asked if(response=='1') // correct answer {// allowed a turn, has cell been targeted before if(document.getElementById(x).style.visibility=='visible') {alertboxer('

Information

This Cell has already been Attacked.
Try another

');} else {// showexplosion(x); // keep all cell html while displaying explosion cellcontents=document.getElementById(x).parentNode.innerHTML; fireshot(x); soundplayer('explode'); response='0'; // reset response so must fire before answering another question } } else{ alertboxer('

Information

'+gametext[1]+'
You must answer a Question
before you can Click on the Map!

'); } } /* 180625 - removed explosion gif function showexplosion(x){ // keep all cell html while displaying explosion cellcontents=document.getElementById(x).parentNode.innerHTML; document.getElementById('cell'+x).style.backgroundColor='black'; document.getElementById('cell'+x).innerHTML=""; ship=x; // keep span id timer=setTimeout("fireshot(ship)",1200); } */ function fireshot(x){ document.getElementById('cell'+x).innerHTML=cellcontents; //put html back document.getElementById('cell'+x).style.backgroundColor='transparent'; document.getElementById(x).style.visibility="visible"; // make ship letter visible // make image fit cell document.getElementById('cell'+x).style.backgroundSize='contain'; if (document.getElementById(x).innerHTML=="B") {alertboxer("

Congratulations

Excellent, You destroyed a "+gametext[4]+"

"); document.getElementById('cell'+x).style.background='url('+gameimages[0]+') no-repeat center'; document.getElementById('cell'+x).style.backgroundSize='contain'; document.getElementById(x).innerHTML=''; } if (document.getElementById(x).innerHTML=="M") {alertboxer("

Congratulations

You destroyed a "+gametext[5]+"

"); document.getElementById('cell'+x).style.background='url('+gameimages[1]+') no-repeat center'; document.getElementById('cell'+x).style.backgroundSize='contain'; document.getElementById(x).innerHTML=''; } if (document.getElementById(x).innerHTML=="S") {alertboxer("

Congratulations

You destroyed a "+gametext[6]+"

"); document.getElementById('cell'+x).style.background='url('+gameimages[2]+') no-repeat center'; document.getElementById('cell'+x).style.backgroundSize='contain'; document.getElementById(x).innerHTML=''; } if (document.getElementById(x).innerHTML=="x") { alertboxer("

Information


wrong

You Missed !

"); document.getElementById('cell'+x).style.background='url("shot.png") no-repeat center'; document.getElementById(x).innerHTML=' '; // misses hold a single space } // Is the enemy destroyed - count hits of empty cells holding only a space has an object if (document.getElementById(x).innerHTML=="") {hits=hits+1; if (hits>=numships) {message=''; message='

Congratulations

The '+gametext[0]+' is destroyed.
'; message=message+' Congratulations on your promotion to '+gametext[3]+' !
Hit the New Game button to Play Again

'; alertboxer(message); playagain() } } if (questionsanswered==ammo&&hits < numships) // we are out of ammo {outofammo();} } function playagain(){ // make resetbox full screen and display play again button document.getElementById('resetbox').style.width=document.body.clientWidth+'px'; document.getElementById('resetbox').style.height=document.body.clientHeight+'px'; document.getElementById('resetbox').style.display='block'; document.getElementById('resetbutton').style.display='block'; } function soundplayer(x){ // use new html audio tag to play mp3's document.getElementById("sndplayer").src=x+".mp3"; document.getElementById("sndplayer").play(); } function displayinstructions(){ if(document.getElementById('instructions').style.display=='block') {$("#instructions").slideUp("normal");} else{$("#instructions").slideDown("normal");} } function doafterclose(){ //after alertboxer closes // add pulser class via js once alertbox closes // document.getElementById('instructionslink').className='boxes'; }