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()
|
2022-03-09 23:37:42 +01:00
|
|
|
|
|
|
|
#utworzenie sapera
|
|
|
|
saper = minesweeper.Minesweeper(0,0, TILE_SIZE)
|
2022-03-09 01:36:46 +01:00
|
|
|
|
|
|
|
#główna pętla
|
|
|
|
game_loop = True
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
while game_loop:
|
2022-03-09 23:37:42 +01:00
|
|
|
#wdrożenie FPS, delta - czas od ostatniej klatki
|
2022-03-09 11:08:09 +01:00
|
|
|
delta = clock.tick(FPS)
|
2022-03-09 01:36:46 +01:00
|
|
|
|
|
|
|
#sterowanie
|
|
|
|
keys = pygame.key.get_pressed()
|
2022-03-09 23:37:42 +01:00
|
|
|
if keys[pygame.K_DOWN]:
|
|
|
|
saper.move(map, 0)
|
|
|
|
elif keys[pygame.K_UP]:
|
|
|
|
saper.move(map, 180)
|
|
|
|
elif keys[pygame.K_LEFT]:
|
|
|
|
saper.move(map, 270)
|
|
|
|
elif keys[pygame.K_RIGHT]:
|
|
|
|
saper.move(map, 90)
|
2022-03-09 01:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
#narysowanie terenu i obiektów
|
|
|
|
map.draw_tiles()
|
2022-03-09 23:37:42 +01:00
|
|
|
map.draw_objects()
|
|
|
|
saper.draw(window.window, delta, map)
|
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()
|