コード例 #1
0
ファイル: test_player.py プロジェクト: theophilus8402/caves
    def test_move_player(self):
        player = make_player((1, 1))
        lichen = make_lichen((1, 0))

        w = World("main")
        add_entity(w, lichen.id, lichen)
        add_entity(w, "player", player)

        w.tiles = set_tile(w.tiles, (1, 1), floor)
        w.tiles = set_tile(w.tiles, (1, 0), floor)
        w.tiles = set_tile(w.tiles, (1, 2), wall)
        w.tiles = set_tile(w.tiles, (2, 1), floor)

        # check to see if it attacks the lichen
        assert lichen.hp == lichen.max_hp
        move_player("n", w)
        assert lichen.hp < lichen.max_hp

        # check to see if it digs
        assert get_tile(w.tiles, (1, 2)) == wall
        move_player("s", w)
        assert get_tile(w.tiles, (1, 2)) == floor

        # check to see if it just moves
        assert player.location == (1, 1)
        move_player("s", w)
        assert player.location == (1, 2)
コード例 #2
0
def populate_world(world):
    empty_location = find_empty_tile(world)
    world = add_entity(world, "player", make_player(empty_location))

    world = add_creatures(world, make_lichen, 30)
    world = add_creatures(world, make_bunny, 20)
    world = add_creatures(world, make_silverfish, 20)

    return world
コード例 #3
0
ファイル: test_digger.py プロジェクト: theophilus8402/caves
    def test_can_dig(self):
        player = make_player((1, 1))

        w = World("new world")
        w.tiles = set_tile(w.tiles, (1, 1), floor)
        w.tiles = set_tile(w.tiles, (1, 2), wall)

        assert player.can_dig((1, 1), w) == False
        assert player.can_dig((1, 2), w) == True
コード例 #4
0
ファイル: test_digger.py プロジェクト: theophilus8402/caves
    def test_dig(self):
        player = make_player((1, 1))

        w = World("new world")
        w.tiles = set_tile(w.tiles, (1, 1), floor)
        w.tiles = set_tile(w.tiles, (1, 2), wall)

        assert get_tile(w.tiles, (1, 2)) == wall
        player.dig((1, 2), w)
        assert get_tile(w.tiles, (1, 2)) == floor
コード例 #5
0
ファイル: test_attacker.py プロジェクト: theophilus8402/caves
    def test_get_damage(self):
        lichen = make_lichen((1, 1))
        player = make_player((1, 2))

        w = World("world")
        add_entity(w, lichen.id, lichen)

        damage = get_damage(player, lichen, w)
        assert damage <= player.attack_value
        assert damage >= 1
コード例 #6
0
ファイル: test_coords.py プロジェクト: theophilus8402/caves
    def test_get_entities_around(self):
        lichen = make_lichen((1, 1))
        player = make_player((1, 2))
        w = World("main")

        w = add_entity(w, lichen.id, lichen)
        w = add_entity(w, "player", player)

        assert len(get_entities_around(w, player.location, radius=3)) == 2
        assert len(get_entities_around(w, (-5, -5), radius=3)) == 0
        assert len(get_entities_around(w, (0, 0), radius=1)) == 1
コード例 #7
0
ファイル: test_receiver.py プロジェクト: theophilus8402/caves
    def test_send_message_nearby(self):
        lichen = make_lichen((1, 1))
        player = make_player((1, 2))

        w = World("world")
        add_entity(w, lichen.id, lichen)
        add_entity(w, "player", player)

        assert len(player.messages) == 0
        send_message_nearby(player.location, "AAAAHHHH!!!", w)
        assert len(player.messages) == 1
コード例 #8
0
ファイル: test_attacker.py プロジェクト: theophilus8402/caves
    def test_attack(self):
        lichen = make_lichen((1, 1))
        player = make_player((1, 2))

        w = World("world")
        add_entity(w, lichen.id, lichen)

        assert lichen.hp == lichen.max_hp
        player.attack(lichen, w)
        assert len(player.messages) == 1
        assert lichen.hp < lichen.max_hp
コード例 #9
0
ファイル: test_receiver.py プロジェクト: theophilus8402/caves
    def test_receive_message(self):
        lichen = make_lichen((1, 1))
        player = make_player((1, 2))

        w = World("world")
        add_entity(w, lichen.id, lichen)
        add_entity(w, "player", player)

        assert len(player.messages) == 0
        send_message(player, "The Lichen grows at {coord}.",
                     {"coord": "(1, 1)"}, w)
        assert len(player.messages) == 1
コード例 #10
0
ファイル: test_player.py プロジェクト: theophilus8402/caves
    def test_attack(self):
        lichen = make_lichen((1, 1))
        player = make_player((1, 2))
        w = World("main")

        w = add_entity(w, lichen.id, lichen)
        w = add_entity(w, "player", player)

        player.attack(lichen, w)

        assert lichen.hp < lichen.max_hp
        if lichen.hp <= 0:
            assert get_entity(w, lichen.id) == None
        else:
            assert get_entity(w, lichen.id) == lichen
コード例 #11
0
    def test_is_destructible(self):
        lichen = make_lichen((1, 1))
        assert is_destructible(lichen) == True

        player = make_player((1, 2))
        assert is_destructible(player) == False
コード例 #12
0
ファイル: test_attacker.py プロジェクト: theophilus8402/caves
    def test_attack_value(self):
        player = make_player((1, 2))

        assert player.attack_value == 10
        player._attack_value = 3
        assert player.attack_value == 3