diff --git a/src/expansion.cr b/src/expansion.cr index e2f0368..af09ac3 100644 --- a/src/expansion.cr +++ b/src/expansion.cr @@ -124,6 +124,8 @@ loop do router.handle cmd rescue Game::NotEnoughtResources printf ">>> Not enought resources <<<\n" + rescue Game::InvalidPlaceForBuilding + printf ">>> Can't build here <<<\n" end printf "\n" end diff --git a/src/game/command.cr b/src/game/command.cr index 3022a1d..5af426e 100644 --- a/src/game/command.cr +++ b/src/game/command.cr @@ -14,6 +14,10 @@ module Game end def start(world : World) : Int32 + tile = world.map.get(@point) + if !tile.can_build? + raise InvalidPlaceForBuilding.new + end world.map.set(ConstructionSiteTile.new(@point)) BUILD_TIME end @@ -80,6 +84,10 @@ module Game end def start(world : World) : Int32 + tile = world.map.get(@point) + if !tile.can_build? + raise InvalidPlaceForBuilding.new + end world.resources.dec(ResourceType::Crystal, CRYSTALS_COST) world.map.set(ConstructionSiteTile.new(@point)) BUILD_TIME @@ -141,8 +149,12 @@ module Game end def start(world : World) : Int32 - world.map.set(ConstructionSiteTile.new(@point)) + tile = world.map.get(@point) + if !tile.can_build? + raise InvalidPlaceForBuilding.new + end world.resources.dec(ResourceType::Crystal, CRYSTALS_COST) + world.map.set(ConstructionSiteTile.new(@point)) BUILD_TIME end diff --git a/src/game/exception.cr b/src/game/exception.cr index 2c8e0ab..ba1922f 100644 --- a/src/game/exception.cr +++ b/src/game/exception.cr @@ -1,4 +1,10 @@ module Game - class NotEnoughtResources < Exception + class BaseException < Exception + end + + class NotEnoughtResources < BaseException + end + + class InvalidPlaceForBuilding < BaseException end end diff --git a/src/game/tile.cr b/src/game/tile.cr index a343c37..e78f807 100644 --- a/src/game/tile.cr +++ b/src/game/tile.cr @@ -40,7 +40,7 @@ module Game end def can_build? - @role == TileRole::Plateau + has_role(TileRole::Plateau) end end