2022-04-16 00:11:24 +02:00
|
|
|
# pygame - biblioteka do symulacji graficznych
|
2022-03-09 01:36:46 +01:00
|
|
|
import pygame
|
2022-04-16 00:11:24 +02:00
|
|
|
# system - klasy związane z pygame
|
|
|
|
# minesweeper - klasy związane z samym saperem
|
|
|
|
# ai - klasa wykonująca ruchy sapera
|
2022-04-07 05:33:10 +02:00
|
|
|
from classes import system, minesweeper, ai
|
2022-03-09 01:36:46 +01:00
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
# ustalenie wielkości pojedyńczych kawałków mapy, oraz wielkości mapy
|
2022-03-09 01:36:46 +01:00
|
|
|
TILE_SIZE = 64
|
2022-03-24 17:45:52 +01:00
|
|
|
TILES_X = int(12)
|
|
|
|
TILES_Y = int(10)
|
2022-03-09 01:36:46 +01:00
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
# wł/wył muzyki
|
|
|
|
MUSIC = True
|
2022-03-10 00:13:14 +01:00
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
# ustalenie FPS
|
2022-03-09 11:08:09 +01:00
|
|
|
FPS = 60
|
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
|
2022-03-09 01:36:46 +01:00
|
|
|
def main():
|
2022-03-10 00:13:14 +01:00
|
|
|
if MUSIC:
|
|
|
|
pygame.mixer.init()
|
|
|
|
pygame.mixer.Channel(0).play(pygame.mixer.Sound("assets/music.ogg"), -1)
|
2022-04-07 00:55:36 +02:00
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
# 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
|
2022-03-09 01:36:46 +01:00
|
|
|
map = minesweeper.Map(window, TILE_SIZE, TILES_X, TILES_Y)
|
|
|
|
map.generate()
|
|
|
|
map.draw_tiles()
|
2022-04-07 00:55:36 +02:00
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
# utworzenie sapera
|
|
|
|
saper = minesweeper.Minesweeper(0, 0, TILE_SIZE)
|
|
|
|
|
|
|
|
# pierwszy render
|
2022-04-07 18:27:35 +02:00
|
|
|
map.draw_tiles()
|
|
|
|
map.draw_objects()
|
|
|
|
saper.draw(window.window, 0.1)
|
|
|
|
pygame.display.update()
|
2022-04-07 00:55:36 +02:00
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
# utworzenie objektu klasy AI
|
2022-03-10 00:13:14 +01:00
|
|
|
AI = ai.AI(window, map, saper)
|
2022-04-16 00:11:24 +02:00
|
|
|
# wykonanie funkcji ready() AI
|
2022-03-10 00:13:14 +01:00
|
|
|
AI.ready()
|
2022-04-16 00:11:24 +02:00
|
|
|
|
|
|
|
# główna pętla
|
2022-03-09 01:36:46 +01:00
|
|
|
game_loop = True
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
while game_loop:
|
2022-04-16 00:11:24 +02:00
|
|
|
# wdrożenie FPS, delta - czas od ostatniej klatki
|
2022-03-09 11:08:09 +01:00
|
|
|
delta = clock.tick(FPS)
|
2022-04-16 00:11:24 +02:00
|
|
|
|
|
|
|
# wykonanie funkcji update() AI
|
2022-04-07 00:55:36 +02:00
|
|
|
AI.updateFPS()
|
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
if saper.offset_x == 0 and saper.offset_y == 0:
|
2022-04-07 00:55:36 +02:00
|
|
|
AI.updateTile()
|
2022-04-16 00:11:24 +02:00
|
|
|
|
|
|
|
# narysowanie terenu i obiektów
|
2022-03-09 01:36:46 +01:00
|
|
|
map.draw_tiles()
|
2022-03-09 23:37:42 +01:00
|
|
|
map.draw_objects()
|
2022-03-24 11:28:11 +01:00
|
|
|
saper.draw(window.window, delta)
|
2022-04-07 00:55:36 +02:00
|
|
|
|
2022-04-16 00:11:24 +02:00
|
|
|
# odświeżenie ekranu
|
2022-03-09 01:36:46 +01:00
|
|
|
pygame.display.update()
|
2022-04-16 00:11:24 +02:00
|
|
|
|
|
|
|
# sprawdzanie różnych interakcji użytkownika
|
2022-03-09 11:08:09 +01:00
|
|
|
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__":
|
2022-04-16 00:11:24 +02:00
|
|
|
main()
|