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
|
2022-03-10 00:13:14 +01:00
|
|
|
#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
|
|
|
|
|
|
|
#ustalenie wielkości pojedyńczych kawałków mapy, oraz wielkości mapy
|
|
|
|
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-03-10 00:13:14 +01:00
|
|
|
#wł/wył muzyki
|
2022-04-07 00:55:36 +02:00
|
|
|
MUSIC=False
|
2022-03-10 00:13:14 +01:00
|
|
|
|
2022-03-09 11:08:09 +01:00
|
|
|
#ustalenie FPS
|
|
|
|
FPS = 60
|
|
|
|
|
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-03-09 01:36:46 +01:00
|
|
|
#utworzenie okna do gry
|
|
|
|
window = system.Window(TILE_SIZE*TILES_X, TILE_SIZE*TILES_Y, "Intelligent Minesweeper", "icon.png")
|
|
|
|
|
2022-04-07 00:55:36 +02:00
|
|
|
#utworzenie ekranu pauzy
|
|
|
|
pause_menu = pygame.Surface((TILE_SIZE*TILES_X, TILE_SIZE*TILES_Y))
|
|
|
|
pause_menu.set_alpha(128)
|
|
|
|
pause_menu.fill((0,0,0))
|
|
|
|
|
2022-03-09 01:36:46 +01:00
|
|
|
#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-04-07 00:55:36 +02:00
|
|
|
|
|
|
|
|
2022-03-10 00:13:14 +01:00
|
|
|
#utworzenie objektu klasy AI
|
|
|
|
AI = ai.AI(window, map, saper)
|
|
|
|
#wykonanie funkcji ready() AI
|
|
|
|
AI.ready()
|
|
|
|
|
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
|
|
|
|
2022-03-10 00:13:14 +01:00
|
|
|
#wykonanie funkcji update() AI
|
2022-04-07 00:55:36 +02:00
|
|
|
AI.updateFPS()
|
|
|
|
|
|
|
|
if saper.offset_x==0 and saper.offset_y==0:
|
|
|
|
AI.updateTile()
|
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()
|
2022-03-24 11:28:11 +01:00
|
|
|
saper.draw(window.window, delta)
|
2022-03-09 01:36:46 +01:00
|
|
|
|
2022-04-07 00:55:36 +02:00
|
|
|
#pauza
|
|
|
|
if window.paused:
|
|
|
|
window.window.blit(pause_menu, (0,0))
|
|
|
|
|
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()
|