-
Notifications
You must be signed in to change notification settings - Fork 4k
/
mouredev.py
63 lines (52 loc) · 1.81 KB
/
mouredev.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
maze = [
["🐭", "⬛️", "⬛️", "⬛️", "⬛️", "⬛️"],
["⬜️", "⬛️", "⬛️", "⬛️", "⬜️", "⬛️"],
["⬜️", "⬛️", "⬛️", "⬛️", "⬜️", "⬛️"],
["⬜️", "⬜️", "⬜️", "⬜️", "⬜️", "⬜️"],
["⬛️", "⬜️", "⬛️", "⬜️", "⬛️", "⬛️"],
["⬛️", "⬜️", "⬛️", "⬜️", "⬜️", "🚪"]
]
def print_maze():
for row in maze:
print("".join(row))
print()
mickey = [0, 0]
while True:
print_maze()
print("¿Hacia dónde se mueve Mickey?")
print("[w] arriba")
print("[s] abajo")
print("[a] izquierda")
print("[d] derecha")
direction = input("Dirección: ")
current_row, current_column = mickey
new_row, new_column = current_row, current_column
match direction:
case "w":
new_row = current_row - 1
case "s":
new_row = current_row + 1
case "a":
new_column = current_column - 1
case "d":
new_column = current_column + 1
case _:
print("Dirección no válida.\n")
continue
if new_row < 0 or new_row > 5 or new_column < 0 or new_column > 5:
print("No puedes desplazarte fuera del laberinto.\n")
continue
else:
if maze[new_row][new_column] == "⬛️":
print("¡En esa dirección hay un obstáculo!\n")
continue
elif maze[new_row][new_column] == "🚪":
print("¡Has encontrado la salida!")
maze[current_row][current_column] = "⬜️"
maze[new_row][new_column] = "🐭"
print_maze()
break
else:
maze[current_row][current_column] = "⬜️"
maze[new_row][new_column] = "🐭"
mickey = [new_row, new_column]