Check tarraformer

This commit is contained in:
Anton Vakhrushev 2019-09-27 15:06:49 +03:00
parent d5af20a2cf
commit d7c8acaecb
4 changed files with 17 additions and 13 deletions

View File

@ -6,6 +6,9 @@ build-docker:
docker pull alpine:edge
docker build -t $(APP_NAME)-crystal .
.PHONY: install
install: build-docker
.PHONY: build
build:
mkdir -p build

View File

@ -9,7 +9,7 @@
## Терраформация:
- Терраформация, 0 - 100%
- [x] Терраформация, 0 - 100%
## Ресурсы:
@ -22,7 +22,7 @@
- [x] Главная база (склад)
- [x] Добыча кристаллов
- [x] Выращивание кристаллов
- [ ] Терраформатор
- [x] Терраформатор
## Карта

View File

@ -128,15 +128,18 @@ class BuildTerraformerCommand < Command
end
class TerraformCommand < Command
PRODUCTION_TIME = 60
PRODUCTION_VALUE = 5
def initialize(@point : Point)
end
def start(world : World) : Int32
10
PRODUCTION_TIME
end
def finish(world : World)
world.resources.inc(ResourceType::Terraformation, 5)
world.resources.inc(ResourceType::Terraformation, PRODUCTION_VALUE)
world.push(TerraformCommand.new(@point))
end
end

View File

@ -26,15 +26,13 @@ class Resources
end
class World
property ts : Int32
def initialize
@ts = 0
@resources = Resources.new
@map = Map.new
@queue = App::Queue.new
end
private def ts
@ts
@resources = Resources.new
@tasks = App::Queue.new
end
def resources
@ -49,12 +47,12 @@ class World
dur = command.start(self)
done_at = @ts + dur
printf "world : %d : plan `%s` at %d\n", @ts, typeof(command), done_at
@queue.push(done_at, command)
@tasks.push(done_at, command)
end
def run(ts : Int32)
loop do
item = @queue.pop(ts)
item = @tasks.pop(ts)
if item.nil?
break
end
@ -71,6 +69,6 @@ w.map.print
w.push(BuildCrystalHarvesterCommand.new(Point.new(2, 3)))
w.push(BuildCrystalRestorerCommand.new(Point.new(1, 2)))
w.push(BuildTerraformerCommand.new(Point.new(3, 2)))
w.run(240)
w.run(2000)
w.map.print
pp w.resources