diff --git a/Constants.py b/Constants.py index 1ea1895f..5f539860 100644 --- a/Constants.py +++ b/Constants.py @@ -8,4 +8,10 @@ BLACK = (0,0,0) UP = 'UP' DOWN = 'DOWN' LEFT = 'LEFT' -RIGHT = 'RIGHT' \ No newline at end of file +RIGHT = 'RIGHT' + +DECOY = 'Decoy' +ATOMIC_BOMB = 'Atomic Bomb' +CLAYMORE = 'Claymore' +CHEMICAL_BOMB = 'Chemical Bomb' +LAND_MINE = 'Land Mine' \ No newline at end of file diff --git a/Engine/Agent.py b/Engine/Agent.py index bf8bff11..8be23e1b 100644 --- a/Engine/Agent.py +++ b/Engine/Agent.py @@ -1,11 +1,13 @@ import pygame from Constants import ROWS, COLS, UP, LEFT, DOWN, RIGHT class Agent(object): - def __init__(self, y, x): - self.y = y - self.x = x + def __init__(self, point): + self.point = point self.image = pygame.image.load('Engine/agent.png') + def getPoint(self): + return self.point + # def ifNotOnEdge(self, destination): # if destination == UP: # if self.x - 1 <= 0: diff --git a/Engine/Atomic Bomb.png b/Engine/Atomic Bomb.png new file mode 100644 index 00000000..ba8d59af Binary files /dev/null and b/Engine/Atomic Bomb.png differ diff --git a/Engine/Board.py b/Engine/Board.py index 5c8b1ca6..ccf45f6b 100644 --- a/Engine/Board.py +++ b/Engine/Board.py @@ -4,8 +4,10 @@ from Constants import ROWS, COLS, SQUARE_SIZE, GREEN, BLACK, WIDTH class Board: - def __init__(self): + def __init__(self, win): self.board = [] + self.bombMap = {} + self.win = win def drawSquares(self, win): win.fill(GREEN) @@ -15,12 +17,14 @@ class Board: def drawAgent(self, win, agent): rect = agent.image.get_rect() - rect.center = (agent.x * SQUARE_SIZE + SQUARE_SIZE / 2, agent.y * SQUARE_SIZE + SQUARE_SIZE / 2 - 5) + rect.center = (agent.getPoint().getX() * SQUARE_SIZE + SQUARE_SIZE / 2, agent.getPoint().getY() * SQUARE_SIZE + SQUARE_SIZE / 2 - 5) win.blit(agent.image, rect) - def drawBombs(self,win, x, y): - image = pygame.image.load('Engine/bomb.png') - image = pygame.transform.scale(image, (SQUARE_SIZE, SQUARE_SIZE)) - rect = image.get_rect() - rect.center = (x * SQUARE_SIZE + SQUARE_SIZE/2 + 5, y * SQUARE_SIZE + SQUARE_SIZE/2 - 5) - win.blit(image, rect) + def drawBombs(self): + for key in self.bombMap: + bomb = self.bombMap[key] + 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) diff --git a/Engine/Bomb.py b/Engine/Bomb.py new file mode 100644 index 00000000..b4b3aeb6 --- /dev/null +++ b/Engine/Bomb.py @@ -0,0 +1,7 @@ +class Bomb: + + def __init__(self, detonationTime, defuseTime, bombType): + self.detonationTime = detonationTime + self.defuseTime = defuseTime + self.bombType = bombType + self.isDefused = False \ No newline at end of file diff --git a/Engine/BombFactory.py b/Engine/BombFactory.py new file mode 100644 index 00000000..5e03c862 --- /dev/null +++ b/Engine/BombFactory.py @@ -0,0 +1,17 @@ +from Constants import DECOY, ATOMIC_BOMB, CHEMICAL_BOMB, CLAYMORE, LAND_MINE +from Engine.Bomb import Bomb + +class BombFactory: + + @staticmethod + def create(bombType): + if bombType == DECOY: + return Bomb(float('inf'), float('inf'), DECOY) + elif bombType == ATOMIC_BOMB: + return Bomb(2,2,ATOMIC_BOMB) + elif bombType == CHEMICAL_BOMB: + return Bomb(2,3, CHEMICAL_BOMB) + elif bombType == CLAYMORE: + return Bomb(2,4, CLAYMORE) + elif bombType == LAND_MINE: + return Bomb(3,4, LAND_MINE) diff --git a/Engine/Chemical Bomb.png b/Engine/Chemical Bomb.png new file mode 100644 index 00000000..56d89cc4 Binary files /dev/null and b/Engine/Chemical Bomb.png differ diff --git a/Engine/Claymore.png b/Engine/Claymore.png new file mode 100644 index 00000000..41bac77d Binary files /dev/null and b/Engine/Claymore.png differ diff --git a/Engine/Decoy.png b/Engine/Decoy.png new file mode 100644 index 00000000..0112f792 Binary files /dev/null and b/Engine/Decoy.png differ diff --git a/Engine/Game.py b/Engine/Game.py index 270e10ac..af59cf5e 100644 --- a/Engine/Game.py +++ b/Engine/Game.py @@ -1,16 +1,23 @@ +import random + import pygame -from Constants import SQUARE_SIZE, GREEN, RIGHT, LEFT, UP, DOWN, COLS, ROWS +from Constants import SQUARE_SIZE, GREEN, RIGHT, LEFT, UP, DOWN, COLS, ROWS, DECOY, ATOMIC_BOMB, CHEMICAL_BOMB, CLAYMORE, LAND_MINE from Engine.Board import Board from Engine.Agent import Agent +from Engine.BombFactory import BombFactory +from Engine.Point import Point + class Game: def __init__(self, win): - self._init() + self._init(win) self.win = win + self.randomizeObject() + pygame.display.update() - def _init(self): - self.board = Board() - self.agent = Agent(0, 0) + def _init(self,win): + self.board = Board(win) + self.agent = Agent(Point(0,0)) self.turn = GREEN self.goingDown = True @@ -18,26 +25,45 @@ class Game: def update(self): self.board.drawSquares(self.win) - self.board.drawBombs(self.win, 1, 1) - self.board.drawBombs(self.win, 2, 3) - self.board.drawBombs(self.win, 5, 6) + self.board.drawBombs() self.board.drawAgent(self.win,self.agent) pygame.display.update() def move(self): + point = self.agent.getPoint() if self.goingDown: - if self.agent.y + 1 < ROWS: - self.agent.y += 1 - elif self.agent.x + 1 < COLS: - self.agent.x += 1 + if point.getY() + 1 < ROWS: + point.y += 1 + elif point.getX() + 1 < COLS: + point.x += 1 self.goingDown = not self.goingDown else: - if self.agent.y - 1 >= 0: - self.agent.y -= 1 - elif self.agent.x + 1 < COLS: - self.agent.x += 1 + if point.getY() - 1 >= 0: + point.y -= 1 + elif point.getX() + 1 < COLS: + point.x += 1 self.goingDown = not self.goingDown - + 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 + + + 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) diff --git a/Engine/bomb.png b/Engine/Land Mine.png similarity index 100% rename from Engine/bomb.png rename to Engine/Land Mine.png diff --git a/Engine/Point.py b/Engine/Point.py index fbaf7a8f..b6093105 100644 --- a/Engine/Point.py +++ b/Engine/Point.py @@ -1,4 +1,24 @@ class Point: - def __init__(self, column, row): - self.column = column - self.row = row \ No newline at end of file + def __init__(self, x, y): + self.x = x + self.y = y + + def getY(self): + return self.y + + def getX(self): + return self.x + + def __hash__(self): + """Overrides the default implementation""" + return hash(tuple(sorted(self.__dict__.items()))) + + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + else: + return False + + def __ne__(self, other): + return not self.__eq__(other) + diff --git a/Engine/Stone.png b/Engine/Stone.png new file mode 100644 index 00000000..5192c62b Binary files /dev/null and b/Engine/Stone.png differ diff --git a/Engine/__pycache__/Agent.cpython-39.pyc b/Engine/__pycache__/Agent.cpython-39.pyc index 56cfba29..c0aafeca 100644 Binary files a/Engine/__pycache__/Agent.cpython-39.pyc and b/Engine/__pycache__/Agent.cpython-39.pyc differ diff --git a/Engine/__pycache__/Board.cpython-39.pyc b/Engine/__pycache__/Board.cpython-39.pyc index e364f527..8e4e7298 100644 Binary files a/Engine/__pycache__/Board.cpython-39.pyc and b/Engine/__pycache__/Board.cpython-39.pyc differ diff --git a/Engine/__pycache__/Bomb.cpython-39.pyc b/Engine/__pycache__/Bomb.cpython-39.pyc new file mode 100644 index 00000000..12cd0cf4 Binary files /dev/null and b/Engine/__pycache__/Bomb.cpython-39.pyc differ diff --git a/Engine/__pycache__/BombFactory.cpython-39.pyc b/Engine/__pycache__/BombFactory.cpython-39.pyc new file mode 100644 index 00000000..bf63668f Binary files /dev/null and b/Engine/__pycache__/BombFactory.cpython-39.pyc differ diff --git a/Engine/__pycache__/Game.cpython-39.pyc b/Engine/__pycache__/Game.cpython-39.pyc index 7f8a4281..035a3fad 100644 Binary files a/Engine/__pycache__/Game.cpython-39.pyc and b/Engine/__pycache__/Game.cpython-39.pyc differ diff --git a/Engine/__pycache__/Point.cpython-39.pyc b/Engine/__pycache__/Point.cpython-39.pyc new file mode 100644 index 00000000..f9f42ce2 Binary files /dev/null and b/Engine/__pycache__/Point.cpython-39.pyc differ diff --git a/__pycache__/Constants.cpython-39.pyc b/__pycache__/Constants.cpython-39.pyc index 54da7c20..941bb29f 100644 Binary files a/__pycache__/Constants.cpython-39.pyc and b/__pycache__/Constants.cpython-39.pyc differ