59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
![]() |
#pygame - biblioteka do symulacji graficznych
|
||
|
import pygame
|
||
|
#system - klasy związane z pygame
|
||
|
#minesweeper - klasy związane z samym saperem
|
||
|
from classes import system, minesweeper
|
||
|
|
||
|
#ustalenie wielkości pojedyńczych kawałków mapy, oraz wielkości mapy
|
||
|
TILE_SIZE = 64
|
||
|
TILES_X = 16
|
||
|
TILES_Y = 10
|
||
|
|
||
|
def main():
|
||
|
#utworzenie okna do gry
|
||
|
window = system.Window(TILE_SIZE*TILES_X, TILE_SIZE*TILES_Y, "Intelligent Minesweeper", "icon.png")
|
||
|
|
||
|
#utworzenie objektu mapy, wygenerowanie jej i narysowanie na ekranie
|
||
|
map = minesweeper.Map(window, TILE_SIZE, TILES_X, TILES_Y)
|
||
|
map.generate()
|
||
|
map.draw_tiles()
|
||
|
|
||
|
#główna pętla
|
||
|
game_loop = True
|
||
|
clock = pygame.time.Clock()
|
||
|
while game_loop:
|
||
|
#ustalenie FPS
|
||
|
clock.tick(60)
|
||
|
|
||
|
#sprawdzanie różnych interakcji użytkownika
|
||
|
for event in pygame.event.get():
|
||
|
if event.type == pygame.QUIT:
|
||
|
game_loop = False
|
||
|
pygame.quit()
|
||
|
|
||
|
#sterowanie
|
||
|
keys = pygame.key.get_pressed()
|
||
|
not_moving = map.minesweeper.offset_x==0 and map.minesweeper.offset_y==0
|
||
|
if keys[pygame.K_DOWN] and not_moving:
|
||
|
map.minesweeper.move(0)
|
||
|
elif keys[pygame.K_UP] and not_moving:
|
||
|
map.minesweeper.move(1)
|
||
|
elif keys[pygame.K_LEFT] and not_moving:
|
||
|
map.minesweeper.move(2)
|
||
|
elif keys[pygame.K_RIGHT] and not_moving:
|
||
|
map.minesweeper.move(3)
|
||
|
|
||
|
|
||
|
|
||
|
#narysowanie terenu i obiektów
|
||
|
map.draw_tiles()
|
||
|
map.draw_objects()
|
||
|
|
||
|
#odświeżenie ekranu
|
||
|
pygame.display.update()
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|