-
Notifications
You must be signed in to change notification settings - Fork 1
/
dungeon_and_dragons.py
86 lines (78 loc) · 2.28 KB
/
dungeon_and_dragons.py
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
import random
import os
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
dungeon = [(x,y) for x in range(5) for y in range(5)]
def random_items():
return(random.sample(dungeon,3))
def make_dungeon(player_position):
print(" _ _ _ _ _")
for cell in dungeon:
y = cell[1]
if y < 4:
if cell == player_position:
print("|X", end = "")
else:
print("|_", end = "")
elif cell == player_position:
print("|X|")
else:
print("|_|")
def move_player(position,m_input):
x,y = position
if m_input.upper() == "UP":
x -= 1
elif m_input.upper() == "LEFT":
y -= 1
elif m_input.upper() == "RIGHT":
y += 1
elif m_input.upper() == "DOWN":
x += 1
elif m_input.upper() == "QUIT":
exit()
return(x,y)
random_select = random_items()
def moves(position):
x,y = position
moves = ["UP","RIGHT","DOWN","LEFT"]
if x == 0:
moves.remove("UP")
elif y == 4:
moves.remove("RIGHT")
elif x == 4:
moves.remove("DOWN")
elif y == 0:
moves.remove("LEFT")
return(moves)
def main():
location = random_select[0]
door = random_select[1]
dragon = random_select[2]
print("Welcome to the Dungeon!")
input("Press 'Enter' on your keyboard to start the game!")
make_dungeon(location)
print("You are currently in room {}".format(location))
while True:
move_list = moves(location)
print("You can move{}".format(move_list))
print("Enter 'QUIT' to quit")
main_input = input("\n").upper()
if main_input == "QUIT":
break
elif main_input in move_list:
location = move_player(location,main_input)
clear_screen()
make_dungeon(location)
if location == dragon:
print("You lost ! Dragon ate you")
break
elif location == door:
print("Congratulations . you won !")
break
else:
print("You are currently in room {}".format(location))
else:
clear_screen()
make_dungeon(location)
print("Walls are hard ! Don't run into them.")
main()