-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (39 loc) · 1.63 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
import pygame
import sys
from core import Field_GameObject, Menu_GameObject
class Main(object):
""" Class to initialize the main game. """
def __init__(self, size: tuple[int, int]) -> None:
""" Initialization function. """
pygame.init()
self._surface = pygame.display.set_mode(size)
self._cards = Field_GameObject(".\\assets")
self._menu = Menu_GameObject(0, 656, self._cards)
self._moving = []
pygame.display.set_caption("Solitaire")
pygame.display.set_icon(pygame.image.load(".\\assets\\icon.png"))
def exec(self):
""" Renders in-game objects. """
self._cards.render(self._surface)
while True:
for event in pygame.event.get():
match event.type:
case pygame.QUIT:
sys.exit(pygame.quit())
case pygame.MOUSEBUTTONDOWN:
self._cards.new_card()
self._menu.check_buttons()
self._moving = self._cards.start_cards_move()
case pygame.MOUSEBUTTONUP:
self._moving = []
self._cards.stop_cards_move()
case pygame.MOUSEMOTION:
for card in self._moving:
card.move_ip(*event.rel)
self._menu.render(self._surface)
self._cards.render(self._surface)
pygame.display.update()
pygame.time.delay(5)
if __name__ == "__main__":
main = Main((1280, 720))
main.exec()