-
Notifications
You must be signed in to change notification settings - Fork 0
/
dungeon_game.py
98 lines (77 loc) · 2.1 KB
/
dungeon_game.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
87
88
89
90
91
92
93
94
95
96
97
import random
import os
CELLS = [(0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 0), (2, 1), (2, 2)]
def get_locations():
monster = random.choice(CELLS)
door = random.choice(CELLS)
start = random.choice(CELLS)
if monster == door:
get_locations()
if monster == start:
get_locations()
if start == door:
get_locations()
print("Monster={} Door={} Start={}".format(monster, door, start))
return monster, door, start
def move_player(player, move):
x, y = player
if move == "LEFT":
y -= 1
elif move == "RIGHT":
y += 1
elif move == "DOWN":
x += 1
else:
x -= 1
player = x, y
return player
def draw_map(player):
print(' _ _ _')
tile ='|{}'
for idx, cell in enumerate(CELLS):
if idx in [0, 1, 3, 4, 6, 7]:
if cell == player:
print(tile.format('X'), end="")
else:
print(tile.format('_'), end="")
else:
if cell == player:
print(tile.format('X|'))
else:
print(tile.format('_|'))
def get_moves(player):
MOVES = ['LEFT', 'RIGHT', 'UP', 'DOWN']
if player[0] == 0:
del MOVES[2]
if player[0] == 2:
del MOVES[3]
if player[1] == 0:
del MOVES[0]
if player[1] == 2:
del MOVES[1]
return MOVES
monster, door, player = get_locations()
total_move = 0
print("Welcome to the dungeon!")
while True:
print("You're currently in room {}".format(player)) # fill in with player position
print("You can move {}".format(get_moves(player))) # fill in with available moves
print("Enter QUIT to quit")
draw_map(player)
move = input("> ")
move = move.upper()
if move == 'QUIT':
break
if move in get_moves(player):
total_move += 1
player = move_player(player, move)
else:
print ("You can't move {}.".format(move))
if player == door:
print("You win!!!!!")
exit()
if player == monster:
print("You got eaten by the monster!!!!")
exit()