-
Notifications
You must be signed in to change notification settings - Fork 0
/
pymine.py
55 lines (50 loc) · 1.85 KB
/
pymine.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""PyMine
This is a minesweeper game, written in Python and with pygame."""
from sys import exit
import pygame
from pygame.locals import *
from lib.utility import MyMouse
from lib.minefield import Minefield
__filename__ = "pymine.py"
__title__ = 'PyMine'
__author__ = 'Zhao Xin (zhaoxin@imzhao.com)'
__copyright__ = 'Copyright 2013 Zhao Xin'
__licence__ = 'GPL'
__version__ = '0.6.0'
pygame.init()
clock = pygame.time.Clock()
pygame.display.set_caption("PyMine")
pymine_icon = pygame.image.load("resource/image/mine.png")
pygame.display.set_icon(pymine_icon)
mymouse = MyMouse('resource/image/shovel.png')
min_of_columns, max_of_columns = 10, 40
min_of_rows, max_of_rows = 10, 30
minefield = Minefield(min_of_columns, min_of_rows)
while True:
clock.tick(60)
minefield.render()
mymouse.render(minefield.screen)
pygame.display.flip()
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key in [K_r, K_a, K_d, K_w, K_s]:
if event.key == K_a:
minefield.number_of_columns = max(
min_of_columns, minefield.number_of_columns - 1)
elif event.key == K_d:
minefield.number_of_columns = min(
max_of_columns, minefield.number_of_columns + 1)
elif event.key == K_w:
minefield.number_of_rows = max(
min_of_rows, minefield.number_of_rows - 1)
elif event.key == K_s:
minefield.number_of_rows = min(
max_of_rows, minefield.number_of_rows + 1)
minefield.new()
elif event.type == MOUSEBUTTONDOWN:
minefield.click(event.pos, event.button)
elif event.type == pygame.QUIT:
pygame.quit()
exit(0)