Repository navigation
Expand file tree
/
Copy pathadv.py
More file actions
129 lines (101 loc) · 4.15 KB
/
Copy pathadv.py
File metadata and controls
129 lines (101 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from room import Room
from player import Player
from os import system, name
# Declare all the rooms
room = {
'outside': Room("Outside Cave Entrance",
"North of you, the entrance to the the mansion awaits."),
'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the the north, a light flickers in
the distance, but there is no way across the chasm."""),
'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to the north. The smell of gold permeates the air."""),
'treasure': Room("Treasure Chamber", """\n\nYou've found the long-lost treasure
chamber! Sadly, it has already been compl\netely emptied by
earlier adventurers. The only exit is to the the south."""),
}
# Link rooms together
room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
# --- clears console on game launch ---
def clearCon():
#--nt is for windows
if name == 'nt':
_= system('cls')
#--for mac and linux
else:
_= system('clear')
clearCon()
print("""Welcome to the the adventure. In this game you will not be able to the save your progress.
So lace those boots and lets and lets get moving.""")
#--- stringing capitalize and strip to the clear white space and assure name is capital. ---
newPlayer = input("\nWhat is your name brave traveler?\n").capitalize().strip()
while len(newPlayer) < 2:
newPlayer = input('\nPlease input at least a 2 character value for your name.\n').capitalize().strip()
#creates new Player instance with custom name.
Player1 = Player(newPlayer, room['outside'])
print(f'\nWelcome {Player1.name}. You are currently {Player1.current_room}\n')
input("Press any key to the continue")
#--- dictionary for directions ---
directions = {
'n': 'North',
's': 'South',
'e': 'East',
'w': 'West',
'q': 'Quit'
}
print('Type in the letter for the direction you would like to the go:')
for options in directions:
print(f' {options} for {directions[options]}')
print('\n')
currentRoom = []
def roomChange():
keys = room.keys()
for i in keys:
if str(i).capitalize() not in str(Player1.current_room):
continue
else:
currentRoom.clear()
currentRoom.append(i)
# print(i)
# print(Player1.current_room)
roomChange()
direction = ''
print('current room: '+ str(currentRoom[0]))
while direction != 'q':
direction = input('Which way do you go ----')
try:
selected = f'{directions[direction]}'
if direction == 'n':
Player1.current_room = Player1.current_room.n_to
roomChange()
print(f'\n\nYou head {selected} to the {Player1.current_room}\n {room[currentRoom[0]].dialog}\n ')
if direction == 's':
Player1.current_room = Player1.current_room.s_to
roomChange()
print(f'\n\nYou head {selected} to the {Player1.current_room}\n {room[currentRoom[0]].dialog}\n ')
if direction == 'e':
Player1.current_room = Player1.current_room.e_to
roomChange()
print(f'\n\nYou head {selected} to the {Player1.current_room}\n {room[currentRoom[0]].dialog}\n ')
if direction == 'w':
Player1.current_room = Player1.current_room.w_to
roomChange()
print(f'\n\nYou head {selected} to the {Player1.current_room}\n {room[currentRoom[0]].dialog}\n ')
except KeyError:
print(f"\nWhat in the heck is {direction}, try that again\n")
for options in directions:
print(f' {options} for {directions[options]}')
print('\n')
except AttributeError:
print('\nYou see that there is nothing in that direction and turn around.\n')
clearCon()
print(f'\n \nDust yourself off {Player1.name}, we will see you again.\n \n')