Skip to content

Travis addition to Joes Game #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cba06cb
Create Rectangle-Joe.py
KenwoodFox Nov 1, 2019
a211514
framework for adventure game
KenwoodFox Nov 3, 2019
4d66d35
Added `where` command
KenwoodFox Nov 3, 2019
0f28a72
updated text
KenwoodFox Nov 3, 2019
8c243b5
Use def for fuzzy words
KenwoodFox Nov 4, 2019
a5753eb
Update Adventure.py
KenwoodFox Nov 4, 2019
716eaff
Update Adventure.py
KenwoodFox Nov 4, 2019
48c3fda
It works!
KenwoodFox Nov 4, 2019
9c9eac0
Remove verbose
KenwoodFox Nov 4, 2019
50b20e7
Create .gitignore
KenwoodFox Nov 4, 2019
cadaa78
save system kinda works but not really lol!
KenwoodFox Nov 4, 2019
9ca36f3
Delete Joe.yaml
KenwoodFox Nov 4, 2019
b25c469
fix a bug where lowercase y would not allow you through a door
KenwoodFox Nov 5, 2019
82e89c2
Create instructions for installing requires
KenwoodFox Nov 5, 2019
00a7a97
Update readme.md
KenwoodFox Nov 5, 2019
5a12a37
Update Adventure.py
KenwoodFox Nov 5, 2019
a490125
update typo in lobby
KenwoodFox Nov 5, 2019
b7b1ad0
Update Adventure.py
KenwoodFox Nov 5, 2019
5762c61
added Travis Room
Nov 6, 2019
8037e20
made the code better
Nov 6, 2019
edd5174
added inspect
Nov 6, 2019
3fdef16
updated bottle name
Nov 7, 2019
5905421
changed the ceiling desc
Nov 7, 2019
95e5527
updated the right file this time
Nov 7, 2019
0548888
No synonyms anymore to the look feature
KenwoodFox Nov 7, 2019
b10f3b6
Merge branch 'joes-game' of https://github.com/CRTC-Computer-Engineer…
KenwoodFox Nov 7, 2019
9c5511a
Added comments
KenwoodFox Nov 7, 2019
36dacb9
Removed syntax: No longer requires objects or items in directions to …
KenwoodFox Nov 7, 2019
5aeb5dd
added secretroom
Nov 7, 2019
76f55b5
Merge branch 'joes-game' of https://github.com/CRTC-Computer-Engineer…
Nov 7, 2019
e19e62d
changed item naming
Nov 7, 2019
c74f9e1
added path to the secret room
Nov 7, 2019
3450d7e
made it better
Nov 7, 2019
824a503
Item pickup now works
KenwoodFox Nov 7, 2019
d500b55
Merge branch 'joes-game' of https://github.com/CRTC-Computer-Engineer…
KenwoodFox Nov 7, 2019
69d91e1
added compass navigation, added snake room, fixed bugs
Nov 7, 2019
e44b08a
added a new room. identified more bugs
Nov 13, 2019
a56d7b7
added woodenhouse
Nov 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Basic Text Adventure Game/saves/*.yaml
127 changes: 127 additions & 0 deletions Basic Text Adventure Game/Adventure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import yaml
import Levenshtein as lev

select_edits = 2 # How close an input has to be to match
current_yaml = "gamedata/lobby.yaml"

selected_direction = ''
current_user = ""

def fuzzy_words(input_word, alisis_list):
output = 0
for word in alisis_list:
if ((lev.distance(input_word, word)) < select_edits):
output = output + 1
if output >= 1:
return True
else:
return False

def enter_room(filepath):
"""Reads data from a yaml file"""
with open(filepath, "r") as file_desc:
data = yaml.full_load(file_desc)
return data

def save_data(filepath, data):
"""Dumps data to a yaml"""
with open(filepath, "w") as file_desc:
yaml.dump(data, file_desc)

def main_menu():
while(True):
print("Welcome to the main menu\n[N] to start a new game, [L] to load an old one.")
menu_input = (input(":")).upper() # Get the menu input and make it uppercase
if menu_input == "N": # if the input is N
menu_username = input("Input your name: ") # Ask for name
global current_user # tell python that we're using the global instance of current_user
current_user = "saves/" + menu_username + ".yaml" # Set the user to the user's file location
save_userdata("name", menu_username)
break
elif menu_input == "L":
print("Feature not functional")
else:
print("I did not understand that")

def save_userdata(data_type, data):
if current_user == "":
print("Error, you must create a user")
else:
try:
current_user_data = enter_room(current_user)
current_user_data.update({data_type: data})
save_data(current_user, current_user_data)
except:
userfile = open(current_user, "w")
userfile.write("name:")
userfile.close()
current_user_data = enter_room(current_user)
current_user_data.update({data_type: data})
save_data(current_user, current_user_data)

if __name__ == "__main__": # If this is the main file
current_room = enter_room(current_yaml) # fill current_room with all the room data of the current room
main_menu()
print (current_room['roommeta']['desc']) # give us the desc of that room
while(True):

user_command = (input(":")).upper()
user_arg_1 = user_command.split()[0]
try:
user_arg_2 = user_command.split()[1]
except:
user_arg_2 = ""

if (fuzzy_words(user_arg_1, ["LOOK"])): # If the user asks to look
try: # First try and set the direction to the user input
print(current_room[user_arg_2.lower()]['desc']) # Print the description
selected_direction = user_arg_2.lower() # Set the selected_direction
except:
print("That is not a direction or there is nothing there.") # Print error
elif (fuzzy_words(user_arg_1, ["WHERE", "MAP"])):
try:
print(current_room[selected_direction])
except:
print("Even i dont know where you are")
elif (fuzzy_words(user_arg_1, ["INSPECT", "EXAMINE"])):
try:
print(current_room[selected_direction][user_arg_2.lower()]['inspect']) # Print the inspection text for that object
except:
print("This object cannot be inspected") # Tell the user that there is no information for that selected object
elif (fuzzy_words(user_arg_1, ["PICKUP", "GRAB", "TAKE"])):
try:
pick_item = current_room[selected_direction][user_arg_2.lower()]['name']
data = current_room['items'][pick_item]
save_userdata('inventory', data)
print("You picked up the item")
except:
print("Item cannot be picked up")
elif (fuzzy_words(user_arg_1, ["EXIT", "MENU"])):
save_userdata("current_room", current_yaml) # Save current room
save_userdata("selected_direction", selected_direction) # Save current direction
main_menu()
elif (fuzzy_words(user_arg_1, ["USE"])):
print("use")
elif (fuzzy_words(user_arg_1, ["OPEN"])):
if user_arg_2 == "DOOR":
if selected_direction != '':
destination = current_room[selected_direction][user_arg_2.lower()]['dest']
else:
print("You were not looking in a direction.")
destination = "Nowhere"
if destination != "Nowhere":
confirm = (input(destination + ", would you like to enter? Y/N: ")).upper()
if confirm == "Y":
current_yaml = current_room[selected_direction][user_arg_2.lower()]['path']
current_room = enter_room(current_yaml)
print (current_room['roommeta']['desc'])
elif confirm == "N":
break
else:
print("I did not understand the command")
else:
print("This door does not lead anywhere, its a wonder somebody took the time to install it.")
else:
print("This is not a door or cannot be opened")
else:
print("Thats not something I understand")
38 changes: 38 additions & 0 deletions Basic Text Adventure Game/gamedata/lobby.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
roommeta:
desc: "Welcome to the first room of the game! Thanks so much for playing. There are only a few commands you can use right now, you can LOOK NORTH, EAST, SOUTH, or WEST, INSPECT things, OPEN doors, TAKE things, or USE things."
inspect: The room is simple and undecoreated, somebody should tell the game designer to add stuff
items:
blueKey:
blueKey:
desc: A Blue Key
inspect: The key is small and looks blue.
gameManual:
gameManual:
name: Welcome! and thanks for playing this game, INSPECT this manual for more info
inspect: This manual is almost useful for nothing!
west:
desc: You turn to the left and find a wooden door and a small key on the floor, you cannot pick up the key beacuse i did not program that feature yet.
key:
name: blueKey
inspect: Its a blue key
door:
inspect: A simple wooden door, you're not sure where it leads
dest: Nowhere
east:
desc: You see a simple wooden door and nothing else.
door:
inspect: Its a simple wooden door, your inspection reveals nothing more about it
dest: It apears this door leads to newroom
path: gamedata/newroom.yaml
south:
desc: There is nothing behind you but wall
north:
desc: You see a simple wooden door and nothing else.
door:
inspect: A simple wooden door, you're not sure where it leads
dest: Nowhere
down:
desc: there is the game manual on the ground. use INSPECT MANUAL.
gameManual:
name: gameManual
inspect: This manual is almost useful for nothing!
42 changes: 42 additions & 0 deletions Basic Text Adventure Game/gamedata/minecraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
roommeta:
desc: Dude, it's literally just minecraft.
inspect: "It looks like a new minecraft world! Advancement made: Opening Inventory"
items:
stick:
stick:
desc: A stick! You took it right off of the tree.
inspect: It is a sturdy stick. It seems malleable but you cannot break it.
seed:
seed:
desc: A seed. You foraged it from the grass.
inspect: It is a wheat seed. It is dry.
gameManual:
gameManual:
desc: Welcome! and thanks for playing this game, INSPECT this manual for more info
inspect: This manual is almost useful for nothing!
down:
desc: You look down and see meter long grass blocks. A few of them have grass. you see a SEED.
seed:
name: seed
inspect: It is a wheat seed. It is dry.
west:
desc: you look left. The land seems to go on forever in a cascade of valleys and forests.
east:
desc: You see a wooden house. It is a simple design will large windows. There is a wooden door with slits.
door:
dest: This leads to someones wooden house
inspect: You inspect the door. You see a few marks that look like arrows went through the door.
path:
north:
desc: you look ahead and see a decaying tree. There are a few sticks on the ground surrounding it. One stick looks healthy.
stick:
name: stick
inspect: It is a sturdy stick. It seems malleable but you cannot break it.
south:
desc: There is the door you came in. It leads back to the secret room.
door:
inspect: You try to focus on the details of the door but they seem to disappear. The door seems ethereal.
dest: It appears to go back to the secret room
path: gamedata/secretroom.yaml
up:
desc: You look into the sky. There is a square sun and clouds made of rectangles.
24 changes: 24 additions & 0 deletions Basic Text Adventure Game/gamedata/newroom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
roommeta:
desc: You are in newroom. Its a basic empty room.
inspect: There's nothing in this room.
north:
desc: you see a door
door:
inspect: The door is wet.
dest: this leads to travis room
path: gamedata/travisroom.yaml
south:
desc: you see a locked wooden door. you can INSPECT door
door:
inspect: The door needs a red key.
dest: Nowhere
up:
desc: There is a ceiling.
down:
desc: There is nothing on the ground.
west:
desc: You see a basic wooden door
door:
inspect: A simple wooden door, it leads to the lobby
dest: It apears this door leads to the lobby
path: gamedata/lobby.yaml
36 changes: 36 additions & 0 deletions Basic Text Adventure Game/gamedata/secretroom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
roommeta:
desc: How did you get in here? This room is a secret.
inspect: you feel lighter than normal
items:
stone:
stone:
desc: A stone. It feels lighter than a regular stone. It looks odd.
inspect: There seems to be two words in a different language on the stone. It reads Go back.
gameManual:
gameManual:
desc: Welcome! and thanks for playing this game, INSPECT this manual for more info
inspect: This manual is almost useful for nothing!
down:
desc: You see your body.
west:
desc: you see a wall. The wall is illuminated by the ceiling.

east:
desc: You see a stone on the ground next to the wall. You can INSPECT STONE.
stone:
name: stone
inspect: There seems to be two words in a different language on the stone. It reads Go back.
north:
desc: There is a magical door with the same markings as a few stones to the east.
door:
inspect: It is glowing as if it wasnt on the wall. The markings seem dangerous..
dest: this leads to a blocky world
path: gamedata/minecraft.yaml
south:
desc: You feel something looking at you. You should head back to travis room.
door:
inspect: It is the door leading back to the room you came from.
dest: It appears to go back
path: gamedata/travisroom.yaml
up:
desc: You look into the sky. Sometimes the clouds glitch. You feel like its a simulation.
Empty file.
38 changes: 38 additions & 0 deletions Basic Text Adventure Game/gamedata/travisroom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
roommeta:
desc: This is Travis Room. In this room you can also LOOK UP and LOOK DOWN
inspect: Apon further inspection, the room opens up to your left and right more than forward.
items:
bottle:
desc: A bottle
inspect: The bottle can hold liquid. It's clear.
gameManual:
desc: Welcome! and thanks for playing this game, INSPECT this manual for more info
inspect: This manual is almost useful for nothing!
down:
desc: You look down. You see a bottle on the ground. You can INSPECT bottle.
bottle:
name: bottle
inspect: Its an empty bottle.
west:
desc: You turn to the left and see a wall.

east:
desc: You see a large metal door with strange markings all over it. The door is slightly ajar. you see nothing else.
door:
inspect: Its a large metal door with strange markings all over it, your inspection reveals nothing more about it
dest: This leads to a secret room
path: gamedata/secretroom.yaml
south:
desc: There is the door that leads back to the previous room.
door:
inspect: It is the door leading back to the room you came from.
dest: It appears to go back.
path: gamedata/newroom.yaml
up:
desc: You see the ceiling. you see that the ceiling is gay.
north:
desc: there is a door with a window
door:
inspect: you look through the window. There are a few snakes in the next room.
dest: This leads to another room
path: gamedata/snakeroom.yaml
23 changes: 23 additions & 0 deletions Basic Text Adventure Game/gamedata/woodenhouse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
roommeta:
desc: It is a wooden house in the minecraft room.
items:
gameManual:
gameManual:
desc: Welcome! and thanks for playing this game, INSPECT this manual for more info
inspect: This manual is almost useful for nothing!
down:
desc: There is a nice looking oak wood floor. There is a trapdoor in the corner leading down.
door:
dest: it is a trapdoor that leads under the floor
inspect: it seems to go down very far.
path: Unknown
west:
desc: You can see outside through a large glass window. You can see a decaying tree outside.
east:
desc: There is a table with a few tools, a furnace with some food cooking in it, and a record player.
north:
desc: "There is a closed door labelled: stairs."
door:
dest: There are stairs behind the door. They lead upstairs
inspect: The door is unlocked and goes upstairs.
path: Unknown
7 changes: 7 additions & 0 deletions Basic Text Adventure Game/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Welcome! To get started after cloning this repo, make sure to install dependencies!
`pip install -r requirements.txt`
or if on windows
`py -m pip install -r requirements.txt`

once done, play the game!
`python Adventure.py`
2 changes: 2 additions & 0 deletions Basic Text Adventure Game/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PyYAML==5.1.2
python-Levenshtein==0.12.0
8 changes: 8 additions & 0 deletions CodeHS/3/4/7/Rectangle-Joe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
length = 10
width = 5

area = length * width
perimeter = 2 * (length + width)

print "Length is " + str(length) + "\nWidth is " + str(width)
print "Area is " + str(area) + "\nPerimeter is " + str(perimeter)