Riddler #
In this lab we will remind ourselves of classes and object-oriented programming with a riddle guessing game. It’s up to you to use the Riddle class to create working game.
[0] Setup #
๐ Github Repo: github.com/Making-with-Code/lab_riddler
๐ป Get the necessary packages:poetry update
poetry shell
๐พ ๐ฌ Exiting the poetry shell
When you want to exit the shell, you can type
exitor^D
๐ This repository has two files:
- riddle.py: This file had the- Riddleclass and a list of- Riddleobjects
- game.py: When run, this file should play the riddle guessing game
[1] Riddle Object #
Let’s start by exploring the Riddle object. It has two properties and one method.
class Riddle:
    def __init__(self,prompt,answer):
        self.prompt = prompt
        self.answer = answer
    def check_guess(self,guess):
        """Checks whether a guess is correct.
        Uses the fuzzywuzzy library to accept guesses which are close to the answer.
        """
        min_fuzz_ratio = 80
        similarity = fuzz.ratio(guess.lower(), self.answer.lower())
        if similarity >= min_fuzz_ratio:
            return True
        else:
            return False
To learn more about how
check_guess()accepts guesses that are very close to the answer, you can visit the fuzzywuzzy documentation
๐ป 
 Open riddle.py inside the interactive Python shell. As a reminder, the Python shell is a great way to run small tests.
python -i riddle.py
๐ป 
 Create an instance of a Riddle.
r = Riddle('What has to be broken before you can use it?','an egg')
๐ป 
 Print the prompt and the answer to check you correctly created a Riddle.
r.prompt
r.answer
๐ป 
 Try to guess the riddle by using the check_guess(guess) method.
r.check_guess('a towel')
๐พ ๐ฌ Exiting the python shell
When you want to exit the shell, you can type
exit()or^D
๐ป 
 Now that you understand how to create a Riddle, open up riddle.py
This file contains an empty list riddle_list.
riddle_list = [
]
๐ป 
 Add 5 instances of a Riddle() object to riddle_list. 
Here is a list of riddles, but feel free to write your own!
[2] Creating the Game #
Now that you understand how the Riddle is structured, it’s up to you use it and create a guessing game.
-----------------------------------
---- Welcome to the Riddler ----
-----------------------------------
๐ป Start by opening up
 game.py
๐ป 
 It is up to you to finish the code in game.py to create a riddle guessing game! The game should:
- loop each Riddlein theriddleslist
- ask the user to guess the answer
- tell the user if their guess was correct or incorrect
๐น๏ธ Once you’ve completed your game logic, play test your game! python game.py
-----------------------------------
---- Welcome to the Riddler ----
-----------------------------------
Riddle 1: What is black and white and read all over?
Guess: newspaper
Correct :)
Riddle 2: What has to be broken before you can use it?
Guess: A chicken
Incorrect :(
[3] Deliverables #
โกโจ Congrats on completing the lab!
Once you’ve successfully completed the lab, fill out this Google form.
๐ป Push your work to Github:
- git status
- git add -A
- git status
- git commit -m “describe your code and your process here”
be sure to customize this message, do not copy and paste this line
- git push
[4] Extension: Additional Features #
Now that we’ve got a basic riddle guessing game, let’s improve it!
Simple Improvements #
Let’s start with a few simple improvements.
- tracking user guesses
- randomizing order of riddles
๐ป Keep track of the user's guesses and provide a score at the end. For example once the user guessed all of the riddles, it may print:
Score: 3/5
๐ป Randomize the order of the riddles. Use the random library to change the order the riddles are given each time the user plays the game.
You may want to look at the Random library documentation for a hint
Difficulty Settings #
Currently, there are no difficulty settings for the game. Some riddles are easy, some riddles are difficult, and some riddles are in-between.
๐ป Implement a difficulty setting in your game to make it more accesisble.
 Your game should allow the user between easy, medium, or hard riddles. This will require you to change the Riddle object and the game play flow in game.py.
Hint: what property could you add to store the difficulty of each riddle?
Add Terminal Menu System #
Although the Riddler is functional, it is not the most exciting looking game. Let’s spice it up with colors!
๐ป Explore the package colorama to add color to your game!
The package is already installed, but you will need to add the import statements to the top of
game.py.
