implemented minefield, tiles and mines
This commit is contained in:
parent
699174bc6d
commit
7a735106bd
7
main.py
7
main.py
@ -5,6 +5,7 @@ from pyglet.gl import * # for blocky textures
|
||||
# other files of this project
|
||||
import project_constants
|
||||
import event_interpreter
|
||||
import minefield as mf
|
||||
|
||||
|
||||
|
||||
@ -20,7 +21,8 @@ def main():
|
||||
|
||||
|
||||
# loading minefields
|
||||
# TODO : call to a minefield loading function goes here
|
||||
# create an instance of Minefield, pass necessary data
|
||||
minefield = mf.Minefield()
|
||||
|
||||
|
||||
running = True
|
||||
@ -47,7 +49,7 @@ def main():
|
||||
|
||||
# mines
|
||||
# TODO : call to a mine blitting function goes here
|
||||
|
||||
minefield.draw(project_constants.SCREEN)
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
@ -63,5 +65,6 @@ def main():
|
||||
|
||||
else: event_interpreter.interpret( event )
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
20
mine.py
Normal file
20
mine.py
Normal file
@ -0,0 +1,20 @@
|
||||
import project_constants as consts
|
||||
|
||||
|
||||
class Mine:
|
||||
def __init__(self, position, mine_type, active=True):
|
||||
self.position = position
|
||||
self.mine_type = mine_type
|
||||
|
||||
if mine_type == 'a':
|
||||
self.asset = consts.ASSET_MINE_A
|
||||
elif mine_type == 'b':
|
||||
self.asset = consts.ASSET_MINE_B
|
||||
elif mine_type == 'f':
|
||||
self.asset = consts.ASSET_MINE_F
|
||||
elif mine_type == 'k':
|
||||
self.asset = consts.ASSET_MINE_K
|
||||
else:
|
||||
self.asset = None
|
||||
|
||||
self.active = active
|
39
minefield.py
Normal file
39
minefield.py
Normal file
@ -0,0 +1,39 @@
|
||||
import pygame
|
||||
import project_constants as consts
|
||||
import tile as tl
|
||||
import mine as mn
|
||||
|
||||
|
||||
class Minefield:
|
||||
def __init__(self, minefield_data=None):
|
||||
|
||||
# create matrix of a desired size, fill it with empty tile objects
|
||||
self.matrix = [[tl.Tile((i, j)) for i in range(consts.V_GRID_VER_TILES)] for j in range(consts.V_GRID_HOR_TILES)]
|
||||
|
||||
# serialize JSON, create matrix
|
||||
|
||||
# iterate through matrix fields
|
||||
for x in range(consts.V_GRID_HOR_TILES):
|
||||
for y in range(consts.V_GRID_VER_TILES):
|
||||
# if there should be a mine, create one
|
||||
mine = mn.Mine((x, y), 'f')
|
||||
|
||||
# change tile properties
|
||||
self.matrix[x][y].update_color("green")
|
||||
self.matrix[x][y].mine = mine
|
||||
|
||||
def draw(self, window):
|
||||
# iterate through tiles
|
||||
for column in self.matrix:
|
||||
for tile in column:
|
||||
pixel_coords = (
|
||||
consts.V_SCREEN_PADDING + consts.V_TILE_SIZE * tile.position[0], # x
|
||||
consts.V_SCREEN_PADDING + consts.V_TILE_SIZE * tile.position[1] # y
|
||||
)
|
||||
|
||||
window.blit(tile.asset, pixel_coords)
|
||||
|
||||
if tile.mine is not None:
|
||||
window.blit(tile.mine.asset, pixel_coords)
|
||||
|
||||
|
48
tile.py
Normal file
48
tile.py
Normal file
@ -0,0 +1,48 @@
|
||||
import project_constants as consts
|
||||
|
||||
|
||||
class Tile:
|
||||
def __init__(self, position, color=None, mine=None):
|
||||
self.position = position
|
||||
self.color = color
|
||||
|
||||
if color == "blue":
|
||||
self.asset = consts.ASSET_TILE_BLUE
|
||||
elif color == "green":
|
||||
self.asset = consts.ASSET_TILE_GREEN
|
||||
elif color == "orange":
|
||||
self.asset = consts.ASSET_TILE_ORANGE
|
||||
elif color == "purple":
|
||||
self.asset = consts.ASSET_TILE_PURPLE
|
||||
elif color == "red":
|
||||
self.asset = consts.ASSET_TILE_RED
|
||||
elif color == "white":
|
||||
self.asset = consts.ASSET_TILE_WHITE
|
||||
elif color == "yellow":
|
||||
self.asset = consts.ASSET_TILE_YELLOW
|
||||
else:
|
||||
self.asset = None
|
||||
|
||||
self.mine = mine
|
||||
|
||||
def update_color(self, color):
|
||||
self.color = color
|
||||
|
||||
if color == "blue":
|
||||
self.asset = consts.ASSET_TILE_BLUE
|
||||
elif color == "green":
|
||||
self.asset = consts.ASSET_TILE_GREEN
|
||||
elif color == "orange":
|
||||
self.asset = consts.ASSET_TILE_ORANGE
|
||||
elif color == "purple":
|
||||
self.asset = consts.ASSET_TILE_PURPLE
|
||||
elif color == "red":
|
||||
self.asset = consts.ASSET_TILE_RED
|
||||
elif color == "white":
|
||||
self.asset = consts.ASSET_TILE_WHITE
|
||||
elif color == "yellow":
|
||||
self.asset = consts.ASSET_TILE_YELLOW
|
||||
else:
|
||||
self.asset = None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user