| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //***************** Scene Object - Initialize When Scene Starts Event *************//
- // this function takes an array
- // shuffles it randomly and returns it
- $this.shuffle = function(arr){
- arr.sort(() => random(-10, 5));
- return arr;
- };
- $this.words = [
- "analog",
- "array",
- "binary",
- "browser",
- "computer",
- "condition",
- "conditional",
- "database",
- "download",
- "function",
- "group",
- "hardware",
- "interface",
- "javascript",
- "keywords",
- "layers",
- "megabyte",
- "network",
- "object",
- "program",
- "random",
- "routine",
- "scene",
- "script",
- "software",
- "sprite",
- "string",
- "syntax",
- "toggle",
- "variable",
- "visible",
- "website",
- "window",
- ];
- $this.getNewWord = function() {
- // clear out the guess word
- guess.text("");
- message.text("Unscramble the word: Click here for a new one.");
-
- // select a word at a random
- $this.selectedWord = $this.words[random($this.words.length - 1)];
-
- // create an empty array for the ordered letters
- var orderedLetters = [];
-
- // put each letter in the array
- for (var l = 0; l < $this.selectedWord.length; l++) {
- orderedLetters.push($this.selectedWord[l]);
- }
-
- // shuffle the letters in a new array
- var shuffledLetters = $this.shuffle(orderedLetters);
- // updated the shuffledLabel text
- shuffledLabel.text(shuffledLetters);
- };
- $this.checkGuess = function() {
- // only check if the guess is the correct length
- var originalWord = $this.selectedWord;
- var guessedWord = guess.text();
- if(originalWord.length === guessedWord.length) {
- message.text("Good job! Click here to play again!");
- // loop through letter in the guess
- for (var l = 0; l < originalWord.length; l++) {
- if (originalWord[l] != guessedWord[l]) {
- message.text("Wrong! Click here to try again!");
- }
- }
- }
- }
- if ($this.scene.state() == "PLAY") {
- $this.getNewWord();
- }
- //********************* resetButton Object - Mouse Click Event ********************//
- guess.text("");
- //******************** submitButton Object - Mouse Click Event ********************//
- $this.scene.checkGuess();
- //******************** message Object - Mouse Click Event ************************//
- $this.scene.getNewWord();
|