diff --git a/src/game/command.cr b/src/game/command.cr index 06ba305..4a4b2f0 100644 --- a/src/game/command.cr +++ b/src/game/command.cr @@ -13,6 +13,7 @@ module Game end def start(world : World) : Int32 + world.map.set(ConstructionSiteTile.new(@point)) BUILD_TIME end @@ -71,6 +72,7 @@ module Game def start(world : World) : Int32 world.resources.dec(ResourceType::Crystal, CRYSTALS_COST) + world.map.set(ConstructionSiteTile.new(@point)) BUILD_TIME end @@ -122,6 +124,7 @@ module Game end def start(world : World) : Int32 + world.map.set(ConstructionSiteTile.new(@point)) world.resources.dec(ResourceType::Crystal, CRYSTALS_COST) BUILD_TIME end diff --git a/src/game/map.cr b/src/game/map.cr index cda262b..9dec3b2 100644 --- a/src/game/map.cr +++ b/src/game/map.cr @@ -39,7 +39,7 @@ module Game end def get(x : Int32, y : Int32) : Tile - @data[key(Point.new(x, y))] + get(Point.new(x, y)) end def set(tile : Tile) @@ -75,15 +75,6 @@ module Game seek_tile end - def print - (0...SIZE).each do |x| - (0...SIZE).each do |y| - printf "%c", @data[key(Point.new(x, y))].letter - end - printf "\n" - end - end - private def key(p : Point) : String return sprintf "%d:%d", p.x, p.y end diff --git a/src/game/tile.cr b/src/game/tile.cr index 2120ac2..a343c37 100644 --- a/src/game/tile.cr +++ b/src/game/tile.cr @@ -1,5 +1,6 @@ module Game enum TileRole + ConstructionSite CrystalDeposits CrystalHarvester CrystalRestorer @@ -37,6 +38,10 @@ module Game charged = @cur + value @cur = charged <= @cap ? charged : @cap end + + def can_build? + @role == TileRole::Plateau + end end class PlateauTile < Tile @@ -49,6 +54,16 @@ module Game end end + class ConstructionSiteTile < Tile + def letter : Char + '_' + end + + def has_role(role : TileRole) : Bool + role == TileRole::ConstructionSite + end + end + class MainBaseTile < Tile def letter : Char 'H'