Hangman
17th February 2002
Hangman is a DHTML version of the classic pen and paper game. The game works in all modern graphical browsers (with javascript enabled).
Choose from the preset themes below (opens in a popup window):
Get the script
Download the zipfile [32K], unzip it into your site directory
and add the configuration script to your page in an external .js file:
//********************************************************************
//*** Hangman script by Brothercake ***
//*** http://www.brothercake.com/ ***
//********************************************************************
var themes = new Array;
var phrases = new Array;
//********************************************************************
//*********** DEFINE THE PRESET THEMES - STARTING FROM [1] ***********
themes[1] = 'Movies'; // maxlength is 25 characters
phrases[1] = new Array( // avoid overlong puzzles - 669 characters in total
'TERMINATOR',
'STAR_WARS',
'GREASE',
'TWELVE_MONKEYS',
'DRIVING_MISS_DAISY',
'GALAXY_QUEST',
'ALIEN',
'PULP_FICTION',
'TOTAL_RECALL',
'THE_MUMMY_RETURNS',
'ENTER_THE_DRAGON',
'INDEPENDENCE_DAY',
'MEN_IN_BLACK',
'MAD_MAX',
'PREDATOR',
'THE_BEACH'
);
themes[2] = 'Female Singers';
phrases[2] = new Array(
'MARIAH_CAREY',
'BRITNEY_SPEARS',
'CHRISTINA_AGUILERA',
'LAURYN_HILL',
'MADONNA',
'DIDO',
'JANET_JACKSON',
'MANDY_MOORE',
'SHANIA_TWAIN',
'KIM_WILDE',
'BJORK',
'KATE_BUSH'
);
//********************************************************************
//build query string
themes[0]="*";
phrases[0]=new Array('*');
var hNum,hString,fText,hWin,jFind,jCount,jString,jEnc,tpa,tpl,goWin;
var enl=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
function generatePuzzle(hNum,goWin) {
//encrypt and compile string
hString='th='+themes[hNum]+'&ph=';
var remPhrases=new Array;
for(i=0;i<phrases[hNum].length;i++){
remPhrases[i]=phrases[hNum][i];
}
for(i=0;i<phrases[hNum].length;i++){
jCount=0;jString='';
for(k=0;k<phrases[hNum][i].length;k++){
tpl=phrases[hNum][i].charAt(k);
if(tpl=="_"){
jFind="99$";
jString+=jFind;
jCount++;
}
else {
for(j=0;j<enl.length;j++){
if(tpl==enl[j]){
jFind=(j+50)+"$";
jString+=jFind;
jCount++;
}
}
}
}
phrases[hNum][i]=jString;
hString+=phrases[hNum][i];
if(i<(phrases[hNum].length-1)){hString+=',';}
}
hString+='&en=true';
//open game window
hWin = open("hangman/hangman.htm?"+hString,"hWin","width=708,height=417,status=yes,scrollbars=no,scrolling=no,toolbar=no,menubar=no,location=no,resizable=no");
for(i=0;i<phrases[hNum].length;i++){
phrases[hNum][i]=remPhrases[i];
}
var sw = screen.width;
var sh = screen.height;
hWin.moveTo((sw - 708) / 2,(sh - 417) / 2);
hWin.focus();
}
Then you can open individual games by passing
the relevant array number through a javascript:
URL:
<a href="javascript:generatePuzzle(1)">Movies</a>
The script contains the configuration arrays for each of your puzzles, and a function to encrypt the data before sending it as a query string to the game - the encryption is not at all sophisticated, but it's enough that the answers aren't right in front of you.
When adding new arrays you must index them beginning from
1 (because 0 is reserved).
You can make any number of puzzles, but each must follow very strict rules:
- The title cannot be longer than 25 characters and can only contain letters, numbers and spaces.
- Phrases can only contain CAPITAL_LETTERS seperated by underscores - no numbers or special characters.
- Each phrase can contain up to three words, which must be separated with underscores.
- Each word should not be longer than 13 letters and each phrase not longer than 40 characters in total.
- The total size of each puzzle array cannot exceed 669 characters, because once encrypted they triple in length, and there is a maximum size a URL + query string can be. This amounts to 15 or 20 phrases on average.