-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (37 loc) · 1.42 KB
/
main.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
import pygame
import sys
from objects import draw
from objects import utils
# pylint: disable=no-member
mapsize = (32, 32)
cellmap = utils.getCellMap(mapsize[0], mapsize[1], 120)
screen = pygame.display.set_mode((mapsize[0] * 20, mapsize[1] * 20))
pygame.display.set_caption('Minesweep')
pygame.init()
draw.background(screen)
for i in range(mapsize[0]):
for j in range(mapsize[1]):
draw.drawCell(screen, i, j, 10, cellmap[i][j].getMineCount())
pygame.display.update()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
mousex = event.pos[0] // 20
mousey = event.pos[1] // 20
if event.button == 1: # 좌클릭
if cellmap[mousex][mousey].isMine:
run = False
continue
for p in utils.clickCellMap(cellmap, mousex, mousey, mapsize[0], mapsize[1]):
draw.drawCell(screen, p[0], p[1], 10, cellmap[p[0]][p[1]].getMineCount())
elif event.button == 3: # 우클릭
if cellmap[mousex][mousey].isEnable:
continue
cellmap[mousex][mousey].isFlag = not cellmap[mousex][mousey].isFlag
draw.drawCell(screen, mousex, mousey, 10, cellmap[mousex][mousey].getMineCount())
pygame.display.update()
if event.type == pygame.QUIT:
run = False
pygame.quit()
sys.exit()