-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (51 loc) · 1.8 KB
/
main.py
File metadata and controls
66 lines (51 loc) · 1.8 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
from board import Board
from button import Button
import pygame
size = width, height = 800, 900
board = Board(position=(100,150),size=600,padding=20) # default: english version
button = Button('New game', (250,785),(300,80))
button.add_option('English version', board.reset_board,'english')
button.add_option('French version', board.reset_board,'french')
screen = pygame.display.set_mode(size)
pygame.display.set_caption('Peg Solitaire')
clock = pygame.time.Clock()
pygame.font.init()
font = pygame.font.SysFont('Arial',80)
button_font = pygame.font.SysFont('Arial',30)
text = ''
text_pos = (width//2,75)
running = True
game_status = 0
# 0 -> playing
# -1 -> game over (lost)
# 1 -> won
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if not button.is_open():
if event.button == 1:
board.pick(event.pos)
else:
button.click(event.pos)
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
board.release(event.pos)
game_status = board.check_game_status()
if game_status == 1:
text = 'YOU WIN'
elif game_status == -1:
text = 'GAME OVER'
else:
text = ''
screen.fill([10]*3)
text_render = font.render(text, False, (255,255,255))
dx, dy = text_render.get_rect().width//2, text_render.get_rect().height//2
board.show(screen, pygame.mouse.get_pos(),game_status)
screen.blit(text_render, (text_pos[0]-dx, text_pos[1]-dy))
button.update(pygame.mouse.get_pos())
button.show(screen,button_font)
pygame.display.update()
clock.tick(60)
pygame.quit()