-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.py
More file actions
69 lines (58 loc) · 1.79 KB
/
Copy pathGame.py
File metadata and controls
69 lines (58 loc) · 1.79 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
import pygame as pg
from Checkboard import Checkboard
c = Checkboard()
class Game:
def __init__(self):
"""
set l'état de game a True
"""
self.__game = True
@property
def game(self):
"""
:return: renvoie l'état de la variable game
"""
return self.__game
def finished(self):
"""
:return: met l'état de la variable game a False
"""
self.__game = False
def run(self):
"""
: return : lance tout le programme principal
"""
c.drawboard()
clock = pg.time.Clock()
img = c.loadpawns()
clicks = []
while self.game:
for event in pg.event.get():
if event.type == pg.QUIT:
self.sauvergarde()
self.finished()
if event.type == pg.MOUSEBUTTONDOWN:
click = pg.mouse.get_pos()
row = click[0] // c.size
col = click[1] // c.size
carreselectionne = (row, col)
clicks.append(carreselectionne)
if len(clicks) == 1:
c.colorizesquare()
if len(clicks) == 2:
c.modifyboard(clicks[0], clicks[1])
clicks = []
c.drawboard()
c.drawstatus(img)
pg.display.flip()
clock.tick(15)
def sauvergarde(self):
"""
:return : souvegarde le score dans un fichier texte à part
"""
file = open("score.txt", "w")
w = str(c.score["blancs"])
b = str(c.score["noirs"])
file.write("score des blancs : " + w + "\n")
file.write("score des noirs: " + b)
file.close()