Copy link to clipboard
Copied
As part of my Hangman game I want to have two Arrays, one holding the wordlist, and one holding the clues. What I intend to do, is randomly generate a word along with the clue to that word. I've got the word generator working correctly but I'm not sure how I can make it choose a clue from a seperate array. This is what I have so far to make the Array of words work:
var words: Array = ["LONDON", "CYPRUS", "CHINA"];
This is my Array of the words
number = (Math.floor(Math.random()* 3));
inProgress = words[number];
wordLength = inProgress.length;
This is what I use to randomly Generate the word. Note: number is a number variable I created and inProgress is a String variable I created.
I would like to know how I'm able to make it randomly generate the clue along with this, using the Array:
var clues: Array = ["Capital of England", "Small Island", "Highest population"];
If it makes it easier to see the whole code leading up to this I'll paste it below for you to see. Thanks!
var words: Array = ["LONDON", "CYPRUS", "CHINA"];
var number:Number;
var inProgress: String = new String;
var wordLength:Number;
var myDisplay: Array = new Array();
var displayOut: String = new String;
var rightCount: Number = 0;
var used: String = new String;
var guess: String = new String;
var guessLetter: String = new String;
var correctGuess: Boolean = false;
number = (Math.floor(Math.random()* 3));
inProgress = words[number];
currentClue = clues[number];
wordLength = inProgress.length;
for (var i = 0; i <wordLength; i ++)
{
myDisplay = "*";
displayOut += " " + myDisplay
}
var answerText:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();
myFormat.font = "Segoe UI Symbol";
myFormat.color = 0X00FF00;
myFormat.size = 23;
addChild(answerText);
this.answerText.x = 375;
this.answerText.y = 40;
this.answerText.width =250;
this.answerText.text = displayOut;
answerText.setTextFormat(myFormat);
Use a textfield and assign the clue as the text property of it.
clueTextField.text = clues[number];
Copy link to clipboard
Copied
If you order the two arrays the same then choosing the word should be no different for the clue. Whatever random number you use for the word would be the same value you use for the clue.
Copy link to clipboard
Copied
I see, but how do I display the clue on the screen? Do I use the addChild command?
Copy link to clipboard
Copied
Use a textfield and assign the clue as the text property of it.
clueTextField.text = clues[number];
Copy link to clipboard
Copied
My God, you are smart. Thank you yet again I'm very grateful!!
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now