2022-04-16 00:11:24 +02:00
|
|
|
# pygame - biblioteka do symulacji graficznych
|
2022-05-19 01:16:58 +02:00
|
|
|
from multiprocessing import freeze_support
|
2022-05-19 01:23:51 +02:00
|
|
|
import os
|
2022-05-19 10:42:46 +02:00
|
|
|
|
2022-05-19 01:23:51 +02:00
|
|
|
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
|
2022-03-09 01:36:46 +01:00
|
|
|
import pygame
|
2022-05-19 11:45:35 +02:00
|
|
|
from chefboost import Chefboost as chef
|
|
|
|
import pandas as pd
|
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-05-19 01:16:58 +02:00
|
|
|
from classes import system, minesweeper, ai, decisionTrees
|
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-06-09 17:14:14 +02:00
|
|
|
TILE_SIZE = 72
|
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
|
2022-09-08 00:47:05 +02:00
|
|
|
MUSIC = False
|
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-05-19 10:42:46 +02:00
|
|
|
# włączenie tekstu
|
2022-05-05 18:35:07 +02:00
|
|
|
pygame.font.init()
|
2022-04-16 00:11:24 +02:00
|
|
|
|
2022-05-19 10:42:46 +02:00
|
|
|
|
2022-03-09 01:36:46 +01:00
|
|
|
def main():
|
2022-05-19 11:45:35 +02:00
|
|
|
|
|
|
|
|
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()
|
2022-05-19 12:26:48 +02:00
|
|
|
|
|
|
|
# create decision tree
|
|
|
|
tree = decisionTrees.DecisionTrees()
|
|
|
|
model = tree.create_model()
|
|
|
|
|
2022-03-09 01:36:46 +01:00
|
|
|
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-05-19 12:26:48 +02:00
|
|
|
AI.updateTile(model)
|
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-05-05 18:35:07 +02:00
|
|
|
elif event.type in [i.timer_event for i in map.mines]:
|
|
|
|
for i in map.mines:
|
2022-05-19 10:42:46 +02:00
|
|
|
i.explosion_timer -= 1
|
2022-03-09 01:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-05-19 01:16:58 +02:00
|
|
|
freeze_support()
|
2022-04-16 00:11:24 +02:00
|
|
|
main()
|