Add build place checking
This commit is contained in:
parent
f1c36ecc40
commit
ae3e220dfa
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,4 +1,10 @@
|
||||
module Game
|
||||
class NotEnoughtResources < Exception
|
||||
class BaseException < Exception
|
||||
end
|
||||
|
||||
class NotEnoughtResources < BaseException
|
||||
end
|
||||
|
||||
class InvalidPlaceForBuilding < BaseException
|
||||
end
|
||||
end
|
||||
|
@ -40,7 +40,7 @@ module Game
|
||||
end
|
||||
|
||||
def can_build?
|
||||
@role == TileRole::Plateau
|
||||
has_role(TileRole::Plateau)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user