Projekt_AI-Automatyczny_saper/Engine/Game.py

71 lines
1.9 KiB
Python
Raw Normal View History

2021-03-27 22:07:55 +01:00
import random
2021-03-13 21:16:35 +01:00
import pygame
2021-03-27 22:07:55 +01:00
from Constants import SQUARE_SIZE, GREEN, RIGHT, LEFT, UP, DOWN, COLS, ROWS, DECOY, ATOMIC_BOMB, CHEMICAL_BOMB, CLAYMORE, LAND_MINE
2021-03-16 18:53:26 +01:00
from Engine.Board import Board
from Engine.Agent import Agent
2021-03-27 22:07:55 +01:00
from Engine.BombFactory import BombFactory
from Engine.Point import Point
2021-03-13 21:16:35 +01:00
class Game:
def __init__(self, win):
2021-03-27 22:07:55 +01:00
self._init(win)
2021-03-13 21:16:35 +01:00
self.win = win
2021-03-27 22:07:55 +01:00
self.randomizeObject()
pygame.display.update()
2021-03-13 21:16:35 +01:00
2021-03-27 22:07:55 +01:00
def _init(self,win):
self.board = Board(win)
self.agent = Agent(Point(0,0))
2021-03-13 21:16:35 +01:00
self.turn = GREEN
2021-03-16 18:53:26 +01:00
self.goingDown = True
2021-03-13 21:16:35 +01:00
def update(self):
2021-03-15 19:58:20 +01:00
self.board.drawSquares(self.win)
2021-03-27 22:07:55 +01:00
self.board.drawBombs()
2021-03-16 18:53:26 +01:00
self.board.drawAgent(self.win,self.agent)
2021-03-13 21:16:35 +01:00
pygame.display.update()
2021-03-16 18:53:26 +01:00
def move(self):
2021-03-27 22:07:55 +01:00
point = self.agent.getPoint()
2021-03-16 18:53:26 +01:00
if self.goingDown:
2021-03-27 22:07:55 +01:00
if point.getY() + 1 < ROWS:
point.y += 1
elif point.getX() + 1 < COLS:
point.x += 1
2021-03-16 18:53:26 +01:00
self.goingDown = not self.goingDown
else:
2021-03-27 22:07:55 +01:00
if point.getY() - 1 >= 0:
point.y -= 1
elif point.getX() + 1 < COLS:
point.x += 1
2021-03-16 18:53:26 +01:00
self.goingDown = not self.goingDown
2021-03-27 22:07:55 +01:00
self.agent.point = point
def randomizeObject(self):
for x in range(10):
point = Point(random.randint(0,7), random.randint(0,7))
if point not in self.board.bombMap:
bomb = self.pickBomb(random.randint(0, 4))
self.board.bombMap[point] = bomb
2021-03-15 19:04:51 +01:00
2021-03-27 22:07:55 +01:00
def pickBomb(self, rand):
if(rand == 0):
return BombFactory.create(DECOY)
elif(rand == 1):
return BombFactory.create(CHEMICAL_BOMB)
elif(rand == 2):
return BombFactory.create(ATOMIC_BOMB)
elif(rand == 3):
return BombFactory.create(CLAYMORE)
elif(rand == 4):
return BombFactory.create(LAND_MINE)
2021-03-15 19:04:51 +01:00
2021-03-15 19:58:20 +01:00