Dodany Enum Terrain; Dodany koszt na Tile; Używana jest nowa mapa testowa (reskin secondmap)

This commit is contained in:
Jakub Danilewicz 2021-05-07 19:02:09 +02:00
parent 46b6db6c00
commit 436a155b7e
6 changed files with 548 additions and 49 deletions

View File

@ -8,20 +8,13 @@ import project_constants as const
# ================================= #
tile_asset_options = {
"BLUE": const.ASSET_TILE_BLUE,
"GREEN": const.ASSET_TILE_GREEN,
"ORANGE": const.ASSET_TILE_ORANGE,
"PURPLE": const.ASSET_TILE_PURPLE,
"RED": const.ASSET_TILE_RED,
"WHITE": const.ASSET_TILE_WHITE,
"YELLOW": const.ASSET_TILE_YELLOW
"MUD": const.ASSET_MUD,
"GRASS": const.ASSET_GRASS,
"CONCRETE": const.ASSET_CONCRETE
}
mine_asset_options = {
'A': const.ASSET_MINE_A,
'B': const.ASSET_MINE_B,
'F': const.ASSET_MINE_F,
'K': const.ASSET_MINE_K
"MINE": CONST.ASSET_MINE
}
@ -30,21 +23,6 @@ mine_asset_options = {
# ====================== #
def test_blits():
display_concrete((2, 3))
display_mud((5, 6))
display_mud((5, 7))
display_grass((2, 1))
display_mine((2, 7))
display_mine((5, 7))
display_concrete((0, 0))
display_chained_mine((1, 2), (2, 3))
display_chained_mine((2, 3))
display_chained_mine((4, 8), (11, 15))
display_time_mine((1, 8), 12)
display_time_mine((2, 8), 34)
def blit_graphics(minefield):
# background grid (fills frame with white, blits grid)
const.SCREEN.fill((255, 255, 255))
@ -64,7 +42,7 @@ def blit_graphics(minefield):
# draw a tile
const.SCREEN.blit(
tile_asset_options.get(tile.color),
tile_asset_options.get(tile.terrain_type),
tile_screen_coords
)
@ -75,10 +53,9 @@ def blit_graphics(minefield):
# draw a mine on top if there is one
if tile.mine is not None:
# current icons don't represent actual types, thus every mine has the same icon (temporary solution)
const.SCREEN.blit(mine_asset_options['A'], tile_screen_coords)
const.SCREEN.blit(mine_asset_options["MINE"], tile_screen_coords)
# all the tests in one place
test_blits()
# sapper
display_sapper(

View File

@ -39,7 +39,7 @@ class JsonGenerator:
"direction": direction
}
# overwrites grid field with a new grid with randomized colors and mines
# overwrites grid field with a new grid with randomized terrains and mines
def generate_randomized_grid(self, dimensions, mine_appearance_chance=0.15, predecessor_chance_decrease=0.25):
# clearing grid field
self.clear_grid()
@ -53,13 +53,13 @@ class JsonGenerator:
for j in range(num_of_columns):
# picking random values for tiles
random_tile_color = random.choice(const.STRUCT_TILE_COLORS)
random_tile_terrain = random.choice(const.STRUCT_TILE_TERRAINS)
# adding added tile's indexes to a pool
tile_pool.append((i, j))
# creating random tile
self.add_tile((i, j), random_tile_color)
self.add_tile((i, j), random_tile_terrain)
# deleting agent's starting tile from the pool
deleted_row, deleted_column = self.agents_initial_position
@ -104,15 +104,15 @@ class JsonGenerator:
current_tile = predecessor
# adds a new tile or edits an existing one in the grid field
def add_tile(self, position, color):
def add_tile(self, position, terrain):
# creating new tile without a mine
self.grid[format_position_to_str(position)] = {
"color": color,
"terrain": terrain,
"mine": None
}
# adds a new tile with a mine or edits an existing one in the grid field
def add_tile_with_a_mine(self, position, color, mine_type, attribute_values):
def add_tile_with_a_mine(self, position, terrain, mine_type, attribute_values):
# setting mine data using attribute_values
mine_values = const.STRUCT_MINE_ATTRIBUTES[mine_type]
@ -122,7 +122,7 @@ class JsonGenerator:
# creating a new tile
self.grid[format_position_to_str(position)] = {
"color": color
"terrain": terrain
}
# updating the tile with a mine field
@ -247,11 +247,11 @@ def create_a_tile(tile_dict, position):
position = format_position_to_tuple(position)
# getting tile's parameters
color = tile_dict["color"]
terrain = tile_dict["terrain"]
mine = create_a_mine(position, tile_dict["mine"])
# creating and returning a tile with the parameters set above
return tl.Tile(position, color, mine)
return tl.Tile(position, terrain, mine)
# returns a list of tuples containing chained mine's position and it's predecessors position

View File

@ -24,7 +24,7 @@ class Minefield:
] for row in range(const.V_GRID_VER_TILES)
]
# iterate through tiles, set their colors and add mines
# iterate through tiles, set their terrains and add mines
for row in range(const.V_GRID_VER_TILES):
for column in range(const.V_GRID_HOR_TILES):
@ -36,7 +36,7 @@ class Minefield:
mine = self._create_mine(tile_data["mine"], row, column)
self.matrix[row][column].mine = mine
self.matrix[row][column].color = tile_data["color"].upper()
self.matrix[row][column].terrain_type = tile_data["terrain"].upper()
# ================ #
# === MOVEMENT === #

