added bombs and randBojects
@ -9,3 +9,9 @@ UP = 'UP'
|
||||
DOWN = 'DOWN'
|
||||
LEFT = 'LEFT'
|
||||
RIGHT = 'RIGHT'
|
||||
|
||||
DECOY = 'Decoy'
|
||||
ATOMIC_BOMB = 'Atomic Bomb'
|
||||
CLAYMORE = 'Claymore'
|
||||
CHEMICAL_BOMB = 'Chemical Bomb'
|
||||
LAND_MINE = 'Land Mine'
|
@ -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:
|
||||
|
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:
|
||||
|
||||
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))
|
||||
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 = (x * SQUARE_SIZE + SQUARE_SIZE/2 + 5, y * SQUARE_SIZE + SQUARE_SIZE/2 - 5)
|
||||
win.blit(image, 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
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -1,4 +1,24 @@
|
||||
class Point:
|
||||
def __init__(self, column, row):
|
||||
self.column = column
|
||||
self.row = row
|
||||
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)
|
||||
|
||||
|
BIN
Engine/Stone.png
Normal file
After Width: | Height: | Size: 31 KiB |