added bombs and randBojects
@ -8,4 +8,10 @@ BLACK = (0,0,0)
|
|||||||
UP = 'UP'
|
UP = 'UP'
|
||||||
DOWN = 'DOWN'
|
DOWN = 'DOWN'
|
||||||
LEFT = 'LEFT'
|
LEFT = 'LEFT'
|
||||||
RIGHT = 'RIGHT'
|
RIGHT = 'RIGHT'
|
||||||
|
|
||||||
|
DECOY = 'Decoy'
|
||||||
|
ATOMIC_BOMB = 'Atomic Bomb'
|
||||||
|
CLAYMORE = 'Claymore'
|
||||||
|
CHEMICAL_BOMB = 'Chemical Bomb'
|
||||||
|
LAND_MINE = 'Land Mine'
|
@ -1,11 +1,13 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from Constants import ROWS, COLS, UP, LEFT, DOWN, RIGHT
|
from Constants import ROWS, COLS, UP, LEFT, DOWN, RIGHT
|
||||||
class Agent(object):
|
class Agent(object):
|
||||||
def __init__(self, y, x):
|
def __init__(self, point):
|
||||||
self.y = y
|
self.point = point
|
||||||
self.x = x
|
|
||||||
self.image = pygame.image.load('Engine/agent.png')
|
self.image = pygame.image.load('Engine/agent.png')
|
||||||
|
|
||||||
|
def getPoint(self):
|
||||||
|
return self.point
|
||||||
|
|
||||||
# def ifNotOnEdge(self, destination):
|
# def ifNotOnEdge(self, destination):
|
||||||
# if destination == UP:
|
# if destination == UP:
|
||||||
# if self.x - 1 <= 0:
|
# if self.x - 1 <= 0:
|
||||||
|
BIN
Engine/Atomic Bomb.png
Normal file
After Width: | Height: | Size: 11 KiB |
@ -4,8 +4,10 @@ from Constants import ROWS, COLS, SQUARE_SIZE, GREEN, BLACK, WIDTH
|
|||||||
|
|
||||||
class Board:
|
class Board:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, win):
|
||||||
self.board = []
|
self.board = []
|
||||||
|
self.bombMap = {}
|
||||||
|
self.win = win
|
||||||
|
|
||||||
def drawSquares(self, win):
|
def drawSquares(self, win):
|
||||||
win.fill(GREEN)
|
win.fill(GREEN)
|
||||||
@ -15,12 +17,14 @@ class Board:
|
|||||||
|
|
||||||
def drawAgent(self, win, agent):
|
def drawAgent(self, win, agent):
|
||||||
rect = agent.image.get_rect()
|
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)
|
win.blit(agent.image, rect)
|
||||||
|
|
||||||
def drawBombs(self,win, x, y):
|
def drawBombs(self):
|
||||||
image = pygame.image.load('Engine/bomb.png')
|
for key in self.bombMap:
|
||||||
image = pygame.transform.scale(image, (SQUARE_SIZE, SQUARE_SIZE))
|
bomb = self.bombMap[key]
|
||||||
rect = image.get_rect()
|
image = pygame.image.load('Engine/' + bomb.bombType + '.png')
|
||||||
rect.center = (x * SQUARE_SIZE + SQUARE_SIZE/2 + 5, y * SQUARE_SIZE + SQUARE_SIZE/2 - 5)
|
image = pygame.transform.scale(image, (SQUARE_SIZE - 5, SQUARE_SIZE - 5))
|
||||||
win.blit(image, rect)
|
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)
|
||||||
|
7
Engine/Bomb.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class Bomb:
|
||||||
|
|
||||||
|
def __init__(self, detonationTime, defuseTime, bombType):
|
||||||
|
self.detonationTime = detonationTime
|
||||||
|
self.defuseTime = defuseTime
|
||||||
|
self.bombType = bombType
|
||||||
|
self.isDefused = False
|
17
Engine/BombFactory.py
Normal file
@ -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)
|
BIN
Engine/Chemical Bomb.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
Engine/Claymore.png
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
Engine/Decoy.png
Normal file
After Width: | Height: | Size: 13 KiB |
@ -1,16 +1,23 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
import pygame
|
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.Board import Board
|
||||||
from Engine.Agent import Agent
|
from Engine.Agent import Agent
|
||||||
|
from Engine.BombFactory import BombFactory
|
||||||
|
from Engine.Point import Point
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self, win):
|
def __init__(self, win):
|
||||||
self._init()
|
self._init(win)
|
||||||
self.win = win
|
self.win = win
|
||||||
|
self.randomizeObject()
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
def _init(self):
|
def _init(self,win):
|
||||||
self.board = Board()
|
self.board = Board(win)
|
||||||
self.agent = Agent(0, 0)
|
self.agent = Agent(Point(0,0))
|
||||||
self.turn = GREEN
|
self.turn = GREEN
|
||||||
self.goingDown = True
|
self.goingDown = True
|
||||||
|
|
||||||
@ -18,26 +25,45 @@ class Game:
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.board.drawSquares(self.win)
|
self.board.drawSquares(self.win)
|
||||||
self.board.drawBombs(self.win, 1, 1)
|
self.board.drawBombs()
|
||||||
self.board.drawBombs(self.win, 2, 3)
|
|
||||||
self.board.drawBombs(self.win, 5, 6)
|
|
||||||
self.board.drawAgent(self.win,self.agent)
|
self.board.drawAgent(self.win,self.agent)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
def move(self):
|
def move(self):
|
||||||
|
point = self.agent.getPoint()
|
||||||
if self.goingDown:
|
if self.goingDown:
|
||||||
if self.agent.y + 1 < ROWS:
|
if point.getY() + 1 < ROWS:
|
||||||
self.agent.y += 1
|
point.y += 1
|
||||||
elif self.agent.x + 1 < COLS:
|
elif point.getX() + 1 < COLS:
|
||||||
self.agent.x += 1
|
point.x += 1
|
||||||
self.goingDown = not self.goingDown
|
self.goingDown = not self.goingDown
|
||||||
else:
|
else:
|
||||||
if self.agent.y - 1 >= 0:
|
if point.getY() - 1 >= 0:
|
||||||
self.agent.y -= 1
|
point.y -= 1
|
||||||
elif self.agent.x + 1 < COLS:
|
elif point.getX() + 1 < COLS:
|
||||||
self.agent.x += 1
|
point.x += 1
|
||||||
self.goingDown = not self.goingDown
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -1,4 +1,24 @@
|
|||||||
class Point:
|
class Point:
|
||||||
def __init__(self, column, row):
|
def __init__(self, x, y):
|
||||||
self.column = column
|
self.x = x
|
||||||
self.row = row
|
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)
|
||||||
|
|
||||||
|
BIN
Engine/Stone.png
Normal file
After Width: | Height: | Size: 31 KiB |