Skip to content

Commit a5753eb

Browse files
committed
Update Adventure.py
Added main_menu Added save_userdata
1 parent 8c243b5 commit a5753eb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Basic Text Adventure Game/Adventure.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
current_yaml = "gamedata/lobby.yaml"
66

77
selected_direction = ''
8+
current_user = ""
89

910
def fuzzy_words(input_word, alisis_list):
1011
output = 0
@@ -26,9 +27,30 @@ def save_data(filepath, data):
2627
"""Dumps data to a yaml"""
2728
with open(filepath, "w") as file_desc:
2829
yaml.dump(data, file_desc)
30+
31+
def save_userdata(data_type, data):
32+
print(current_user)
33+
if current_user == "":
34+
print("Error, you must create a user")
35+
else:
36+
current_user_data = enter_room(current_user)
37+
current_user_data.update([data_type][data])
38+
save_data(current_user, current_user_data)
39+
40+
def main_menu():
41+
print("Welcome to the main menu\n[N] to start a new game, [L] to load an old one.")
42+
menu_input = (input(": ")).upper()
43+
if menu_input == "N":
44+
menu_username = input("Input your name: ")
45+
current_user = "saves/" + menu_username + ".yaml"
46+
print(current_user)
47+
save_userdata("name", menu_username)
48+
elif menu_input == "L":
49+
print("Feature not functional")
2950

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

@@ -76,6 +98,8 @@ def save_data(filepath, data):
7698
print(current_room[selected_direction][user_arg_2.lower()]['inspect'])
7799
elif (fuzzy_words(user_arg_1, ["PICKUP", "GRAB"])):
78100
print("pickup")
101+
elif (fuzzy_words(user_arg_1, ["EXIT", "MENU"])):
102+
main_menu()
79103
elif (fuzzy_words(user_arg_1, ["OPEN"])):
80104
if user_arg_2 == "DOOR":
81105
destination = current_room[selected_direction][user_arg_2.lower()]['dest']

0 commit comments

Comments
 (0)