python - When I create an object, what do I pass as the arguments? -
i have class/function in file named "worldmodel.py":
import entities import pygame import ordered_list import actions import occ_grid import point class worldmodel: def __init__(self, num_rows, num_cols, background): self.background = occ_grid.grid(num_cols, num_rows, background) self.num_rows = num_rows self.num_cols = num_cols self.occupancy = occ_grid.grid(num_cols, num_rows, none) self.entities = [] self.action_queue = ordered_list.orderedlist() def add_entity(world, entity): obj = occ_grid.grid() pt = entities.get_position(entity) if within_bounds(world, pt): old_entity = occ_grid.get_cell(pt) if old_entity != none: entities.clear_pending_actions(old_entity) obj.set_cell(pt, entity) world.entities.append(entity)
and have class/method in file named "occ_grid.py":
# define occupancy value empty = 0 gatherer = 1 generator = 2 resource = 3 class grid: def __init__(self, width, height, occupancy_value): self.width = width self.height = height self.cells = [] # initialize grid specified occupancy value row in range(0, self.height): self.cells.append([]) col in range(0, self.width): self.cells[row].append(occupancy_value) def set_cell(self, point, value): self.cells[point.y][point.x] = value
if on first line of code in body of def add_entity
, see i've created object can use set_cell
, method occ_grid.py
. i'm not sure pass occ_grid.grid()
arguments. feedback/thoughts appreciated!
from def __init__(self, width, height, occupancy_value)
, can see self
, width
, height
, occupancy_value
need passed.
now, self
put there need pass in other 3 so:
occupancy_value = # whatever initial value want cells have width = # whatever width want height = # whatever height want obj = occ_grid.grid(width, height, occupancy_value)
Comments
Post a Comment