Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallDoesCoding committed Mar 12, 2023
2 parents 65fe84c + 1b262ea commit 8d8beb9
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 188 deletions.
180 changes: 125 additions & 55 deletions chapters.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,119 @@
from music import *

# import the colorama module
import random
from colorama import Fore

import colorama
from colorama import Fore

import music.musicTimer as musicTimer # stop music thread in this file
from music_player import *

colorama.init(convert=True)

# start the game
def start():

answer = input(Fore.GREEN + "You are on a dirt road. Which way to you want to go left or right? " + Fore.LIGHTMAGENTA_EX).lower()
# if user inputs left then

def start():
answer = input(
Fore.GREEN +
"You are on a dirt road. Which way to you want to go left or right? " +
Fore.LIGHTMAGENTA_EX).lower()
# if user inputs left then
if answer == "left":
random.choice(my_list)()

# if user inputs right then
if answer == "right":
random.choice(my_list)()


def chapter_river():
answer = input(Fore.GREEN +
answer = input(
Fore.GREEN +
"You come to a river, you can walk around it or swim across."
"Type walk to walk around & swim to swim across. " + Fore.LIGHTMAGENTA_EX).lower()
"Type walk to walk around & swim to swim across. " +
Fore.LIGHTMAGENTA_EX).lower()
# if user inputs swim then
if answer == "swim":
game_over(Fore.RED + "You swam across the river and were eaten by an aligator \U0001F480")
game_over(
Fore.RED +
"You swam across the river and were eaten by an aligator \U0001F480"
)
# if user inputs walk then
elif answer == "walk":
# q2
answer = input(Fore.GREEN +
answer = input(
Fore.GREEN +
"You walked for many miles, ran out of water and remembered "
"that there was a shop far away (10 miles/16kms) which supplies water."
"Do you want to go there (yes/no)? " + Fore.LIGHTMAGENTA_EX).lower()
# if user inputs no then
"Do you want to go there (yes/no)? " +
Fore.LIGHTMAGENTA_EX).lower()
# if user inputs no then
if answer == "no":
game_over(Fore.RED + "You were very de-hydrated and died of thirst when you were walking. \U0001F480")

game_over(
Fore.RED +
"You were very de-hydrated and died of thirst when you were walking. \U0001F480"
)

# if user inputs yes then
elif answer == "yes":
print(Fore.GREEN + "You went 10 miles walking and bought 10 liters of drinking water. "
print(
Fore.GREEN +
"You went 10 miles walking and bought 10 liters of drinking water. "
)
# q3
answer = input(Fore.GREEN +
"You are thirsty, do you want to drink some water (yes/no)? " + Fore.LIGHTMAGENTA_EX).lower()
# q3
answer = input(
Fore.GREEN +
"You are thirsty, do you want to drink some water (yes/no)? " +
Fore.LIGHTMAGENTA_EX).lower()
# if user inputs yes then
if answer == "yes":
print(Fore.GREEN + "You drank 5 liters of water and now you feel refreshed.")
print(Fore.GREEN +
"You drank 5 liters of water and now you feel refreshed.")

# if user inputs no then
elif answer == "no":
game_over(Fore.RED + "You died of thirst.\U0001F480 ")
else:
else:
print(Fore.RED + "Not a valid answer. You die. \U0001F480")
random.choice(my_list)()
# q4
answer = input(Fore.GREEN +
"You drank 5 liters of water and now you feel refreshed. Do you want to walk further or go back home? (further/home) " + Fore.LIGHTMAGENTA_EX).lower(
)
answer = input(
Fore.GREEN +
"You drank 5 liters of water and now you feel refreshed. Do you want to walk further or go back home? (further/home) "
+ Fore.LIGHTMAGENTA_EX).lower()
# if user inputs further then
if answer == "further":
game_over(Fore.RED + "You walked 100 more miles and you WIN the game! \U0001f3c6",
win=True)
game_over(
Fore.RED +
"You walked 100 more miles and you WIN the game! \U0001f3c6",
win=True,
)
# if user inputs home then
if answer == "home":
game_over(Fore.RED + "A car crashed you and you were rushed to hospital. Although, it was too late by the time you reached the hospital, and you had already died. \U0001F480")
game_over(
Fore.RED +
"A car crashed you and you were rushed to hospital. Although, it was too late by the time you reached the hospital, and you had already died. \U0001F480"
)
else:
print(Fore.RED + "Not a valid answer. You die. \U0001F480")
game_over()



def chapter_bridge():
answer = input(Fore.GREEN + "You come to a bridge, it looks wobbly,"
"do you want it or do you want to head back? (cross/back) " + Fore.LIGHTMAGENTA_EX).lower()
answer = input(
Fore.GREEN + "You come to a bridge, it looks wobbly,"
"do you want it or do you want to head back? (cross/back) " +
Fore.LIGHTMAGENTA_EX).lower()
# if user inputs back then
if answer == "back":
answer = input(Fore.GREEN +
"You go back to the main road."
"Now you can decide to drive forward or turn left. (forward/left) " + Fore.LIGHTMAGENTA_EX).lower()
answer = input(
Fore.GREEN + "You go back to the main road."
"Now you can decide to drive forward or turn left. (forward/left) "
+ Fore.LIGHTMAGENTA_EX).lower()
if answer == "forward":
game_over(Fore.RED + "You drive forward and crash into a tree and die.\U0001F480 ")
game_over(
Fore.RED +
"You drive forward and crash into a tree and die.\U0001F480 ")
# if users inputs left then
if answer == "left":
chapter_lake()
Expand All @@ -88,51 +124,81 @@ def chapter_bridge():
print(Fore.RED + "Not a valid answer. You die. \U0001F480 ")
game_over()


def chapter_stranger():
answer = input(Fore.GREEN +
"You cross the bridge and meet a stranger, do you talk to them? (y/n) " + Fore.LIGHTMAGENTA_EX).lower()
answer = input(
Fore.GREEN +
"You cross the bridge and meet a stranger, do you talk to them? (y/n) "
+ Fore.LIGHTMAGENTA_EX).lower()
if answer == "n":
game_over(Fore.RED + "The stranger was not pleased by you and murdered you. \U0001F480")
game_over(
Fore.RED +
"The stranger was not pleased by you and murdered you. \U0001F480")
elif answer == "y":
answer = input(Fore.GREEN +
"You talk to a wizard and they ask you,"
"You talk a wizard and they ask you,"
"do you want to be a wizard? (y/n) " + Fore.LIGHTMAGENTA_EX).lower()
if answer == "y":
game_over(Fore.RED + "You are a wizard and you WIN the game! \U0001f3c6", win=True)
game_over(Fore.RED +
"You are a wizard and you WIN the game! \U0001f3c6",
win=True)
elif answer == "n":
game_over(Fore.RED + "The stranger was not pleased by you and murdered you. \U0001F480")
game_over(
Fore.RED +
"The stranger was not pleased by you and murdered you. \U0001F480"
)


def chapter_lake():
answer = input(Fore.GREEN + "You turned left and you come to a lake,"
"do you want to swim or go back? (swim/back) " + Fore.LIGHTMAGENTA_EX).lower()
"do you want to swim or go back? (swim/back) " +
Fore.LIGHTMAGENTA_EX).lower()
if answer == "swim":
game_over(Fore.RED + "You swam across the lake and were eaten by a shark. \U0001F480 ")
game_over(
Fore.RED +
"You swam across the lake and were eaten by a shark. \U0001F480 ")

elif answer == "back":
answer = input(Fore.GREEN +
"You go back to the main road."
"Now you can decide to drive forward or turn left. (forward/left) " + Fore.LIGHTMAGENTA_EX).lower()
answer = input(
Fore.GREEN + "You go back to the main road."
"Now you can decide to drive forward or turn left. (forward/left) "
+ Fore.LIGHTMAGENTA_EX).lower()
if answer == "forward":
chapter_tree()
elif answer == "left":
game_over(Fore.RED + "You died. \U0001F480")
else:
print(Fore.RED + "Not a valid answer. You die.")
game_over(Fore.RED + "Not a valid answer. You die.")


def chapter_tree():
answer = input(Fore.GREEN + "You are very hungry and you see a tree with apples, do you want to eat the fruit? (y/n) " + Fore.LIGHTMAGENTA_EX)
answer = input(
Fore.GREEN +
"You are very hungry and you see a tree with apples, do you want to eat the fruit? (y/n) "
+ Fore.LIGHTMAGENTA_EX)
if answer == "y":
game_over(Fore.RED + "You ate the fruit but it was poisonous and you died. \U0001F480")
game_over(
Fore.RED +
"You ate the fruit but it was poisonous and you died. \U0001F480")
elif answer == "n":
answer = input("You are nearly starving to death. Do you want to eat Pears instead of apples? (y/n) " + Fore.LIGHTMAGENTA_EX).lower()
answer = input(
"You are nearly starving to death. Do you want to eat Pears instead of apples? (y/n) "
+ Fore.LIGHTMAGENTA_EX).lower()
if answer == "y":
game_over(Fore.RED + "You ate the pears but they were poisonous and you died. \U0001F480")
game_over(
Fore.RED +
"You ate the pears but they were poisonous and you died. \U0001F480"
)
elif answer == "n":
game_over(Fore.RED + "You were so hungry that you were nearly going to die in a few seconds, but a lovely gentleman gave you some food and you WIN the game! \U0001f3c6", win=True)
game_over(
Fore.RED +
"You were so hungry that you were nearly going to die in a few seconds, but a lovely gentleman gave you some food and you WIN the game! \U0001f3c6",
win=True,
)

else:
print(Fore.RED + "Not a valid answer. You die. \U0001F480")
game_over()



def game_over(message: str = None, *, end_game=True, win=False):
Expand All @@ -146,18 +212,22 @@ def game_over(message: str = None, *, end_game=True, win=False):
print(Fore.LIGHTYELLOW_EX + "Thanks for playing!")
if game_over:
# Play Again
answer = input(Fore.YELLOW + "Do you want to play again? (y/n) " + Fore.LIGHTBLUE_EX)
answer = input(Fore.YELLOW + "Do you want to play again? (y/n) " +
Fore.LIGHTBLUE_EX)
if answer == "y" or answer == "yes":
random.choice(my_list)()
if music == "on":
print(Fore.GREEN + "Music is on")
elif music == "off":
print(Fore.RED + "Music is off")
music()
music.music()
else:
print(Fore.RED + "Thanks for playing!")
exit()
musicTimer.musicTimerObj.cancel() # stop music thread
# make sure to call these 2 lines every time program exits
musicTimer.musicTimerObj.join()

my_list = [chapter_bridge, chapter_lake]
exit()


my_list = [chapter_bridge, chapter_lake]
27 changes: 15 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
# import modules
import sys
import subprocess
import sys

import pkg_resources

from chapters import *
from music_player import *

# install missing modules
required = {'playsound==1.2.2', 'colorama==0.4.6'}
required = {"playsound==1.2.2", "colorama==0.4.6"}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed

if missing:
python = sys.executable
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
subprocess.check_call([python, "-m", "pip", "install", *missing],
stdout=subprocess.DEVNULL)

# import dependencies
from chapters import *
from music import *

# heading text!
heading = 'Choose Your Own Adventure Game!'
heading = "Choose Your Own Adventure Game!"
copyright = "\U000000A9 2023, KendallDoesCoding, All Rights Reserved"
new_str = Fore.BLUE + heading.center(150)
new_str2 = Fore.BLUE + copyright.center(150)
print(new_str)
print(new_str2)


def main():
# welcome to the game
name = input(Fore.YELLOW + "Type your name: " + Fore.LIGHTBLUE_EX)
print(Fore.LIGHTGREEN_EX + "Welcome", name, "to this adventure!" )
print(Fore.LIGHTGREEN_EX + "Welcome", name, "to this adventure!")

# do you want to play?
answer = input(Fore.YELLOW + "Do you want to play? (y/n) " + Fore.LIGHTBLUE_EX)
answer = input(Fore.YELLOW + "Do you want to play? (y/n) " +
Fore.LIGHTBLUE_EX)
if answer == "y" or answer == "yes":
# starting the game
print(Fore.LIGHTGREEN_EX + "Let's play! \U0001F3AE")
if answer == "n" or answer == "no":
print("See you later! \U0001F600")
exit()
# do you want music?
answer = input(Fore.YELLOW + "Do you want music? \U0001F3B5 (y/n) " + Fore.LIGHTBLUE_EX)
answer = input(Fore.YELLOW + "Do you want music? \U0001F3B5 (y/n) " +
Fore.LIGHTBLUE_EX)
if answer == "y" or answer == "yes":
music()
random.choice(my_list)()
Expand All @@ -47,8 +53,5 @@ def main():
random.choice(my_list)()



if __name__ == "__main__":
main()


Loading

0 comments on commit 8d8beb9

Please sign in to comment.