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)
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
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
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
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
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
def test_get_entity_at(self): new_world = world.World("new world") coords = (1, 1) lichen = make_lichen(coords) new_world = add_entity(new_world, lichen.id, lichen) assert world.get_entity_at(new_world, coords) == lichen other_lichen = make_lichen((1, 2)) new_world = add_entity(new_world, other_lichen.id, other_lichen) assert world.get_entity_at(new_world, (1, 2)) == other_lichen assert world.get_entity_at(new_world, (1, 3)) == None
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
def test_take_damage(self): lichen = make_lichen((1, 1)) assert lichen.hp == 6 w = World("main") w = add_entity(w, lichen.id, lichen) lichen.take_damage(6, w) assert lichen.hp == 0 assert len(w.entities) == 0
def test_take_damage(self): lichen = make_lichen((1, 1)) assert lichen.hp == lichen.max_hp w = World("main") w = add_entity(w, lichen.id, lichen) lichen.take_damage(1, w) assert lichen.hp < lichen.max_hp
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
def test_is_empty(self): new_world = world.World("new world") # pass: floor and no entity new_world.tiles = tile.set_tile(new_world.tiles, (1, 1), tile.floor) assert world.is_empty(new_world, (1, 1)) == True # fail: wall and no entity new_world.tiles = tile.set_tile(new_world.tiles, (1, 2), tile.wall) assert world.is_empty(new_world, (1, 2)) == False # fail: floor and entity new_world.tiles = tile.set_tile(new_world.tiles, (1, 3), tile.floor) lichen = make_lichen((1, 3)) new_world = add_entity(new_world, lichen.id, lichen) assert world.is_empty(new_world, (1, 3)) == False # fail: wall and entity new_world.tiles = tile.set_tile(new_world.tiles, (1, 4), tile.wall) other_lichen = make_lichen((1, 4)) new_world = add_entity(new_world, other_lichen.id, other_lichen) assert world.is_empty(new_world, (1, 4)) == False
def grow(lichen, world): dest = find_empty_neighbor(world, lichen.location) if dest: new_lichen = make_lichen(dest) world = add_entity(world, new_lichen.id, new_lichen) return world
def add_creature(world, make_creature): empty_location = find_empty_tile(world) creature = make_creature(empty_location) world = add_entity(world, creature.id, creature) return world