def nivel(grilla, accion=None): '''Recibe un nivel en forma de grilla (lista de listas), y dibuja en la ventana la representacion de esa grilla. ''' tamanio_x, tamanio_y = soko.dimensiones(grilla) for x in range(tamanio_x): for y in range(tamanio_y): px_x = (x * TAMANIO_CASILLA ) + 2 # Lo desplazo 2 pixeles, porque es lo que ocupan px_y = (y * TAMANIO_CASILLA) + 2 # los bordes de la ventana. gl.draw_image(IMG_SUELO, px_x, px_y) if soko.hay_jugador(grilla, x, y): gl.draw_image(IMG_JUGADOR.get(accion, "src/player_s.gif"), px_x, px_y) elif soko.hay_caja(grilla, x, y): gl.draw_image(IMG_CAJA, px_x, px_y) elif soko.hay_pared(grilla, x, y): gl.draw_image(IMG_PARED, px_x, px_y) if soko.hay_objetivo(grilla, x, y): gl.draw_image(IMG_OBJETIVO, px_x, px_y)
def dibujo_juego(grilla): '''Esta funcion recibe una grilla y dibuja el juego''' x_total, y_total = cargar_tamaño( grilla) #Tupla con el total de de px por pantalla x = 0 y = 0 casilleros_maximos_horizontales = y_total / PX_CELDA for fila in range(len(grilla)): for columna in range(int(casilleros_maximos_horizontales) + PX_CELDA): if columna < len(grilla[fila]): gamelib.draw_image('img/ground.gif', x_total, y_total) celda = grilla[fila][columna] if soko.hay_pared(grilla, columna, fila): gamelib.draw_image('img/wall.gif', x, y) elif soko.hay_jugador(grilla, columna, fila): gamelib.draw_image('img/player.gif', x, y) elif celda == " ": gamelib.draw_image('img/ground.gif', x, y) elif soko.hay_caja(grilla, columna, fila): gamelib.draw_image('img/box.gif', x, y) elif soko.hay_objetivo(grilla, columna, fila): gamelib.draw_image('img/goal.gif', x, y) else: gamelib.draw_image('img/ground.gif', x, y) x = x + PX_CELDA x = 0 y = y + PX_CELDA
def juego_mostrar(grilla): ''' Recibe por parámetro una lista de listas y dibuja en pantalla. ''' for f in range(len(grilla)): for c in range(len(grilla[0])): y = f * DIM_CELDA x = c * DIM_CELDA gamelib.draw_image('img/ground.gif', x, y) if soko.hay_pared(grilla, c, f): gamelib.draw_image('img/wall.gif', x, y) if soko.hay_jugador(grilla, c, f): gamelib.draw_image('img/player.gif', x, y) if soko.hay_caja(grilla, c, f): gamelib.draw_image('img/box.gif', x, y) if soko.hay_objetivo(grilla, c, f): gamelib.draw_image('img/goal.gif', x, y)
def verificar_estado(desc, grilla): x = None y = None try: w, h = soko.dimensiones(grilla) assert (w, h) == (len(desc[0]), len(desc)) for y in range(h): for x in range(w): c = desc[y][x] if c == '#': assert soko.hay_pared(grilla, x, y) assert not soko.hay_objetivo(grilla, x, y) assert not soko.hay_jugador(grilla, x, y) assert not soko.hay_caja(grilla, x, y) elif c == '.': assert not soko.hay_pared(grilla, x, y) assert soko.hay_objetivo(grilla, x, y) assert not soko.hay_jugador(grilla, x, y) assert not soko.hay_caja(grilla, x, y) elif c == '$': assert not soko.hay_pared(grilla, x, y) assert not soko.hay_objetivo(grilla, x, y) assert not soko.hay_jugador(grilla, x, y) assert soko.hay_caja(grilla, x, y) elif c == '@': assert not soko.hay_pared(grilla, x, y) assert not soko.hay_objetivo(grilla, x, y) assert soko.hay_jugador(grilla, x, y) assert not soko.hay_caja(grilla, x, y) elif c == '*': assert not soko.hay_pared(grilla, x, y) assert soko.hay_objetivo(grilla, x, y) assert not soko.hay_jugador(grilla, x, y) assert soko.hay_caja(grilla, x, y) elif c == '+': assert not soko.hay_pared(grilla, x, y) assert soko.hay_objetivo(grilla, x, y) assert soko.hay_jugador(grilla, x, y) assert not soko.hay_caja(grilla, x, y) except AssertionError as e: print('Estado esperado:') print('\n'.join(desc)) print() print('Estado actual:') pprint.pprint(grilla) print() if x is not None and y is not None: print(f'Error en columna = {x}, fila = {y}:') print() raise
def mostrar_interfaz(grilla): '''Muestra la interfaz a partir de la grilla, en su estado actual, dependiendo de su simbolo se mostrara en la interfaz el gif correspondiente''' columnas, filas = soko.dimensiones(grilla) for fila in range(filas): for columna in range(columnas): gamelib.draw_image('img/ground.gif', columna * PIXELES_GIF, fila * PIXELES_GIF) if soko.hay_caja(grilla, columna, fila): gamelib.draw_image('img/box.gif', columna * PIXELES_GIF, fila * PIXELES_GIF) if soko.hay_objetivo(grilla, columna, fila): gamelib.draw_image('img/goal.gif', columna * PIXELES_GIF, fila * PIXELES_GIF) if soko.hay_jugador(grilla, columna, fila): gamelib.draw_image('img/player.gif', columna * PIXELES_GIF, fila * PIXELES_GIF) if soko.hay_pared(grilla, columna, fila): gamelib.draw_image('img/wall.gif', columna * PIXELES_GIF, fila * PIXELES_GIF)