51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
![]() |
import pygame
|
||
|
from classes import minesweeper, system
|
||
|
from random import randrange
|
||
|
|
||
|
class AI:
|
||
|
window:system.Window
|
||
|
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, map, saper):
|
||
|
self.window = window
|
||
|
self.map = map
|
||
|
self.saper = saper
|
||
|
|
||
|
#co ma zrobić tylko na początku
|
||
|
def ready(self):
|
||
|
pass
|
||
|
|
||
|
#co ma robić przy każdym FPS'ie
|
||
|
def update(self):
|
||
|
if self.user_controlled:
|
||
|
self.minesweeper_controls()
|
||
|
return
|
||
|
|
||
|
self.chaos_controls()
|
||
|
|
||
|
|
||
|
def minesweeper_controls(self):
|
||
|
keys = pygame.key.get_pressed()
|
||
|
if keys[pygame.K_DOWN]:
|
||
|
self.saper.move(self.map, 0)
|
||
|
elif keys[pygame.K_UP]:
|
||
|
self.saper.move(self.map, 180)
|
||
|
elif keys[pygame.K_LEFT]:
|
||
|
self.saper.move(self.map, 270)
|
||
|
elif keys[pygame.K_RIGHT]:
|
||
|
self.saper.move(self.map, 90)
|
||
|
|
||
|
def chaos_controls(self):
|
||
|
dir = randrange(4)
|
||
|
if dir==0:
|
||
|
self.saper.move(self.map, 0)
|
||
|
elif dir==1:
|
||
|
self.saper.move(self.map, 180)
|
||
|
elif dir==2:
|
||
|
self.saper.move(self.map, 270)
|
||
|
elif dir==3:
|
||
|
self.saper.move(self.map, 90)
|