View File

@ -70,6 +70,12 @@ class Coords(Enum):
Y = 1
class Terrain(Enum):
CONCRETE = 1
GRASS = 2
MUD = 4
# =============== #
# === STRUCTS === #
# =============== #
@ -79,8 +85,8 @@ class Coords(Enum):
# # USED BY JSON GENERATOR
# used to generate random tile colors
STRUCT_TILE_COLORS = ["BLUE", "GREEN", "ORANGE", "PURPLE", "RED", "WHITE", "YELLOW"]
#####################STRUCT_TILE_COLORS = ["BLUE", "GREEN", "ORANGE", "PURPLE", "RED", "WHITE", "YELLOW"]
STRUCT_TILE_TERRAINS = ["CONCRETE","GRASS","MUD"]
# used to generate random mines and create not random mines
STRUCT_MINE_TYPES = ["standard", "chained", "time"]
@ -118,7 +124,7 @@ STRUCT_MINE_ATTRIBUTE_TYPES = {
# ==== MAPS ==== #
# ============== #
MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "secondmap.json")
MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "fourthmap.json")
# ============== #

View File

@ -0,0 +1,500 @@
{
"0,0": {
"terrain": "CONCRETE",
"mine": null
},
"0,1": {
"terrain": "CONCRETE",
"mine": null
},
"0,2": {
"terrain": "GRASS",
"mine": null
},
"0,3": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
},
"0,4": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
},
"0,5": {
"terrain": "CONCRETE",
"mine": null
},
"0,6": {
"terrain": "MUD",
"mine": null
},
"0,7": {
"terrain": "GRASS",
"mine": null
},
"0,8": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "0,3"
}
},
"0,9": {
"terrain": "GRASS",
"mine": {
"asset": "F",
"mine_type": "time",
"timer": 20
}
},
"1,0": {
"terrain": "GRASS",
"mine": null
},
"1,1": {
"terrain": "GRASS",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"1,2": {
"terrain": "GRASS",
"mine": null
},
"1,3": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
},
"1,4": {
"terrain": "MUD",
"mine": null
},
"1,5": {
"terrain": "GRASS",
"mine": null
},
"1,6": {
"terrain": "GRASS",
"mine": null
},
"1,7": {
"terrain": "GRASS",
"mine": null
},
"1,8": {
"terrain": "MUD",
"mine": null
},
"1,9": {
"terrain": "MUD",
"mine": null
},
"2,0": {
"terrain": "MUD",
"mine": null
},
"2,1": {
"terrain": "CONCRETE",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"2,2": {
"terrain": "MUD",
"mine": null
},
"2,3": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
},
"2,4": {
"terrain": "GRASS",
"mine": null
},
"2,5": {
"terrain": "MUD",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"2,6": {
"terrain": "CONCRETE",
"mine": null
},
"2,7": {
"terrain": "CONCRETE",
"mine": null
},
"2,8": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
},
"2,9": {
"terrain": "CONCRETE",
"mine": null
},
"3,0": {
"terrain": "CONCRETE",
"mine": null
},
"3,1": {
"terrain": "MUD",
"mine": {
"asset": "F",
"mine_type": "time",
"timer": 19
}
},
"3,2": {
"terrain": "GRASS",
"mine": null
},
"3,3": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "1,3"
}
},
"3,4": {
"terrain": "MUD",
"mine": null
},
"3,5": {
"terrain": "CONCRETE",
"mine": null
},
"3,6": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
},
"3,7": {
"terrain": "MUD",
"mine": null
},
"3,8": {
"terrain": "GRASS",
"mine": null
},
"3,9": {
"terrain": "GRASS",
"mine": null
},
"4,0": {
"terrain": "CONCRETE",
"mine": null
},
"4,1": {
"terrain": "MUD",
"mine": null
},
"4,2": {
"terrain": "CONCRETE",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"4,3": {
"terrain": "CONCRETE",
"mine": null
},
"4,4": {
"terrain": "MUD",
"mine": null
},
"4,5": {
"terrain": "MUD",
"mine": null
},
"4,6": {
"terrain": "CONCRETE",
"mine": null
},
"4,7": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
},
"4,8": {
"terrain": "CONCRETE",
"mine": null
},
"4,9": {
"terrain": "MUD",
"mine": null
},
"5,0": {
"terrain": "CONCRETE",
"mine": null
},
"5,1": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "2,3"
}
},
"5,2": {
"terrain": "MUD",
"mine": null
},
"5,3": {
"terrain": "GRASS",
"mine": null
},
"5,4": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "2,8"
}
},
"5,5": {
"terrain": "CONCRETE",
"mine": null
},
"5,6": {
"terrain": "MUD",
"mine": null
},
"5,7": {
"terrain": "MUD",
"mine": null
},
"5,8": {
"terrain": "GRASS",
"mine": null
},
"5,9": {
"terrain": "MUD",
"mine": null
},
"6,0": {
"terrain": "GRASS",
"mine": null
},
"6,1": {
"terrain": "CONCRETE",
"mine": null
},
"6,2": {
"terrain": "MUD",
"mine": null
},
"6,3": {
"terrain": "CONCRETE",
"mine": null
},
"6,4": {
"terrain": "CONCRETE",
"mine": null
},
"6,5": {
"terrain": "GRASS",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"6,6": {
"terrain": "GRASS",
"mine": null
},
"6,7": {
"terrain": "CONCRETE",
"mine": null
},
"6,8": {
"terrain": "CONCRETE",
"mine": null
},
"6,9": {
"terrain": "CONCRETE",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"7,0": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "4,7"
}
},
"7,1": {
"terrain": "CONCRETE",
"mine": null
},
"7,2": {
"terrain": "GRASS",
"mine": null
},
"7,3": {
"terrain": "MUD",
"mine": null
},
"7,4": {
"terrain": "GRASS",
"mine": null
},
"7,5": {
"terrain": "GRASS",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"7,6": {
"terrain": "CONCRETE",
"mine": {
"asset": "F",
"mine_type": "time",
"timer": 39
}
},
"7,7": {
"terrain": "MUD",
"mine": null
},
"7,8": {
"terrain": "GRASS",
"mine": null
},
"7,9": {
"terrain": "GRASS",
"mine": null
},
"8,0": {
"terrain": "GRASS",
"mine": null
},
"8,1": {
"terrain": "GRASS",
"mine": {
"asset": "F",
"mine_type": "time",
"timer": 24
}
},
"8,2": {
"terrain": "GRASS",
"mine": null
},
"8,3": {
"terrain": "CONCRETE",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"8,4": {
"terrain": "CONCRETE",
"mine": null
},
"8,5": {
"terrain": "GRASS",
"mine": null
},
"8,6": {
"terrain": "GRASS",
"mine": null
},
"8,7": {
"terrain": "CONCRETE",
"mine": null
},
"8,8": {
"terrain": "GRASS",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "3,6"
}
},
"8,9": {
"terrain": "GRASS",
"mine": null
},
"9,0": {
"terrain": "MUD",
"mine": null
},
"9,1": {
"terrain": "GRASS",
"mine": null
},
"9,2": {
"terrain": "CONCRETE",
"mine": null
},
"9,3": {
"terrain": "CONCRETE",
"mine": null
},
"9,4": {
"terrain": "CONCRETE",
"mine": null
},
"9,5": {
"terrain": "GRASS",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "0,4"
}
},
"9,6": {
"terrain": "CONCRETE",
"mine": null
},
"9,7": {
"terrain": "MUD",
"mine": null
},
"9,8": {
"terrain": "MUD",
"mine": null
},
"9,9": {
"terrain": "MUD",
"mine": null
},
"agent_starting_position": "0,0"
}

24
tile.py
View File

@ -1,7 +1,23 @@
class Tile:
def __init__(self, position, color=None, mine=None):
self.position = position
self.color = color
from project_constants import Terrain as t
#Assume_cost function assumes colour as an argument (colour that is already given to a tile) and depending
#on what it is returns value of Terrein Enum
#It is used in Tile.cost (giving the value to the tile)
def assume_cost(terrain_type):
if (terrain_type == "CONCRETE"):
return t.CONCRETE
elif (terrain_type == "GRASS"):
return t.GRASS
elif (terrain_type == "MUD"):
return t.MUD
class Tile:
def __init__(self, position, terrain_type=None, mine=None):
self.position = position
self.terrain_type = terrain_type
self.cost = assume_cost(terrain_type)
# mine is an instance of Mine class
self.mine = mine