[font=verdana, arial, helvetica][size=2]I’m making this hangman game (with a little help from friends…) where I want a word to appear in a dynamic text box which gives the user a **clue **as to what word they have to guess. Hope this makes sense…
e.g. The word they have to guess is World Wide Web so they receive Clue: www
Any idea how can do that clue thing?
This is the code I’m using in Frame 1:
stop();
_global.adPairs = [
['PC', 'Personal Computer'],
['AS', 'ActionScript'],
['RAM', 'Random Access Memory'], ['WWW', 'World Wide Web']
]; // etc.
initGame();
stop();
function initGame(Void): String {
// get phrase
var rPair:Array = adPairs[Math.round(Math.random()*(adPairs.length-1))];
man.gotoAndStop(1);
// build display
display = "";
for(var i:Number = 0; i < rPair[1].length; i++) {
// place characters
display += (rPair[1].charAt(i) == ' ') ? ' ' : '_';
}
function makeGuess(code) {
// get the character that links to the key pressed
letter = String.fromCharCode(code);
// check to see whether it is a letter
if (isAlpha(letter)) {
// assume that the letter won't be found
gotOne = false;
// start building new display
newDisplay = "";
for(i=0;i<phrase.length;i++) {
// see whether letters match
if (phrase.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 man
if (!gotOne) {
man.nextFrame();
// see whether the man is done
if (man._currentFrame == 8) {
gotoAndPlay("lose");
}
} else if (display == phrase.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 whether it is in A-Z
return ((n >= 65) and (n <= 90));
}
[/size][/font][font=verdana, arial, helvetica][size=2] Doesn’t seem to do much more than go to the end frame: You win!..very annoying, I’m clearly not doing this right…
Does anyone know what I need to do?[/size][/font]