# Hangman help

**URL:** <https://forum.kirupa.com/t/hangman-help/1873>\
**Category:** flash\
**Created:** [May 7, 2002, 3:31pm UTC](https://forum.kirupa.com/t/hangman-help/1873 "2002-05-07T15:31:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 7, 2002, 3:31pm UTC](https://forum.kirupa.com/t/hangman-help/1873/1 "2002-05-07T15:31:00Z")

</div>

Hi there,  
I’m creating a hangman game and am having a difficult time getting the script to make the computer use the keyboard input (letter keystroke) check the word and add the letter to the word if it’s correct.  
Here’s what I have so far;

initGame();  
stop();

function initGame() {  
// get phrase  
words = new Array();  
words[0] = “game”;  
words[1] = “chocolate”;  
words[2] = “strawberry”;  
words[3] = “taupe”;  
words[4] = “detect”;  
words[5] = “soda pop”;  
words[6] = “square”;  
words[7] = “dinner”;  
words[8] = “breakfast”;  
words[9] = “fuchsia”;

clues = new Array();  
clues[0] = “activity engaged in for diversion or amusement”;  
clues[1] = “a food prepared from ground roasted cacao beans”;  
clues[2] = “the juicy edible usually red fruit of of several low-growing temperate herbs (genus Fragaria) of the rose family that is technically an enlarged pulpy receptacle bearing numerous achenes”;  
clues[3] = “a brownish gray”;  
clues[4] = “to discover the true character of”;  
clues[5] = “a sweet drink consisting of soda water, flavoring, and often ice cream”;  
clues[6] = “any of the quadrilateral spaces marked out on a board for playing games”;  
clues[7] = “a formal feast or banquet”;  
clues[8] = “the first meal of the day especially when taken in the morning”;  
clues[9] = “any of a genus (Fuchsia) of decorative shrubs of the evening-primrose family having showy noddiflowers usually in deep pinks, reds, and purples”;  
//lets say you have 10 words and clues  
var seed = random(10);  
display = words[seed];  
definition = clues[seed];  
// build display  
display = “”;  
for(i=0;i\<words.length;i++) {  
// place saces in the right spots  
if (words.charAt(i) == " ") {  
display = display + " ";

} else {  
// place underscores in place of letters  
display = display + “\_”;  
}  
}  
}  
function makeGuess(code) {  
// get the character that corresponds to the key pressed  
letter = String.fromCharCode(code);

// check to see if it is a letter  
if (isAlpha(letter)) {

// assume that the letter will not be found  
gotOne = false;

// start building new display  
newDisplay = “”;  
for(i=0;i\<words.length;i++) {

// see if letters match  
if (words.charAt(i).toUpperCase() == letter.toUpperCase()) {

// place letter in display text  
newDisplay = newDisplay + letter.toUpperCase();

// note that at least one match has been found  
gotOne = true;

} else {

// not found, so display same character  
newDisplay = newDisplay + display.charAt(i) ;  
}  
}

// show new display  
display = newDisplay;

// if no match found, then add more to fox  
if (!gotOne) {  
fox.nextFrame();

// see if the fox is done  
if (fox.\_currentFrame == :cool: {  
gotoAndPlay(“lose”);  
}

} else if (display == words.toUpperCase()) {  
// the display matches the original, game over  
gotoAndPlay(“win”);  
}  
}  
}

// utility to test whether a character is in A-Z  
function isAlpha(letter) {  
// get character code  
n = letter.charCodeAt(0);

// convert low case to upper case  
if (n \> 90) n -= 32;

// see if it is in A-Z  
return ((n \>= 65) and (n \<= 90));  
}

And I have a movie clip that has this attached

onClipEvent (keyUp) {  
\_root.makeGuess(Key.getAscii());  
}  
Thanks  
Zoester
