Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  1. """
  2.  MasterMind Game
  3.  Author: Peter Casey
  4.  Version: 0.01
  5.  Play the MasterMind......
  6. """
  7.  
  8. def welcome():
  9.     """
  10.        Welcome the user, describe this
  11.        is a MasterMind game
  12.        Input: nothing
  13.        Return: nothing
  14.    """
  15.     print("Welcome to MasterMind")
  16.  
  17. def create_puzzle():
  18.     """
  19.        Create a puzzle for the user to guess
  20.        Input: nothing
  21.        Return: the puzzle (four color pegs)
  22.    """
  23.     print("create a puzzle")
  24.  
  25. def get_user_guess():
  26.     """
  27.        Ask the user for their guess for one turn
  28.        Input: nothing
  29.        Return the user guess (four colors in order)
  30.    """
  31.     print("get the users guess")
  32.  
  33. def evaluate_user_guess(users_guess, puzzle):
  34.     """
  35.        Evalute the users guess against the puzzle
  36.        Input: the users guess, the puzzle
  37.        Return: the Black and White pegs based on evaluation
  38.    """
  39.     print("Evaluate user's guess")
  40.     return "BW"
  41.  
  42. def show_guess_results(results):
  43.     """
  44.        Show player the result of their guess (on screen)
  45.        Input: evaluation of user guess
  46.        Return: nothing
  47.    """
  48.     print("Your guess results are:", results)
  49.  
  50. def show_rules():
  51.     """
  52.        Display basic game rules and game play
  53.    """  
  54.     print("Guess four pins from red, green, blue, and purple")
  55.     print("List them in the order you wish")
  56.     print("Enter the pins with R, G, B, or P")
  57.     print("An Example: GRPB <press enter>")
  58.  
  59. def play_one_round():
  60.     """
  61.        Play one round with a single puzzle
  62.        Unlimited guesses until correct
  63.    """
  64.     puzzle = create_puzzle()
  65.     correct_answer = False
  66.  
  67.     while correct_answer == False:   # not correct_answer
  68.         users_guess = get_user_guess()
  69.         results = evaluate_user_guess(users_guess, puzzle)
  70.         show_guess_results(results)
  71.         correct_answer = (results == "BBBB")
  72.  
  73.  
  74. def game_loop():
  75.     """
  76.        Do the welcome, ask if interested in game play
  77.           if so, play game, ask to go again
  78.    """
  79.     welcome()
  80.     show_rules()
  81.     wants_to_play = input("Want to play? (y/n) ")
  82.  
  83.     while wants_to_play in ['y', 'Y', 'Yes', 'yes']:
  84.         play_one_round()
  85.         wants_to_play = input("Want to play again? (y/n) ")  
  86.  
  87. game_loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement