Typing Game #
In this lab, you will create a typing game! You will be re-introduced to the Terminal, Python syntax, and logical flow.
๐ป Let's start by playing: MonkeyType
โ๏ธ Once you understand the game, re-arrange the pseudocode in the correct order. Check with a teacher before moving on to the setup.
[0] Setup #
๐ Github Repo: github.com/Making-with-Code/lab_typing_game
๐ป
cd
into the lab
cd lab_typing_game
๐พ ๐ฌ Windows Users
I suggest not copying the path command, and instead using
cd
andls
to ensure you are in the correctmaking_with_code
folder.
๐ป Enter the Poetry Shell. We will also run this command at the start of each lab, but only when we are inside a lab folder.
poetry shell
๐พ ๐ฌ Exiting the poetry shell
When you want to exit the shell, you can type
exit
or^D
๐ป Take a look at the files inside with:
ls
typing_game.py
- will run the gameprompts.py
- stores the typing promptshelpers.py.
- helper functions for the games
๐ป Open the folder in Visual Studio Code:
code .
In the Terminal, We will use
code
now instead ofatom
[1] Typing Game #
๐ป Start by running the game:
python typing_game.py
. As you can see the welcome screen, rules, and countdown to the start of the game already coded. Now that you understand how the logical flow of the game, it’s up to you to finish it!
[Game Logic] #
๐ป Translate the pseudocode to Python code in
typing_game.py
. The pseudocode is in the correct order in the comments of the file.
๐พ ๐ฌ Be sure to constantly play test your game!
Do not be afraid to run your game after every change you make to the code:
python typing_game.py
Testing is the key to successful debugging!
๐ Here are a few useful functions you will need to successfully code a working typing game:
input()
- parameters: string
user_answer = input("Do you like pizza? (yes/no): ")
choice()
-
random library
- parameter: a list
- return value: a random item from a list
animal_list = ['dog','cat','bird']
random_animal = choice(animal_list)
time()
-
time library
- return value: the current time
current_time = time()
calculate_wpm()
- this function is written in helpers.py
- parameters:
prompt
,start_time
,end_time
- return value: the words per minute
wpm = calculate_wpm('hello i am a dog', start_time, end_time)
round()
- parameters: number to round, number of decimal places
number_rounded = round(2.555,2)
[Calculate the user’s accuracy] #
Now that you have the logic of the game complete, let’s communicate the accuracy of the user’s input. Words per Minute (WPM) means nothing without accuracy!
๐ป
In helpers.py
complete the function calculate_accuracy()
to calculate user’s typing accuracy. Typing accuracy is calculated by dividing the correct characters typed in by the total total characters typed. For example, if you typed 9 out of 10 characters correctly, you would have .90 accuracy or 90% accuracy.
- parameters:
chosen_prompt
,user_typed_prompt
- return value:
accuracy
rounded to decimal place
๐ญ Be sure to consider the following:
- how do you loop through each letter of the
user_typed_prompt
and compare it to thechosen_prompt
? - how do you keep track of correct characters?
- how do you find the total number of characters?
- what if the user presses
enter/return
before the end of the prompt?
๐ป
Integrate calculate_accuracy()
into typing_game.py
so it reports both the wpm
and accuracy
to the user. You should print the user’s accuracy as a percentage after the WPM. Consider, how will you convert a decimal to a percentage?
WPM: 80.5
Accuracy: 92.2%
[4] Deliverables #
โกโจ
Once you’ve successfully completed the game be sure to fill out this Google form.
๐ป Push your work to Github:
- git status
- git add file_name.py file_name2.py
- git status
- git commit -m “describe your drawing and your process here”
be sure to customize this message, do not copy and paste this line
- git push
[3] Extension #
๐ Choose from any of the extension activities below. Be sure to push to Github any work you do on either of the extensions.
[Adjusted WPM] #
Adjusted Words Per Minute is the typing speed adjust for the user’s accuracy. It is calculated by WPM*Accuracy
. For example:
wpm = 50.4
accuracy = 80.3%
adjusted_wpm = 40.5
๐ป
Calculate the user’s adjusted_wpm
and print it to the user.
WPM: 80.5
Accuracy: 92.2%
Adjusted WPM: 74.2
[Generate random prompts] #
Typing games often increase the difficulty by having the prompts be random words that do not tell a story. For example the prompt may be something like, “score wear question continue friend”. It is up to you to write a function that does just that.
๐ป
In helpers.py
, finish the function generate_prompt()
.
- It should return a string with a prompt of a random length between 10-15.
- It should get the words from the
common_word_list
inprompts.py
.
๐ป
Integrate generate_prompt()
into typing_game.py
.
[Difficult levels] #
As you may have noticed, the prompts are quite simple. There is no punctuation, hardly any capital letters, no numbers, or special symbols. It is up to you to create an easy, medium, and hard difficulty level of the game.
๐ป
In prompts.py
, fill in the prompt_dictionary
with differing prompts for easy
, medium,
and hard
. You may get the prompts from online, just be sure to cite your sources in the comments of the file.
๐ป
Integrate the difficulty levels into typing_game.py
.
- the user should be able to choose which difficulty they want
- based on that difficulty level, the game should pick a random prompt from that difficulty level.