// 03-012-15 - moved js code to wordcode.js file
// 230525 - fix faulty word completion, must press 1st then last letter
aboxtitle="Word Puzzle";
splashscreen='
';
// requires words.js
// puzzle dimensions
rowsize=20; // num of letters in row
colsize=14 // num of letters in column
twoclicks=0 // don't checkword till twoclicks
maxwords=words.length;
// split word list into two halves one for horizontal placement one for vertical placement
// allow for odd numbered lists
halfwords = Math.floor(maxwords / 2)
if(halfwords!=maxwords/2){halfwords=halfwords+1}
startword='';
finishword='';
timetaken=0; //set timetaken as global
newelement="
Clues
";
// preload sounds
soundfiles=['correct1.mp3','wrong1.mp3'];
for (i=0;i100)
{alertboxer('Information
Cannot locate a word, please Reload page
'); }
else{ // store start and end in wordloc array cell for word
wordstart='r'+rownum+'c'+colnum;
wordend='r'+(rownum+words[items].length-1)+'c'+colnum;
wordloc[items]=wordstart+'-'+wordend;
wordlocations=''; //initialise a string to build up cell locations for all letters in word
// write vertical word into table
for (i=0;iCongratulations !All Clues Found
in '+mins+' mins '+secs+' seconds.
Game Over');
// document.getElementById('restart').style.visibility='visible';
}
}
function timer(){
timetaken=timetaken+1;
timerid=setTimeout('timer()',1000);
}
function startup(){
if (title=='') // display title
{document.getElementById('title').innerHTML='Word Puzzle';}
else {document.getElementById('title').innerHTML=title;}
maketable(); // create a dynamic table
// First make sure we start with dots in all cells for any restart
for (i=1;i<=rowsize;i++)
{for (j=1;j<=colsize;j++)
{loc='r'+i+'c'+j;
document.getElementById(loc).innerHTML='.';
document.getElementById(loc).className='letter';
}
}
newelement=''; //clear existing clues
// hide restart button
//document.getElementById('restart').style.visibility='hidden';
// add clues to clue div
for (i=0;i"+clues[i]+" ";
document.getElementById('clues').innerHTML=newelement;
}
locatehword();
alertsetup();
alertboxer(splashscreen);
displayinstructions();
}
function maketable(){
// rowsize colsize from question file
// this creates a new tbody tag needed by ie in memory
newtablebody=document.createElement('tbody');
newtablebody.setAttribute('id','tablebody'); //add an id to the tablebody
//add the tbody tag to the table tag
document.getElementById('puzzle').appendChild(newtablebody);
for (i=1;i<=rowsize;i++)
{ // now build rows and columns
newrow=document.createElement('tr');
for (j=1;j<=colsize;j++)
{
newcell=document.createElement('td'); // create a new td element
id='r'+i+'c'+j;
newcell.setAttribute('id',id); //add an id to the td tag
newcell.setAttribute('class','letter'); //add a class to the td tag
newcell.innerHTML='.'; // add a dot to start
newrow.appendChild(newcell); //add cell to row
}
document.getElementById('tablebody').appendChild(newrow); // add new row to the table
}
}
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')
{//document.getElementById('instructions').style.display='none';
$("#instructions").slideUp("normal");}
else{//document.getElementById('instructions').style.display='block';
$("#instructions").slideDown("normal");}
}
function doafterclose(){ //after alertboxer closes
// add pulser class via js once alertbox closes
document.getElementById('instructionslink').className='boxes';
}
window.onload=function attachbehaviours(){
startup();// now launch startup functions
// Attach onclick behaviour to cells
for (var r=1;r<=rowsize;r++)
{for (var c=1;c<=colsize;c++)
{
cellstring="r"+r+"c"+c;
document.getElementById(cellstring).onclick=function (){checkword(this,this.id)};
}
}
timer();
}