Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *title Choicescript Hangman Coding Challenge
- *comment -- LETTER DEFINITIONS --
- *temp l1 "a"
- *temp l2 "b"
- *temp l3 "c"
- *temp l4 "d"
- *temp l5 "e"
- *temp l6 "f"
- *temp l7 "g"
- *temp l8 "h"
- *temp l9 "i"
- *temp l10 "j"
- *temp l11 "k"
- *temp l12 "l"
- *temp l13 "m"
- *temp l14 "n"
- *temp l15 "o"
- *temp l16 "p"
- *temp l17 "q"
- *temp l18 "r"
- *temp l19 "s"
- *temp l20 "t"
- *temp l21 "u"
- *temp l22 "v"
- *temp l23 "w"
- *temp l24 "x"
- *temp l25 "y"
- *temp l26 "z"
- *comment -- GAME [RE]START --
- *label hm_reset
- *comment Number of guesses allowed
- *temp hm_lives 10
- *temp n
- *temp hmvictory false
- *comment Randomly select this game's word
- *rand n 1 10
- *gotoref "hmword_"&n
- *comment -- THE WORDS --
- *label hmword_1
- *temp hmword "dog"
- *temp hmletter_count 3
- *temp hmletter_1 "d"
- *temp hmletter_1_found false
- *temp hmletter_2 "o"
- *temp hmletter_2_found false
- *temp hmletter_3 "g"
- *temp hmletter_3_found false
- *goto hang_man_top
- *label hmword_2
- *temp hmword "cat"
- *temp hmletter_count 3
- *temp hmletter_1 "c"
- *temp hmletter_1_found false
- *temp hmletter_2 "a"
- *temp hmletter_2_found false
- *temp hmletter_3 "t"
- *temp hmletter_3_found false
- *goto hang_man_top
- *label hmword_3
- *temp hmword "fish"
- *temp hmletter_count 4
- *temp hmletter_1 "f"
- *temp hmletter_1_found false
- *temp hmletter_2 "i"
- *temp hmletter_2_found false
- *temp hmletter_3 "s"
- *temp hmletter_3_found false
- *temp hmletter_4 "h"
- *temp hmletter_4_found false
- *goto hang_man_top
- *label hmword_4
- *temp hmword "shark"
- *temp hmletter_count 5
- *temp hmletter_1 "s"
- *temp hmletter_1_found false
- *temp hmletter_2 "h"
- *temp hmletter_2_found false
- *temp hmletter_3 "a"
- *temp hmletter_3_found false
- *temp hmletter_4 "r"
- *temp hmletter_4_found false
- *temp hmletter_5 "k"
- *temp hmletter_5_found false
- *goto hang_man_top
- *label hmword_5
- *temp hmword "horse"
- *temp hmletter_count 5
- *temp hmletter_1 "h"
- *temp hmletter_1_found false
- *temp hmletter_2 "o"
- *temp hmletter_2_found false
- *temp hmletter_3 "r"
- *temp hmletter_3_found false
- *temp hmletter_4 "s"
- *temp hmletter_4_found false
- *temp hmletter_5 "e"
- *temp hmletter_5_found false
- *goto hang_man_top
- *label hmword_6
- *temp hmword "rabbit"
- *temp hmletter_count 6
- *temp hmletter_1 "r"
- *temp hmletter_1_found false
- *temp hmletter_2 "a"
- *temp hmletter_2_found false
- *temp hmletter_3 "b"
- *temp hmletter_3_found false
- *temp hmletter_4 "b"
- *temp hmletter_4_found false
- *temp hmletter_5 "i"
- *temp hmletter_5_found false
- *temp hmletter_6 "t"
- *temp hmletter_6_found false
- *goto hang_man_top
- *label hmword_7
- *temp hmword "mouse"
- *temp hmletter_count 5
- *temp hmletter_1 "m"
- *temp hmletter_1_found false
- *temp hmletter_2 "o"
- *temp hmletter_2_found false
- *temp hmletter_3 "u"
- *temp hmletter_3_found false
- *temp hmletter_4 "s"
- *temp hmletter_4_found false
- *temp hmletter_5 "e"
- *temp hmletter_5_found false
- *goto hang_man_top
- *label hmword_8
- *temp hmword "badger"
- *temp hmletter_count 6
- *temp hmletter_1 "b"
- *temp hmletter_1_found false
- *temp hmletter_2 "a"
- *temp hmletter_2_found false
- *temp hmletter_3 "d"
- *temp hmletter_3_found false
- *temp hmletter_4 "g"
- *temp hmletter_4_found false
- *temp hmletter_5 "e"
- *temp hmletter_5_found false
- *temp hmletter_6 "r"
- *temp hmletter_6_found false
- *goto hang_man_top
- *label hmword_9
- *temp hmword "elephant"
- *temp hmletter_count 8
- *temp hmletter_1 "e"
- *temp hmletter_1_found false
- *temp hmletter_2 "l"
- *temp hmletter_2_found false
- *temp hmletter_3 "e"
- *temp hmletter_3_found false
- *temp hmletter_4 "p"
- *temp hmletter_4_found false
- *temp hmletter_5 "h"
- *temp hmletter_5_found false
- *temp hmletter_6 "a"
- *temp hmletter_6_found false
- *temp hmletter_7 "n"
- *temp hmletter_7_found false
- *temp hmletter_8 "t"
- *temp hmletter_8_found false
- *goto hang_man_top
- *label hmword_10
- *temp hmword "meerkat"
- *temp hmletter_count 7
- *temp hmletter_1 "m"
- *temp hmletter_1_found false
- *temp hmletter_2 "e"
- *temp hmletter_2_found false
- *temp hmletter_3 "e"
- *temp hmletter_3_found false
- *temp hmletter_4 "r"
- *temp hmletter_4_found false
- *temp hmletter_5 "k"
- *temp hmletter_5_found false
- *temp hmletter_6 "a"
- *temp hmletter_6_found false
- *temp hmletter_7 "t"
- *temp hmletter_7_found false
- *goto hang_man_top
- *comment -- / END THE WORDS --
- *label hang_man_top
- *comment Going to "hang_man_top" label basically refreshes the page information, via the routine below.
- *gosub hangman_parse
- *comment GAME MENU/INTERFACE
- *choice
- *if (hmvictory) #YOU WIN!!
- *goto hang_man_top
- *if (hm_lives = 0) #YOU LOSE!!
- *goto hang_man_top
- *if ((hm_lives != 0) and (hmvictory != true)) #Guess a Letter
- *label guess_letter
- *gosub hangman_parse
- What letter?
- *temp str
- *input_text str
- *comment convert input to lowercase for easier matching:
- *script temps.str = temps.str.toLowerCase();
- *temp n 1
- *temp count 0
- *temp this_letter
- *comment Seeing as we can't limit length in input fields, the following loop
- *comment makes sure that input string matches the value of a single letter.
- *comment If for some reason it doesn't, it prints an error and prompts re-entry.
- *label check_letter_loop
- *set this_letter ({"l"&n})
- *if (this_letter != str)
- *if (n < 26)
- *comment if we've not checked the input against all 26 letters, check the next one.
- *set n + 1
- *goto check_letter_loop
- *line_break
- Error: '${str}' is not a letter.
- *line_break
- *goto guess_letter
- *comment reset n (count variable) for next loop
- *set n 1
- *comment Once we know the input is a valid letter we can check that letter against the word itself.
- *comment The following loop checks the input string (letter) against all the letters of the word in play.
- *comment Note that if we get a match we still carry on searching the rest as a letter may appear more than once.
- *label guess_letter_loop
- *set this_letter {("hmletter_"&n)}
- *if (this_letter = str)
- *comment Mark the letter as found/which in turn will tell the parse routine to display it.
- *setref (("hmletter_"&n)&"_found") true
- *set count + 1
- *if (n < hmletter_count)
- *set n + 1
- *goto guess_letter_loop
- *comment Tell the player how many matches there were for that letter.
- ${count} letters matched.
- *comment If there were no matches, i.e. the player guessed wrong, we deduct a life.
- *if (count = 0)
- *line_break
- Life lost.
- *line_break
- *set hm_lives - 1
- *line_break
- *goto hang_man_top
- *if ((hm_lives != 0) and (hmvictory != true)) #Guess the Word
- *gosub hangman_parse
- What do you think the word is?
- *temp str
- *input_text str
- *comment convert input to lowercase for easier matching:
- *script temps.str = temps.str.toLowerCase();
- *comment Check if the input string matches the word...
- *if (str = hmword)
- *set hmvictory true
- *comment The following loop just sets all the word's letters to 'found'/true so they're displayed on screen.
- *temp n 1
- *label guessed_word_loop
- *setref (("hmletter_"&n)&"_found") true
- *if (n != hmletter_count)
- *set n + 1
- *goto guessed_word_loop
- *goto hang_man_top
- *else
- *comment If it doesn't set the lives to 0 and reset the screen, essentially causing an instant game over.
- *set hm_lives 0
- *goto hang_man_top
- #Start Over
- *comment Reset the game
- *goto hm_reset
- *comment This whole routine is responsible for printing the text display
- *label hangman_parse
- The Word:
- *temp n 1
- *temp count 0
- *comment This loop checks every letter's (in the active word) found status - if it's not been found (false) then we print an underscore.
- *comment If it has been found, we print that letter instead.
- *label hmword_print_loop
- *temp this_letter {(("hmletter_"&n)&"_found")}
- *if (this_letter != true)
- _
- *if (this_letter)
- *set this_letter {("hmletter_"&n)}
- *set count + 1
- ${this_letter}
- *if (n < hmletter_count)
- *set n + 1
- *goto hmword_print_loop
- *comment Check for victory
- *if (count = hmletter_count)
- *set hmvictory true
- *comment Print hangman diagram parts based on current lives.
- *line_break
- *line_break
- *if (hm_lives < 5)
- _____
- *line_break
- *if (hm_lives < 6)
- |/
- *if (hm_lives < 4)
- |
- *line_break
- *if (hm_lives < 7)
- |
- *if (hm_lives < 3)
- (x)
- *line_break
- *if (hm_lives < 8)
- |
- *if (hm_lives < 2)
- /|\
- *line_break
- *if (hm_lives < 9)
- |
- *if (hm_lives < 1)
- / \
- *line_break
- *if (hm_lives < 10)
- |\_
- *line_break
- *line_break
- *comment Display remaining lives to the player.
- Lives: ${hm_lives}
- *line_break
- *line_break
- *return
Advertisement
Add Comment
Please, Sign In to add comment