-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPI_parte4_mostrarMapa.py
81 lines (65 loc) · 2.34 KB
/
PI_parte4_mostrarMapa.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
import os
from typing import List, Tuple
import readchar
from readchar import readkey, key
laberinto = """..###################
....#...............#
#.#.#####.#########.#
#.#...........#.#.#.#
#.#####.#.###.#.#.#.#
#...#.#.#.#.....#...#
#.#.#.#######.#.#####
#.#...#.....#.#...#.#
#####.#####.#.#.###.#
#.#.#.#.......#...#.#
#.#.#.#######.#####.#
#...#...#...#.#.#...#
###.#.#####.#.#.###.#
#.#...#.......#.....#
#.#.#.###.#.#.###.#.#
#...#.#...#.#.....#.#
###.#######.###.###.#
#.#.#.#.#.#...#.#...#
#.#.#.#.#.#.#.#.#.#.#
#.....#.....#.#.#.#.#
###################.."""
def saludar():
nombreJugador = str(input("Cual es tu nombre? "))
print(f"!Hola¡ {nombreJugador}... Bienvenido al Juego del Laberinto!!!")
saludar()
def convertir_matriz(laberinto):
filas = laberinto.split('\n ')
matriz = [list(fila) for fila in filas]
return matriz
mapa = convertir_matriz(laberinto)
punto_inicial = (0, 0)
punto_final = (len(mapa)-1, len(mapa[0])-1)
def mapa_visual(mapa):
clear_terminal()
for fila in mapa:
print(''.join(fila))
def clear_terminal():
os.system('cls' if os.name == 'nt' else 'clear')
def main_loop(mapa: List[List[str]], punto_inicial: Tuple[int, int], punto_final: Tuple[int, int]):
eje_x, eje_y = punto_inicial
def mostrar_mapa():
mapa[eje_x][eje_y] = 'P'
mapa_visual(mapa)
mostrar_mapa()
while (eje_x, eje_y) != punto_final:
pressed_key = readchar.readkey()
nuevo_eje_x, nuevo_eje_y = eje_x, eje_y
if pressed_key == key.UP and eje_x > 0 and mapa[eje_x - 1][eje_y] != '#':
nuevo_eje_x -= 1
elif pressed_key == key.DOWN and eje_x < len(mapa) -1 and mapa[eje_x + 1][eje_y] != '#':
nuevo_eje_x += 1
elif pressed_key == key.LEFT and eje_y > 0 and mapa[eje_x][eje_y - 1] != '#':
nuevo_eje_y -= 1
elif pressed_key == key.RIGHT and eje_y < len(mapa[0]) -1 and mapa[eje_x][eje_y + 1] != '#':
nuevo_eje_y += 1
mapa[eje_x][eje_y] = '.'
eje_x, eje_y = nuevo_eje_x, nuevo_eje_y
mostrar_mapa()
main_loop(mapa, punto_inicial, punto_final)
print("Fin del Juego!!")
print(f"Lo lograste!! Amigo, \nFelicidades eres el Ganador")