Bored Game

by just_another_person in Circuits > Software

127 Views, 4 Favorites, 0 Comments

Bored Game

Screenshot 2024-07-30 031839.png

I came across the idea for this game one day when I was... you guessed it, bored. This is a pretty simple project and doesn't require much of a background in coding to make, so it's very beginner friendly. In any case, I'll be walking though all the steps of the code, as well as some of the terminology.

If you're already familiar with python feel free to skip to the GitHub link at the last step!

Supplies

Screenshot 2024-07-29 025036.png

Since we're just programming for this project, all you need is Python IDLE. You can download the latest version at their website: https://www.python.org/downloads/

Imports & Lists

Screenshot 2024-07-30 032618.png

Lines 1-3-- Imports

Random-- used to generate random terms from the lists we'll use later. This is super helpful for our game because it's a surprise of what joke, riddle, or fact you'll get.

Time & Sleep-- we can use 'sleep' for adding pauses between our print statements, such as between the joke and punch line.


Lines 5-7-- Lists

These are the lists from which we will pull the random terms. Add as many as you like-- the more you add, the more variety in your game.


Line 9-- input

When figuring out what to do, the code relies on user feedback (represented by 'input'), which it stores as the variable 'indicator'. Based on the feedback, the code will do different things.  

Choosing Your Boredom Buster

Screenshot 2024-07-30 060147.png

Line 11-- The 'while True' loop:

The 'while True' loop is super useful because it allows everything inside it to be repeated indefinitely, or until there is a break command (to 'break' out of the loop). This will come in use if you want to play this multiple times.


Line 12-- 'If' statement

The if statement provides a condition that must be fulfilled in order to move on. For this code, the user has to say something along the lines of 'I'm bored'.


Lines 13-15-- Random choice

This simply chooses a random term from the list we made in the previous step.


Line 18-- User Import

stores user's selection as the variable, 'option'.

Coding for Facts, Riddles, and Jokes

Screenshot 2024-07-30 062610.png

For each of these 'if' statements, it details what to do based on whether the user chose a joke, riddle, or fact. There is also a sleep timer between certain lines, so for example the punch line of the joke appears a few seconds later.

Breaking Out of the While True Loop

Screenshot 2024-07-30 103107.png

Breaking out of the loop-- Lines 47-51

Although you can end the code at the previous step and have a functioning game, if you want to go a step further you can ask the user if they want to continue or not. Based on their input, if they answer anything other than 'no', the while true loop continues to repeat. However, if they answer 'no', it breaks the loop, and the code ends. Of course, you can modify the commands and requirements for breaking the code.


Else-- Lines 53-54

If the user input was not one of the options (i.e.-- you inputted 'k' instead of a, b, or c,), then the else statement will be triggered (lines 13-14)

Test

Screenshot 2024-07-30 032007.png

Woohoo yay you've made you're bored game! Test it out with different inputs, jokes, riddles (basically whatever you want) and modify to your liking!!

GitHub Link!!