Fix up the spatialmap to have an occupied_by method which checks if a square is occupied and returns what is there.
This commit is contained in:
parent
759f93cae0
commit
a11e7de14e
7 changed files with 24 additions and 43 deletions
|
@ -27,11 +27,12 @@ TEST_CASE("SpatialMap::insert", "[spatialmap]") {
|
|||
REQUIRE(!map.occupied(at));
|
||||
|
||||
map.insert(at, player, true);
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
REQUIRE_THROWS(map.insert(at, enemy, true));
|
||||
|
||||
map.insert(enemy_at, enemy, true);
|
||||
REQUIRE(map.occupied_by(enemy_at) == player);
|
||||
REQUIRE(map.occupied(enemy_at));
|
||||
}
|
||||
|
||||
|
@ -47,6 +48,7 @@ TEST_CASE("SpatialMap::remove", "[spatialmap]") {
|
|||
map.insert(at, player, true);
|
||||
map.insert(at, item, false);
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
auto data = map.remove(at, player);
|
||||
REQUIRE(!map.occupied(at));
|
||||
|
@ -74,6 +76,7 @@ TEST_CASE("SpatialMap::move", "[spatialmap]") {
|
|||
map.insert(enemy_at, enemy, true);
|
||||
map.insert(enemy_at, potion, false);
|
||||
REQUIRE(map.occupied(enemy_at));
|
||||
REQUIRE(map.occupied_by(enemy_at) == enemy);
|
||||
|
||||
Point target{at.x + 1, at.y};
|
||||
|
||||
|
@ -89,6 +92,7 @@ TEST_CASE("SpatialMap::move", "[spatialmap]") {
|
|||
map.move(at, target, player);
|
||||
|
||||
REQUIRE(map.occupied(target));
|
||||
REQUIRE(map.occupied_by(target) == player);
|
||||
auto data = map.remove(target, player);
|
||||
REQUIRE(data.entity == player);
|
||||
REQUIRE(data.collision == true);
|
||||
|
@ -116,12 +120,14 @@ TEST_CASE("SpatialMap::occupied/something_there", "[spatialmap]") {
|
|||
map.insert(at, player, true);
|
||||
REQUIRE(map.something_there(at));
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
// then remove the item and still have collision
|
||||
|
||||
map.remove(at, item);
|
||||
REQUIRE(map.something_there(at));
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
// remove player and back to no collision
|
||||
map.remove(at, player);
|
||||
|
@ -133,6 +139,7 @@ TEST_CASE("SpatialMap::occupied/something_there", "[spatialmap]") {
|
|||
map.insert(target, player, true);
|
||||
REQUIRE(map.something_there(target));
|
||||
REQUIRE(map.occupied(target));
|
||||
REQUIRE(map.occupied_by(target) == player);
|
||||
}
|
||||
|
||||
|
||||
|
@ -147,6 +154,7 @@ TEST_CASE("SpatialMap::get", "[spatialmap]") {
|
|||
// finally with collision and an item there
|
||||
map.insert(at, player, true);
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
auto entity = map.get(at);
|
||||
REQUIRE(player == entity);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue