Move to tile roles
This commit is contained in:
parent
6df32784a8
commit
24d0eb4b81
@ -51,13 +51,13 @@ class HarvestCrystalCommand < Command
|
||||
|
||||
private def nearest_deposit(world : World)
|
||||
world.map.nearest_tile @point do |tile|
|
||||
tile.type == TileType::CrystalDeposits && tile.cur > 0
|
||||
tile.has_role(TileRole::CrystalDeposits) && tile.cur > 0
|
||||
end
|
||||
end
|
||||
|
||||
private def nearest_stock(world : World)
|
||||
world.map.nearest_tile @point do |tile|
|
||||
tile.type == TileType::Warehouse
|
||||
tile.has_role(TileRole::Warehouse)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -108,7 +108,7 @@ class RestoreCrystalCommand < Command
|
||||
|
||||
private def nearest_deposit(world : World)
|
||||
world.map.nearest_tile @point do |tile|
|
||||
tile.type == TileType::CrystalDeposits && tile.cur < tile.cap
|
||||
tile.has_role(TileRole::CrystalDeposits) && tile.cur < tile.cap
|
||||
end
|
||||
end
|
||||
end
|
||||
|
24
src/tile.cr
24
src/tile.cr
@ -1,4 +1,4 @@
|
||||
enum TileType
|
||||
enum TileRole
|
||||
CrystalDeposits
|
||||
CrystalHarvester
|
||||
CrystalRestorer
|
||||
@ -18,7 +18,7 @@ abstract class Tile
|
||||
getter cur
|
||||
|
||||
abstract def letter : Char
|
||||
abstract def type : TileType
|
||||
abstract def has_role(role : TileRole) : Bool
|
||||
|
||||
def withdraw(value)
|
||||
if value >= @cur
|
||||
@ -42,8 +42,8 @@ class PlateauTile < Tile
|
||||
'.'
|
||||
end
|
||||
|
||||
def type : TileType
|
||||
TileType::Plateau
|
||||
def has_role(role : TileRole) : Bool
|
||||
role == TileRole::Plateau
|
||||
end
|
||||
end
|
||||
|
||||
@ -52,8 +52,8 @@ class MainBaseTile < Tile
|
||||
'H'
|
||||
end
|
||||
|
||||
def type : TileType
|
||||
TileType::Warehouse
|
||||
def has_role(role : TileRole) : Bool
|
||||
role == TileRole::Warehouse
|
||||
end
|
||||
end
|
||||
|
||||
@ -67,8 +67,8 @@ class CrystalTile < Tile
|
||||
'f'
|
||||
end
|
||||
|
||||
def type : TileType
|
||||
TileType::CrystalDeposits
|
||||
def has_role(role : TileRole) : Bool
|
||||
role == TileRole::CrystalDeposits
|
||||
end
|
||||
end
|
||||
|
||||
@ -77,8 +77,8 @@ class CrystalHarvesterTile < Tile
|
||||
'm'
|
||||
end
|
||||
|
||||
def type : TileType
|
||||
TileType::CrystalHarvester
|
||||
def has_role(role : TileRole) : Bool
|
||||
role == TileRole::CrystalHarvester
|
||||
end
|
||||
end
|
||||
|
||||
@ -87,7 +87,7 @@ class CrystalRestorerTile < Tile
|
||||
'h'
|
||||
end
|
||||
|
||||
def type : TileType
|
||||
TileType::CrystalRestorer
|
||||
def has_role(role : TileRole) : Bool
|
||||
role == TileRole::CrystalRestorer
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user