-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (56 loc) · 1.95 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
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
import pygame
from board import Board
from image_loader import load_image
def main():
pygame.init()
# Setting a game window with computer's screen size
screen_info = pygame.display.Info()
width, height = screen_info.current_w, screen_info.current_h
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Board dev')
# Making a board
board = Board(7, 7)
cell_size = 120
left = width // 2 - board.width * cell_size // 2
top = height // 2 - board.height * cell_size // 2
board.set_view(left, top, cell_size)
# Making a dig count
count = 5
# Sprites
all_sprites = pygame.sprite.Group()
cursor_image = load_image("cursor.png")
cursor = pygame.sprite.Sprite(all_sprites)
cursor.image = cursor_image
cursor.rect = cursor.image.get_rect()
pygame.mouse.set_visible(False)
# Game cycle
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEMOTION:
cursor.rect.topleft = event.pos
if event.type == pygame.MOUSEBUTTONDOWN:
if count:
board.get_click(event.pos)
count -= 1
screen.fill('#f4a460')
# Working with text
font = pygame.font.Font(None, 100)
if count:
count_label = font.render(str(count), True, 'white')
else:
count_label = font.render(str(count), True, 'red')
screen.blit(count_label, (20, 20))
if not count:
text = font.render("Game Over!", True, 'white')
screen.blit(text, (width // 2 - text.get_width() // 2, 1100))
board.render(screen)
# Cursor render
if pygame.mouse.get_focused():
all_sprites.draw(screen)
pygame.display.flip()
pygame.quit()
if __name__ == '__main__':
main()