Add build place checking

This commit is contained in:
Anton Vakhrushev 2019-10-08 16:17:24 +03:00
parent f1c36ecc40
commit ae3e220dfa
4 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,10 @@
module Game
class NotEnoughtResources < Exception
class BaseException < Exception
end
class NotEnoughtResources < BaseException
end
class InvalidPlaceForBuilding < BaseException
end
end

View File

@ -40,7 +40,7 @@ module Game
end
def can_build?
@role == TileRole::Plateau
has_role(TileRole::Plateau)
end
end