52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import pygame
|
|
from classes import minesweeper, system
|
|
from random import randrange
|
|
|
|
class AI:
|
|
window:system.Window
|
|
current_map:minesweeper.Map
|
|
saper:minesweeper.Minesweeper
|
|
|
|
#jak True to można się poruszać strzałkami, jak False sam się porusza
|
|
user_controlled=False
|
|
|
|
def __init__(self, window, current_map, saper):
|
|
self.window = window
|
|
self.current_map = current_map
|
|
self.saper = saper
|
|
|
|
#co ma zrobić tylko na początku
|
|
def ready(self):
|
|
self.saper.set_map(self.current_map)
|
|
|
|
#co ma robić przy każdym FPS'ie
|
|
def update(self):
|
|
if self.user_controlled:
|
|
self.minesweeper_controls()
|
|
return
|
|
|
|
self.chaos_controls()
|
|
#TU pisać resztę
|
|
|
|
|
|
def minesweeper_controls(self):
|
|
keys = pygame.key.get_pressed()
|
|
if keys[pygame.K_DOWN]:
|
|
self.saper.move(0)
|
|
elif keys[pygame.K_UP]:
|
|
self.saper.move(180)
|
|
elif keys[pygame.K_LEFT]:
|
|
self.saper.move(270)
|
|
elif keys[pygame.K_RIGHT]:
|
|
self.saper.move(90)
|
|
|
|
def chaos_controls(self):
|
|
dir = randrange(4)
|
|
if dir==0:
|
|
self.saper.move(0)
|
|
elif dir==1:
|
|
self.saper.move(180)
|
|
elif dir==2:
|
|
self.saper.move(270)
|
|
elif dir==3:
|
|
self.saper.move(90) |