2-7 Making a Simple Text Game

  1. Write a program that lets the user play the game of “Rock, Paper, Scissors” against the computer.  The program should work as follows:
      • When the program begins, a random number in the range of 1 through 3 is generated.  If the number is 1, then the computer has chosen rock.  If the number is 2, then the computer has chosen paper.  If the number is 3, then the computer has chosen scissors.  But don’t display the computer’s choice yet!
      • The user enters their choice of “rock”, “paper”, or “scissors”.  You may use a menu for this, but be sure to include input validation.
      • The computer’s choice is displayed.
    • A winner is selected based on the following rules:
  2. Write a “Magic Number Guessing Game” that works as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 1000 (inclusive). The program then displays:

    I have a number between 1 and 1000.
    Can you guess my number?
    Please type your first guess:

    The player then types a guess. The program responds with one of the following:

    If the player’s guess is incorrect, your program should loop until the player finally gets the number right.  Y our program should keep telling the player Too high or Too low to help the player “zero in” on the correct answer.  After a game ends, the program should prompt the user to enter “y” to play again or “n” to exit the game.  Design your program with a main() function and a few helper functions, each performing a specific task.

Once you have the above working, enhance your “Magic Number Guessing Game” so that the player has at most 10 guesses. If the player fails to guess in time, the program should display an appropriately chastising message.

  1. CHALLENGE: Let’s turn the number guessing game around! This time write a program where the user is asked to pick a number between 1 and 100, and the computer tries to guess what the number is. When the computer makes a guess, it should present the user with a menu of three options:

    My guess is: 56
    Am I?
    1. Too low.
    2. Correct!
    3. Too high.
    Which one:

    If the computer is correct, the game will end.  If the computer is too low, it should generate another guess that is higher than the previous guess.  If the guess is too high, then it should generate another guess that is lower than the previous guess. Try and make the computer as smart/efficient as possible in its guessing technique. ‘Again, design your program with a main() function and a few helper functions.