-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab.py
More file actions
71 lines (61 loc) · 2.24 KB
/
Copy pathlab.py
File metadata and controls
71 lines (61 loc) · 2.24 KB
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
# Modulo que prove o labirinto
import pygame, support
from pygame.locals import *
from pygame.sprite import *
# Objetos presentes no labirinto
class Porta:
def __init__(self, x, y):
self.image = support.carrega_imagem('porta1.png')
self.rect = Rect(x, y, 40, 40)
class Saida:
def __init__(self, x, y):
Sprite.__init__(self)
self.image = support.carrega_imagem('porta2.png')
self.rect = self.image.get_rect(center=(x, y))
class Parede(Sprite):
def __init__(self, x, y, nivel):
Sprite.__init__(self)
self.image = support.carrega_imagem('parede%d.png' % nivel)
self.rect = self.image.get_rect(center=(x, y))
class Objeto(Sprite):
def __init__(self, x, y, nivel):
Sprite.__init__(self)
self.image = support.carrega_imagem('objeto%d.png' % nivel)
self.rect = Rect(x, y, 20, 20)
class Labirinto(Sprite):
# Inicializar componentes
def __init__(self, nivel):
self.porta = support.carrega_imagem('porta1.png')
self.saida = support.carrega_imagem('porta2.png')
self.parede = support.carrega_imagem('parede%d.png' % nivel)
self.objeto = support.carrega_imagem('objeto%d.png' % nivel)
# Desenhar labirinto
def constroi(self, tela, nivel):
labirinto = support.carrega_labirinto(nivel)
y = 84
# Cada linha
for linha in labirinto:
x = 112
# Cada coluna
for letra in linha:
if letra == "#":
tela.blit(self.parede, (x, y))
elif letra == "s":
tela.blit(self.porta, (x, y))
elif letra == "f":
tela.blit(self.saida, (x, y))
x += 40
y += 40
# Cria a lista de objetos contidos no labirinto
def cria_objetos(self, paredes, objetos, nivel):
labirinto = support.carrega_labirinto(nivel)
y = 84
for linha in labirinto:
x = 112
for letra in linha:
if letra == '#':
paredes.add(Parede(x, y, nivel))
elif letra == 'o':
objetos.add(Objeto(x, y, nivel))
x += 40
y += 40