Hello everybody, I need some help with a game I'm trying to program. It's basically hangman without the animations.
I'd appreciate any contributions!
So far, I've come up with the part of the script that determines which word to use (provided that the player sets the number of letters). Now, I need to program the part of the game that allows the player to guess a word, and for the sprite to show which letter appears in the appropriate spot (for example, if the word were game, and the player guesses "g", it'd appear on top of the sprite as g _ _ _). However, if the player guesses incorrectly, then the sprite should inform them that the player has lost a life. This should continue per guess, so if the next word the player guesses is a "m", then it should say, g _ m _ . Until the player either runs out of lives, or, guesses the word entirely.
Another concern I have is, once the letter has already been guessed, how would I prevent the player from guessing the same letter again? And if they do decide to input a repeated value, how would I go about alerting them?
Thank you all in advance.
Offline
when gf clicked set [lives v] to (5) set [word v] to [word] delete [all] of [word_letters v] set [i v] to (0) repeat <length of [word]> add <letter (i) of (word)> to [word_letters v] change [i v] by (1) end delete [all] of [guesses v] forever if <(lives) > (0)> ask [What letter do you want to guess?] and wait if <[guesses v] contains (answer)> say [You already guessed that!] for (3) secs else add (answer) to [guesses v] if <[word_letters v] contains (answer)> set [i v] to (0) repeat <length of [word_letters v]> if <(answer) = <item (i) of [word_letters v]>> delete (i) of [word_letters v] end change [i v] by (1) end else say [That letter is not in the word!] for (3) secs change [lives v] by (-1) end end say [You have guessed the following letters] for (3) secs say (guesses) for <<length of [guesses v]> / (2)> secsAlso (guesses) is the list, not a variable.
Word = test
Word_Display = ____
Letter: t
Word_Display = t__t
Letter: s
Word_Display = t_st
Letter: e
Word_Display = test
Word_Display = You got it!
You could do something like:
when gf clicked set [word_display v] to [] forever set [n v] to (0) set [word_display v] to [] repeat <length of (word)> if <[word_letters v] contains <item (n) of [guesses v]>> set [word_display v] to <join (word_display) <item (n) of [guesses v]>> else set [word_display v] to <join (word_display) [_]> end change [n v] by (1) end say (word_display) for (3) secsIt should be quite simple to merge those two scripts together. Try 'em out and tell us if it works.
Last edited by Magnie (2012-02-09 00:11:51)
Offline
Could you explain the script beyond the point of set i to 0, repeat length of word letters, and so on? I somewhat got lost at that point. Also, it appears as though you're deleting the letters from the word list if they match it correctly--if I do that, how will I eventually determine whether they've guessed all the letters correctly?
Thank you for helping, I appreciate it
Offline
Haha, whoops, you can replace the deletion part with a say block saying something like "The letter is in the word!".
Btw: It's 11PM here, so I wasn't/am-not thinking straight.
when gf clicked set [lives v] to (5) set [word v] to [word] delete [all] of [word_letters v] set [i v] to (0) repeat <length of [word]> add <letter (i) of (word)> to [word_letters v] change [i v] by (1) end delete [all] of [guesses v] forever if <(lives) > (0)> ask [What letter do you want to guess?] and wait if <[guesses v] contains (answer)> say [You already guessed that!] for (3) secs else add (answer) to [guesses v] if <[word_letters v] contains (answer)> say [The letter is in the word!] for (3) secs else say [That letter is not in the word!] for (3) secs change [lives v] by (-1) end end say [You have guessed the following letters] for (3) secs say (guesses) for <<length of [guesses v]> / (2)> secs set [i v] to (0) set [word_display v] to [] repeat <length of (word)> if <[word_letters v] contains <item (i) of [guesses v]>> set [word_display v] to <join (word_display) <item (i) of [guesses v]>> else set [word_display v] to <join (word_display) [_]> end change [i v] by (1) end say (word_display) for (3) secsIf you want, I can explain all the code later.
Last edited by Magnie (2012-02-09 01:27:25)
Offline
Hi Everyone I'll Really need to know all the script on this so can u help
Offline
Connor-McIntosh wrote:
Hi Everyone I'll Really need to know all the script on this so can u help
There is a script above, you can use that one. Could you explain what you need help with more thoroughly?
Offline
Do you know the game eight ball
Offline
Connor-McIntosh wrote:
Do you know the game eight ball
I've played with an Eight Ball before.
Could you please explain you are trying to do with Scratch so we can help?
Offline
I'll Would Like To Know How To Make A maze on my first Map Then a Hangman on the other 1 Then a Math quiz o there other but i would like when i start a game u have to press play to start or information for wat to do and leaderboard
Offline
Connor-McIntosh wrote:
I'll Would Like To Know How To Make A maze on my first Map Then a Hangman on the other 1 Then a Math quiz o there other but i would like when i start a game u have to press play to start or information for wat to do and leaderboard
It sounds like what you're doing is pretty complex. To organize all those scripts, I usually create a main script that broadcasts things in the order in which they happen.
On the main menu, create a sprite and program it to start the maze game when it's clicked.
when [Maze button] clicked broadcast [Maze v]In the maze sprites:
when I receive [Maze v] //Maze scripts go under thisAs for the various games you want to make, I would recommend searching this website for similar projects, and using those scripts.
Last edited by silvershine (2012-02-12 12:08:25)
Offline