Developing a Number Guessing Game

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.

starting script for a number guessing game

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.

  1. Have the sprite welcome the player and ask the player's name before beginning.
  2. 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....
  3. 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."
  4. 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.
  5. Keep track of how many guesses the player makes before getting the right number.
  6. When the player guesses the secret number, say how many guesses it took. Congratulate the player, using the player's name.
  7. 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."
  8. Be creative! Think of your own improvements.