diff --git a/src/command.cr b/src/command.cr index 9f4dca3..9ddc219 100644 --- a/src/command.cr +++ b/src/command.cr @@ -16,8 +16,7 @@ class BuildCrystalHarvesterCommand < Command end def finish(world : World) - harverster = CrystalHarvesterTile.new(@point) - world.map.set(harverster) + world.map.set(CrystalHarvesterTile.new(@point)) world.push(HarvestCrystalCommand.new(@point)) end end @@ -45,7 +44,7 @@ class HarvestCrystalCommand < Command end def finish(world : World) - world.resources.add_crystal(@value) + world.resources.inc(ResourceType::Crystal, @value) world.push(HarvestCrystalCommand.new(@point)) end diff --git a/src/expansion.cr b/src/expansion.cr index ee92af6..99adf8e 100644 --- a/src/expansion.cr +++ b/src/expansion.cr @@ -3,16 +3,25 @@ require "./command" require "./map" require "./queue" +enum ResourceType + Crystal + Terraformation +end + class Resources - def initialize(@crystal = 0) + def initialize + @values = {} of ResourceType => Int32 + ResourceType.each do |t| + @values[t] = 0 + end end - def add_crystal(x) - @crystal += x + def [](t : ResourceType) + @values[t] end - def crystal - @crystal + def inc(t : ResourceType, value : Int32) + @values[t] = @values[t] + value end end @@ -64,4 +73,4 @@ w.push(BuildCrystalRestorerCommand.new(Point.new(1, 2))) w.push(BuildCrystalRestorerCommand.new(Point.new(3, 2))) w.run(60) w.map.print -printf "Wood: %d\n", w.resources.crystal +pp w.resources