Projekt_AI-Automatyczny_saper/Engine/Board.py

41 lines
1.4 KiB
Python
Raw Normal View History

2021-03-13 21:16:35 +01:00
import pygame
2021-03-15 19:58:20 +01:00
from Constants import ROWS, COLS, SQUARE_SIZE, GREEN, BLACK, WIDTH
2021-03-30 23:10:20 +02:00
from Engine.Bomb import Bomb
2021-03-13 21:16:35 +01:00
class Board:
2021-03-16 18:53:26 +01:00
2021-03-27 22:07:55 +01:00
def __init__(self, win):
2021-03-13 21:16:35 +01:00
self.board = []
2021-03-27 22:07:55 +01:00
self.bombMap = {}
self.win = win
2021-03-13 21:16:35 +01:00
2021-03-15 19:58:20 +01:00
def drawSquares(self, win):
2021-03-13 21:16:35 +01:00
win.fill(GREEN)
for row in range(ROWS):
for col in range(COLS):
2021-03-30 21:01:54 +02:00
pygame.draw.rect(win, BLACK,
pygame.Rect(row * SQUARE_SIZE, col * SQUARE_SIZE, SQUARE_SIZE, SQUARE_SIZE), 2)
2021-03-15 19:58:20 +01:00
def drawAgent(self, win, agent):
2021-03-16 18:53:26 +01:00
rect = agent.image.get_rect()
2021-03-30 21:01:54 +02:00
rect.center = (agent.getPoint().getX() * SQUARE_SIZE + SQUARE_SIZE / 2,
agent.getPoint().getY() * SQUARE_SIZE + SQUARE_SIZE / 2 - 5)
2021-03-16 18:53:26 +01:00
win.blit(agent.image, rect)
2021-03-27 22:07:55 +01:00
def drawBombs(self):
for key in self.bombMap:
bomb = self.bombMap[key]
2021-03-30 21:01:54 +02:00
if not bomb.isDefused:
image = pygame.image.load('Engine/' + bomb.bombType + '.png')
image = pygame.transform.scale(image, (SQUARE_SIZE - 5, SQUARE_SIZE - 5))
rect = image.get_rect()
rect.center = (key.getX() * SQUARE_SIZE + SQUARE_SIZE / 2, key.getY() * SQUARE_SIZE + SQUARE_SIZE / 2)
self.win.blit(image, rect)
2021-03-30 23:10:20 +02:00
def getBomb(self, point):
if point in self.bombMap:
return self.bombMap[point]
return Bomb(0,0,"")