This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
102 lines (85 loc) · 2.4 KB
/
gui.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Interface graphique pygame du jeu
import os
import sys
import time
import pygame
from pygame.locals import *
from Serpent import *
TAILLE_CASE = 20
def pos(x): return x[1] * TAILLE_CASE, x[0] * TAILLE_CASE
if not pygame.font:
print('Attention, polices désactivées')
if not pygame.mixer:
print('Attention, son désactivé')
FOND = 255, 255, 255
pygame.init()
fenetre = pygame.display.set_mode(
(TAILLE_CASE * Plateau.TAILLE_MAX, TAILLE_CASE * Plateau.TAILLE_MAX))
fenetre.fill(FOND)
m = Plateau(4, 4)
# chargement des images
imgSerp = pygame.image.load("./img/corps.png").convert_alpha()
imgMur = pygame.image.load("./img/murs.png").convert_alpha()
imgPomme = pygame.image.load("./img/pommes.png").convert_alpha()
imgPoire = pygame.image.load("./img/poire.png").convert_alpha()
def afficher():
for Scoord in m.s.coords:
posxy = pos(Scoord)
fenetre.blit(imgSerp, posxy)
for Mcoord in m.murs:
posxy = pos(Mcoord)
fenetre.blit(imgMur, posxy)
for Pcoord in m.pommes:
posxy = pos(Pcoord)
fenetre.blit(imgPomme, posxy)
for Pcoord in m.poires:
posxy = pos(Pcoord)
fenetre.blit(imgPoire, posxy)
continuer = 1
# Jeux
while continuer:
fenetre.fill(FOND)
direction = m.s.direction
# On parcours la liste de tous les événements reçus
for event in pygame.event.get():
if event.type == QUIT:
continuer = 0
break
if event.type == KEYDOWN:
if event.key == K_LEFT:
direction = Direction.OUEST
elif event.key == K_RIGHT:
direction = Direction.EST
elif event.key == K_UP:
direction = Direction.NORD
elif event.key == K_DOWN:
direction = Direction.SUD
if not continuer:
break
afficher()
time.sleep(m.s.vitesse)
m.s.direction = direction
m.s.avancer()
m.aManger()
pygame.display.flip()
if m.aPerdu():
continuer = 0
if m.aGagner():
continuer = 0
fin = 1
# animation de fin
while fin:
fenetre.fill(FOND)
afficher()
time.sleep(m.s.vitesse)
m.s.reduire()
pygame.display.flip()
# On parcours la liste de tous les événements reçus
for event in pygame.event.get():
if event.type == QUIT:
fin = 0
break
# message final
print(m.message)