Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var wordList = [ // List of words separated into different difficuties.
- // EASY DIFFICULTY
- {word: "CAT", difficulty: "EASY"},
- {word: "DOG", difficulty: "EASY"},
- {word: "BALL", difficulty: "EASY"},
- {word: "FISH", difficulty: "EASY"},
- {word: "TREE", difficulty: "EASY"},
- {word: "BOOK", difficulty: "EASY"},
- {word: "MOON", difficulty: "EASY"},
- {word: "STAR", difficulty: "EASY"},
- {word: "CAKE", difficulty: "EASY"},
- {word: "BIRD", difficulty: "EASY"},
- {word: "SNOW", difficulty: "EASY"},
- {word: "FROG", difficulty: "EASY"},
- {word: "SAND", difficulty: "EASY"},
- {word: "CAR", difficulty: "EASY"},
- {word: "BEE", difficulty: "EASY"},
- {word: "BEAR", difficulty: "EASY"},
- {word: "SHIP", difficulty: "EASY"},
- {word: "LAND", difficulty: "EASY"},
- {word: "BOAT", difficulty: "EASY"},
- {word: "APPLE", difficulty: "EASY"},
- {word: "MILK", difficulty: "EASY"},
- {word: "HAND", difficulty: "EASY"},
- {word: "FOOT", difficulty: "EASY"},
- {word: "GAME", difficulty: "EASY"},
- {word: "KEY", difficulty: "EASY"},
- {word: "DOOR", difficulty: "EASY"},
- {word: "FARM", difficulty: "EASY"},
- {word: "RAIN", difficulty: "EASY"},
- {word: "POND", difficulty: "EASY"},
- {word: "BACK", difficulty: "EASY"},
- {word: "BARK", difficulty: "EASY"},
- {word: "SALT", difficulty: "EASY"},
- {word: "WIND", difficulty: "EASY"},
- {word: "WORM", difficulty: "EASY"},
- {word: "KING", difficulty: "EASY"},
- {word: "QUEEN", difficulty: "EASY"},
- {word: "SPADE", difficulty: "EASY"},
- {word: "JOKE", difficulty: "EASY"},
- // MEDIUM DIFFICULTY
- {word: "TIGER", difficulty: "MEDIUM"},
- {word: "DANCE", difficulty: "MEDIUM"},
- {word: "BREAD", difficulty: "MEDIUM"},
- {word: "GRASS", difficulty: "MEDIUM"},
- {word: "CHAIR", difficulty: "MEDIUM"},
- {word: "OCEAN", difficulty: "MEDIUM"},
- {word: "MUSIC", difficulty: "MEDIUM"},
- {word: "CANDY", difficulty: "MEDIUM"},
- {word: "WATER", difficulty: "MEDIUM"},
- {word: "CLOUD", difficulty: "MEDIUM"},
- {word: "TABLE", difficulty: "MEDIUM"},
- {word: "BRUSH", difficulty: "MEDIUM"},
- {word: "EAGLE", difficulty: "MEDIUM"},
- {word: "TRAIN", difficulty: "MEDIUM"},
- {word: "PAPER", difficulty: "MEDIUM"},
- {word: "WATCH", difficulty: "MEDIUM"},
- {word: "SUGAR", difficulty: "MEDIUM"},
- {word: "SLIME", difficulty: "MEDIUM"},
- {word: "SMILE", difficulty: "MEDIUM"},
- {word: "MONEY", difficulty: "MEDIUM"},
- {word: "GREEN", difficulty: "MEDIUM"},
- {word: "BLUE", difficulty: "MEDIUM"},
- {word: "FIELD", difficulty: "MEDIUM"},
- {word: "CLOCK", difficulty: "MEDIUM"},
- {word: "SHOES", difficulty: "MEDIUM"},
- {word: "STORM", difficulty: "MEDIUM"},
- {word: "ISLAND", difficulty: "MEDIUM"},
- {word: "TRAVEL", difficulty: "MEDIUM"},
- {word: "TICKET", difficulty: "MEDIUM"},
- {word: "JADE", difficulty: "MEDIUM"},
- {word: "ZEBRA", difficulty: "MEDIUM"},
- // HARD DIFFICULTY
- {word: "ELEPHANT", difficulty: "HARD"},
- {word: "FREEDOM", difficulty: "HARD"},
- {word: "UNIVERSE", difficulty: "HARD"},
- {word: "WORLD", difficulty: "HARD"},
- {word: "FOREST", difficulty: "HARD"},
- {word: "SYMPHONY", difficulty: "HARD"},
- {word: "HOSPITAL", difficulty: "HARD"},
- {word: "PICTURE", difficulty: "HARD"},
- {word: "EXERCISE", difficulty: "HARD"},
- {word: "WISDOM", difficulty: "HARD"},
- {word: "HOLOGRAM", difficulty: "HARD"},
- ];
- var messages = [
- {text: "This is a good start!", amount: 1},
- {text: "Three right-answer-teers!", amount: 3},
- {text: "You are on a roll!", amount: 5},
- {text: "This is impressive!", amount: 8},
- {text: "You're really good at this..!", amount: 10},
- {text: "This is my highest score ever", amount: 14},
- {text: "A whole 20 words with no misses??", amount: 20},
- {text: "How are you doing this?", amount: 22},
- {text: "Okay this is starting to get worrying", amount: 25},
- {text: "You have to be cheating.", amount: 30}
- ];
- var currentWord = ""; // Placeholder variabe for the current word chosen
- var scrambledWord = ""; // PLaceholder variable for the current word scrambled
- var hintUsed = false; // Bool value meant to hold whether or not a hint has been used
- var playerScore = 0; // Holds player current score
- var playerHighscore = 0; // Holds player highest score
- // Main Screen Handlers
- onEvent("mainScreenBegin", "click", function(){ // Functions runs when begin button is pressed
- setScreen("gameScreen"); // Sets screen to the game screen
- updateScreen(); // Calls updatescreen() function
- });
- // Game Screen Handlers
- function updateScreen(){ // function ran when UI update is needed
- var randomPick = Math.floor(Math.random() * wordList.length); // Picks a random word from the list of words
- currentWord = wordList[randomPick].word; // Updates currentWord vaue to chosen word
- scrambledWord = scrambleWord(currentWord); // Runs scrambleWord(word) function with currentWord as sent parameter.
- setText("gameScreenScrambleBox", scrambledWord); // Updates the textbox to the scrambled word
- setText("gameScreenDifficulty", wordList[randomPick].difficulty); // Updates textbox to match current word difficulty
- // Series of if-statements ran in order to update the text color of word difficulty text box
- if (wordList[randomPick].difficulty == "EASY") {
- setProperty("gameScreenDifficulty", "text-color", "#17b300");
- } else if (wordList[randomPick].difficulty == "MEDIUM") {
- setProperty("gameScreenDifficulty", "text-color", "#ffcb4c");
- } else {
- setProperty("gameScreenDifficulty", "text-color", "#fb7070");
- }
- // Updates player score and player highscore text boxes
- setText("gameScreenScore", "Score: " + playerScore);
- setText("gameScreenHScore", "Highscore: " + playerHighscore);
- hintUsed = false; // Resets hintUsed to false
- setText("gameScreenHDisplay", ""); // Resets textbox to blank
- setText("gameScreenTextInput", ""); // Resets user input text box to blank
- }
- // Parameter word holds the current randomly chosen word.
- function scrambleWord(word){ // Function ran when sent word needs to be scrambled
- var letters = word.split(""); // Separates characters into individuals and assigns them to the letters list
- for (var i = letters.length - 1; i > 0; i--){ // Loops through all elements in letters list
- var tempIndex = Math.floor(Math.random() * (i + 1)); // Creates a temporary index bet
- var tempVariable = letters[i]; // Temporary variable meant to hold current chosen letter
- letters[i] = letters[tempIndex]; // Changes the value of the letters[i] element to randomly chosen index
- letters[tempIndex] = tempVariable; // Changes the value of letters[tempIndex] element to formerly updated variable
- }
- return letters.join(""); // Joins the individual characters into one chunk of characters (scrambled word)
- }
- function updateScore(bool){
- if (bool){
- playerScore++;
- if (playerScore > playerHighscore){
- playerHighscore = playerScore;
- }
- for (var i = 0; i < messages.length - 1; i++){
- if (messages[i].amount == playerScore){
- setText("gameMessageDisplay", messages[i].text);
- }
- }
- } else {
- playerScore = 0;
- setText("gameMessageDisplay", "");
- }
- }
- onEvent("gameScreenBack", "click", function(){ // Event ran when the back button is pressed
- setScreen("mainScreen"); // Sets screen to main/home screen
- });
- onEvent("gameScreenSubmit", "click", function(){
- if (getText("gameScreenTextInput").toUpperCase() == currentWord || getText("gameScreenTextInput").toUpperCase() == currentWord + " " ){
- updateScore(true);
- setProperty("gameScreenTextInput", "border-color", "green");
- var currTime = getTime();
- while (getTime() - currTime < 1000){}
- setProperty("gameScreenTextInput", "border-color", rgb(153, 153, 153));
- playSound("sound://category_notifications/game_notification_83.mp3");
- } else{
- updateScore(false);
- setProperty("gameScreenTextInput", "border-color", "red");
- var currTime0 = getTime();
- while (getTime() - currTime0 < 1000){}
- setProperty("gameScreenTextInput", "border-color", rgb(153, 153, 153));
- playSound("sound://category_alerts/comedy_game_over_1.mp3");
- }
- updateScreen();
- });
- onEvent("gameScreenHint", "click", function(){ // Function ran when the hint button is pressed
- var firstLetter = currentWord[0]; // Gathers the first letter of the current word
- // Checks whether the hint has already been used on this word or not.
- if (!hintUsed){ // If hint hasnt been used provides hint and updates hint text box while setting hintUsed variable to true
- setText("gameScreenHDisplay", "THE FIRST LETTER OF THE WORD IS: " + firstLetter);
- hintUsed = true;
- } else { // If hint has been used provides warning and then updates hint text box with current hint
- setText("gameScreenHDisplay", "HINT ALREADY USED!");
- // Functions as a one second pause in the middle of the event
- var currTime = getTime();
- while (getTime() - currTime < 1000){}
- setText("gameScreenHDisplay", "THE FIRST LETTER OF THE WORD IS: " + firstLetter);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement