Add build place checking
This commit is contained in:
parent
f1c36ecc40
commit
ae3e220dfa
@ -124,6 +124,8 @@ loop do
|
|||||||
router.handle cmd
|
router.handle cmd
|
||||||
rescue Game::NotEnoughtResources
|
rescue Game::NotEnoughtResources
|
||||||
printf ">>> Not enought resources <<<\n"
|
printf ">>> Not enought resources <<<\n"
|
||||||
|
rescue Game::InvalidPlaceForBuilding
|
||||||
|
printf ">>> Can't build here <<<\n"
|
||||||
end
|
end
|
||||||
printf "\n"
|
printf "\n"
|
||||||
end
|
end
|
||||||
|
@ -14,6 +14,10 @@ module Game
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start(world : World) : Int32
|
def start(world : World) : Int32
|
||||||
|
tile = world.map.get(@point)
|
||||||
|
if !tile.can_build?
|
||||||
|
raise InvalidPlaceForBuilding.new
|
||||||
|
end
|
||||||
world.map.set(ConstructionSiteTile.new(@point))
|
world.map.set(ConstructionSiteTile.new(@point))
|
||||||
BUILD_TIME
|
BUILD_TIME
|
||||||
end
|
end
|
||||||
@ -80,6 +84,10 @@ module Game
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start(world : World) : Int32
|
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.resources.dec(ResourceType::Crystal, CRYSTALS_COST)
|
||||||
world.map.set(ConstructionSiteTile.new(@point))
|
world.map.set(ConstructionSiteTile.new(@point))
|
||||||
BUILD_TIME
|
BUILD_TIME
|
||||||
@ -141,8 +149,12 @@ module Game
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start(world : World) : Int32
|
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.resources.dec(ResourceType::Crystal, CRYSTALS_COST)
|
||||||
|
world.map.set(ConstructionSiteTile.new(@point))
|
||||||
BUILD_TIME
|
BUILD_TIME
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
module Game
|
module Game
|
||||||
class NotEnoughtResources < Exception
|
class BaseException < Exception
|
||||||
|
end
|
||||||
|
|
||||||
|
class NotEnoughtResources < BaseException
|
||||||
|
end
|
||||||
|
|
||||||
|
class InvalidPlaceForBuilding < BaseException
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -40,7 +40,7 @@ module Game
|
|||||||
end
|
end
|
||||||
|
|
||||||
def can_build?
|
def can_build?
|
||||||
@role == TileRole::Plateau
|
has_role(TileRole::Plateau)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user