This block is a first draft of a number-guessing game. The computer chooses a number and asks the player to guess it. Click the image to load the code.
The game is not so cool yet. You will improve it to make it seem more like a person is playing with you.
Here are some ways to make the code act more like a human. Try each of these in order. When you are done, your finished code should be able to deal with all of them.
- Have the sprite welcome the player and ask the player's name before beginning.
- When the sprite says whether the player's guess is correct or not, have it use the player's name. For example, "Nope, Maria, that's not my number. Try again." or "Wow, Maria, you got it!" or....
- Have the sprite tell the player whether the number the player guessed is too big or too small. "That's too big, David. Try again."
- Right now, the script always picks a number between 1 and 10. At the start of the game, ask the player what the maximum number should be, and set a variable named
maximum
to that number. Let your program choose a number between 1 and maximum
.
- Keep track of how many guesses the player makes before getting the right number.
- When the player guesses the secret number, say how many guesses it took. Congratulate the player, using the player's name.
- See if you can find a way to vary the language a bit so that your program does not always repeat exactly the same words in the same situation. For example, if a player guesses too high twice in a row, the program could say "That's still too big, David. Try another number."
- Be creative! Think of your own improvements.