Beispiel #1
0
 def home_base_location():
     return Location(x=0, y=0)
Beispiel #2
0
 def build_locations_for_range(x, y_range):
     return [Location(x, y) for y in range(-y_range, y_range + 1)]
Beispiel #3
0
 def update_tiles(self, updates):
     for update in updates:
         location = Location(update.x, update.y)
         self.tile_at(location).set_update(update)
Beispiel #4
0
 def tile_at_offset(self, target, offset):
     return self.tile_at(Location(x=target.x + offset.x, y=target.y + offset.y))
Beispiel #5
0
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)