├── README.md └── adventure.py /README.md: -------------------------------------------------------------------------------- 1 | # text-based-adventure-game-python 2 | A simple text based choose your own adventure game built in python3. You can find the step by step tutorial here on my blog - https://thecodingpie.com 3 | 4 | Output: 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /adventure.py: -------------------------------------------------------------------------------- 1 | # some rooms 2 | 3 | # diamond room 4 | def diamond_room(): 5 | # some prompts 6 | print("\nYou are now in a room filled with diamonds!") 7 | print("And there is a door too!") 8 | print("What would you do? (1 or 2)") 9 | print("1). Take some diamonds and go through the door.") 10 | print("2). Just go through the door.") 11 | 12 | # take input() 13 | answer = input(">") 14 | 15 | if answer == "1": 16 | # the player is dead, call game_over() function with the "reason" 17 | game_over("They were cursed diamonds! The moment you touched it, the building collapsed, and you die!") 18 | elif answer == "2": 19 | # the player won the game 20 | print("\nNice, you're are an honest man! Congrats you win the game!") 21 | # activate play_again() function 22 | play_again() 23 | else: 24 | # call game_over() with "reason" 25 | game_over("Go and learn how to type a number.") 26 | 27 | 28 | # bear room 29 | def bear_room(): 30 | # give some prompts 31 | # '\n' is to print the line in a new line 32 | print("\nThere is a bear here.") 33 | print("Behind the bear is another door.") 34 | print("The bear is eating tasty honey!") 35 | print("What would you do? (1 or 2)") 36 | print("1). Take the honey.") 37 | print("2). Taunt the bear.") 38 | 39 | # take input() 40 | answer = input(">") 41 | 42 | if answer == "1": 43 | # the player is dead! 44 | game_over("The bear killed you.") 45 | elif answer == "2": 46 | # lead him to the diamond_room() 47 | print("\nYour Good time, the bear moved from the door. You can go through it now!") 48 | diamond_room() 49 | else: 50 | # else call game_over() function with the "reason" argument 51 | game_over("Don't you know how to type a number?") 52 | 53 | 54 | # monster room 55 | def monster_room(): 56 | # some prompts 57 | # '\n' is to print the line in a new line 58 | print("\nNow you entered the room of a monster!") 59 | print("The monster is sleeping.\nBehind the monster, there is another door. What would you do? (1 or 2)") 60 | print("1). Go through the door silently.") 61 | print("2). Kill the monster and show your courage!") 62 | 63 | # take input() 64 | answer = input(">") 65 | 66 | if answer == "1": 67 | # lead him to the diamond_room() 68 | diamond_room() 69 | elif answer == "2": 70 | # the player is dead, call game_over() with "reason" 71 | game_over("The monster was hungry, he/it ate you.") 72 | else: 73 | # game_over() with "reason" 74 | game_over("Go and learn how to type a number.") 75 | 76 | 77 | # function to ask play again or not 78 | def play_again(): 79 | print("\nDo you want to play again? (y or n)") 80 | 81 | # convert the player's input to lower_case 82 | answer = input(">").lower() 83 | 84 | if "y" in answer: 85 | # if player typed "yes" or "y" start the game from the beginning 86 | start() 87 | else: 88 | # if user types anything besides "yes" or "y", exit() the program 89 | exit() 90 | 91 | 92 | # game_over function accepts an argument called "reason" 93 | def game_over(reason): 94 | # print the "reason" in a new line (\n) 95 | print("\n" + reason) 96 | print("Game Over!") 97 | # ask player to play again or not by activating play_again() function 98 | play_again() 99 | 100 | 101 | def start(): 102 | # give some prompts. 103 | print("\nYou are standing in a dark room.") 104 | print("There is a door to your left and right, which one do you take? (l or r)") 105 | 106 | # convert the player's input() to lower_case 107 | answer = input(">").lower() 108 | 109 | if "l" in answer: 110 | # if player typed "left" or "l" lead him to bear_room() 111 | bear_room() 112 | elif "r" in answer: 113 | # else if player typed "right" or "r" lead him to monster_room() 114 | monster_room() 115 | else: 116 | # else call game_over() function with the "reason" argument 117 | game_over("Don't you know how to type something properly?") 118 | 119 | 120 | # start the game 121 | start() --------------------------------------------------------------------------------