示例#1
0
    def test_should_prevent_movement_outside_of_map_bounds(self):
        p = interfaces.Position(1, 1)
        o = tiles.Wall(p)
        assert_is(self.map.add(o), None)

        for (x, y) in (
            (-1, 0),
            (9, 9),
            (-1, 9),
        ):
            m = interfaces.Position(x, y)
            assert_raises(errors.InvalidMoveError, self.map.move, o, m)
示例#2
0
def step_impl(context, brightness):
    brightness = strip_prepositions(brightness)
    b = {
        'very dim': 0.1,
        'dim': 0.3,
        'low': 0.5,
        'medium': 0.7,
        'bright': 1.0,
        'very bright': 1.2
    }.get(brightness, 1.0)

    context.map.add(
        tiles.FlatLight(interfaces.Position(1, 1),
                        context.map.size - interfaces.Position(1, 1), b))
    context.map.recalculate_lighting()
示例#3
0
    def test_should_call_try_movement_on_all_traversables_at_destination_pos(
            self):
        p = interfaces.Position(1, 1)
        p1 = p + (1, 0)
        ts = [
            Mock(spec=tiles.Floor),
            Mock(spec=tiles.Floor),
        ]
        o = monsters.Dalek(p)
        for t in ts:
            t.pos = p1
            t.try_movement = Mock(return_value=1.0)
            self.map.add(t)
        self.map.add(o)

        t1 = Mock(spec=tiles.Floor)
        t1.pos = p
        t1.try_leaving = Mock(return_value=True)
        self.map.add(t1)

        assert_equal(self.map.move(o, p1), 2.0)

        for t in ts:
            t.try_movement.assert_called_once_with(o)
        assert_equal(t1.try_movement.call_count, 0)
示例#4
0
def step_impl(context):
    #DalekRL.init()
    p = player.Player()
    p.redraw_screen = Mock()
    p.handle_keys = Mock(return_value=p.do_nothing)  # default is do nothing
    context.map = maps.EmptyMap(0, interfaces.Position(80, 46), p)
    context.map.generate()
示例#5
0
    def test_should_add_obj_to_correct_layer_if_not_given(self):
        p = interfaces.Position(1, 1)
        for (o, layer) in (
            (tiles.Wall(p), tiles.Tile),
            (tiles.EvidencePanel(p), tiles.Tile),
            (monsters.Dalek(p), monsters.Monster),
            (monsters.StaticCamera(p), monsters.Monster),
            (items.HandTeleport(p, 1.0), items.Item),
            (items.RemoteControl(p, 1.0), items.Item),
        ):
            assert_is(self.map.add(o), None)

            assert_is(self.map.find_at_pos(p, layer), o)
            assert_is(o.map, self.map)

            assert_is(self.map.remove(o), None)
            assert_is(self.map.find_at_pos(p, layer), None)
示例#6
0
    def test_should_remove_obj_from_given_layer(self):
        # almost exactly the same
        p = interfaces.Position(1, 1)
        for (o, layer) in (
            (tiles.Wall(p), tiles.Tile),
            (tiles.EvidencePanel(p), tiles.Tile),
            (monsters.Dalek(p), monsters.Monster),
            (monsters.StaticCamera(p), monsters.Monster),
            (items.HandTeleport(p, 1.0), items.Item),
            (items.RemoteControl(p, 1.0), items.Item),
        ):

            assert_is(self.map.add(o, layer), None)
            assert_is(o.map, self.map)
            assert_is(self.map.find_at_pos(p, layer), o)

            assert_is(self.map.remove(o, layer), None)

            assert_is(o.pos, None)
            assert_is(self.map.find_at_pos(p, layer), None)
示例#7
0
    def test_should_use_layer_parameter_if_given(self):
        p = interfaces.Position(1, 1)
        p1 = p + (1, 1)
        for (o, layer) in (
            (tiles.Wall(p), tiles.Tile),
            (tiles.EvidencePanel(p), tiles.Tile),
            (monsters.Dalek(p), monsters.Monster),
            (monsters.StaticCamera(p), monsters.Monster),
            (items.HandTeleport(p, 1.0), items.Item),
            (items.RemoteControl(p, 1.0), items.Item),
        ):
            assert_is(self.map.add(o, layer), None)

            assert_equal(self.map.move(o, p1, layer), 0.0)

            assert_is(o.map, self.map)
            assert_is(self.map.find_at_pos(p, layer), None)
            assert_is(self.map.find_at_pos(p1, layer), o)
            assert_equal(o.pos, p1)

            assert_is(self.map.remove(o, layer), None)
            assert_is(self.map.find_at_pos(p, layer), None)
示例#8
0
def step_impl(context, enemy, actor):
    a = clean_actor(context, actor)
    e_class = clean_enemy(context, enemy)

    e = e_class(a.pos + interfaces.Position(2, 2))
    context.map.add(e)
示例#9
0
 def test_should_not_add_if_not_mappable(self):
     p = interfaces.Position(1, 1)
     assert_raises(AssertionError, self.map.add, self, p)
示例#10
0
 def setUp(self):
     self.player = Mock(spec_set=player.Player)
     self.map = maps.Map(None, interfaces.Position(3, 3), self.player)
示例#11
0
    def test_should_prevent_movement_when_not_added_to_map(self):
        p = interfaces.Position(1, 1)
        o = tiles.Wall(p)

        assert_raises(AssertionError, self.map.move, o, p + (1, 1))
示例#12
0
 def test_should_prevent_removal_of_obj_not_on_map(self):
     p = interfaces.Position(1, 1)
     o = tiles.Wall(p)
     assert_raises(AssertionError, self.map.remove, o)