2022-03-09 01:36:46 +01:00
|
|
|
#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
|
|
|
|
|
2022-03-09 11:08:09 +01:00
|
|
|
#ustalenie FPS
|
|
|
|
FPS = 60
|
|
|
|
|
2022-03-09 01:36:46 +01:00
|
|
|
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:
|
2022-03-09 11:08:09 +01:00
|
|
|
#ustalenie FPS, delta - czas od ostatniej klatki
|
|
|
|
delta = clock.tick(FPS)
|
2022-03-09 01:36:46 +01:00
|
|
|
|
|
|
|
#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()
|
2022-03-09 11:08:09 +01:00
|
|
|
map.draw_objects(delta)
|
2022-03-09 01:36:46 +01:00
|
|
|
|
|
|
|
#odświeżenie ekranu
|
|
|
|
pygame.display.update()
|
|
|
|
|
2022-03-09 11:08:09 +01:00
|
|
|
#sprawdzanie różnych interakcji użytkownika
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
game_loop = False
|
|
|
|
pygame.quit()
|
2022-03-09 01:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|