Skip to content

Commit df9e60a

Browse files
committed
optimisation
1 parent 1f2f138 commit df9e60a

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

python/Maze.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
colorTrB = (255, 0, 0)
4444
dX = {'N':0,'S':0,'E':1,'O':-1}
4545
dY = {'N':-1,'S':1,'E':0,'O':0}
46+
colorFond = (255,255,255)
4647

4748
# Fonction qui transforme un labyrinthe en une chaine de caractère pour le sauvegarder
4849

@@ -282,7 +283,7 @@ def move(way,liste):
282283

283284
# On définit le taux de rafraichissement de l'affichage sur 60 Hz et on remplit le fond d'une couleur blanche
284285
clock.tick(60)
285-
window.fill((255,255,255))
286+
window.fill(colorFond)
286287

287288
# De base, on se trouve sur le menu avec deux choix : Jouer un nouveau niveau ou rejouer un ancien pour battre son score
288289

@@ -367,8 +368,7 @@ def move(way,liste):
367368
for y in range(len(liste)): # On actualise l'affichage du labyrinthe
368369
for x in range(len(liste[y])):
369370
if liste[y][x] == '0':
370-
rect = pygame.Rect(x*10, y*10, 10, 10)
371-
pygame.draw.rect(window, (0,0,0), rect)
371+
continue
372372

373373
elif liste[y][x] == '1' or (liste[y][x] == '4' and tracer == False):
374374
rect = pygame.Rect(x*10, y*10, 10, 10)
@@ -389,20 +389,20 @@ def move(way,liste):
389389
pygame.draw.rect(window, (128,0,128), rect)
390390

391391
elif liste[y][x] == '5':
392-
rect = pygame.Rect(x*10, y*10+8, 10, 2)
393-
pygame.draw.rect(window, (0,0,0), rect)
392+
rect = pygame.Rect(x*10, y*10, 10, 8)
393+
pygame.draw.rect(window, (255,255,255), rect)
394394

395395
elif liste[y][x] == '6':
396-
rect = pygame.Rect(x*10, y*10, 10, 2)
397-
pygame.draw.rect(window, (0,0,0), rect)
396+
rect = pygame.Rect(x*10, y*10+2, 10, 8)
397+
pygame.draw.rect(window, (255,255,255), rect)
398398

399399
elif liste[y][x] == '7':
400-
rect = pygame.Rect(x*10+8, y*10, 2, 10)
401-
pygame.draw.rect(window, (0,0,0), rect)
400+
rect = pygame.Rect(x*10, y*10, 8, 10)
401+
pygame.draw.rect(window, (255,255,255), rect)
402402

403403
elif liste[y][x] == '8':
404-
rect = pygame.Rect(x*10, y*10, 2, 10)
405-
pygame.draw.rect(window, (0,0,0), rect)
404+
rect = pygame.Rect(x*10+2, y*10, 8, 10)
405+
pygame.draw.rect(window, (255,255,255), rect)
406406

407407
elif liste[y][x] == '9':
408408
if difficult != 3:
@@ -451,8 +451,13 @@ def move(way,liste):
451451
delay += 1/60
452452
if delay > 1.5:
453453
if regenonce == True:
454-
gen_new_maze( int((xWindow-10)/20), int((yWindow-10)/20) )
455-
buff = liste
454+
if difficult == 3:
455+
gen_new_maze(60,30)
456+
update_size_screen(10,10)
457+
buff = liste.copy()
458+
liste, playerloc = reduce_maze(buff)
459+
else:
460+
gen_new_maze( int((xWindow-10)/20), int((yWindow-10)/20) )
456461
t0 = time.monotonic()
457462
regenonce = False
458463
regenonce = True
@@ -534,6 +539,7 @@ def move(way,liste):
534539
if event.key == K_b: # Touche B -> Touche Retour
535540
play, replay, settings, finish, tracer = [False] * 5
536541
update_size_screen(25,25)
542+
colorFond = (255,255,255)
537543

538544

539545
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # On gère les actions avec la souris
@@ -555,6 +561,7 @@ def move(way,liste):
555561
play = True
556562
settings = False
557563
nametxt = ''
564+
colorFond = (0,0,0)
558565

559566
if buttonSwitchR.collidepoint(mouse_pos):
560567
set_difficult(1)

0 commit comments

Comments
 (0)