def home_base_location(): return Location(x=0, y=0)
def build_locations_for_range(x, y_range): return [Location(x, y) for y in range(-y_range, y_range + 1)]
def update_tiles(self, updates): for update in updates: location = Location(update.x, update.y) self.tile_at(location).set_update(update)
def tile_at_offset(self, target, offset): return self.tile_at(Location(x=target.x + offset.x, y=target.y + offset.y))
from state import Tile, Location from directions import Direction, cardinal_directions offset_map = { Direction.NORTH: Location(x=0, y=-1), Direction.EAST: Location(x=1, y=0), Direction.SOUTH: Location(x=0, y=1), Direction.WEST: Location(x=-1, y=0), Direction.NONE: Location(0, 0) } def offset_for_direction(direction): return offset_map[direction] class Map: def __init__(self): self.width = None self.height = None self.tiles = {} def set_size(self, width, height): self.width = width self.height = height def update_tiles(self, updates): for update in updates: location = Location(update.x, update.y) self.tile_at(location).set_update(update)