Check tarraformer
This commit is contained in:
parent
d5af20a2cf
commit
d7c8acaecb
3
Makefile
3
Makefile
@ -6,6 +6,9 @@ build-docker:
|
|||||||
docker pull alpine:edge
|
docker pull alpine:edge
|
||||||
docker build -t $(APP_NAME)-crystal .
|
docker build -t $(APP_NAME)-crystal .
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
|
install: build-docker
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
|
4
WORLD.md
4
WORLD.md
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
## Терраформация:
|
## Терраформация:
|
||||||
|
|
||||||
- Терраформация, 0 - 100%
|
- [x] Терраформация, 0 - 100%
|
||||||
|
|
||||||
## Ресурсы:
|
## Ресурсы:
|
||||||
|
|
||||||
@ -22,7 +22,7 @@
|
|||||||
- [x] Главная база (склад)
|
- [x] Главная база (склад)
|
||||||
- [x] Добыча кристаллов
|
- [x] Добыча кристаллов
|
||||||
- [x] Выращивание кристаллов
|
- [x] Выращивание кристаллов
|
||||||
- [ ] Терраформатор
|
- [x] Терраформатор
|
||||||
|
|
||||||
## Карта
|
## Карта
|
||||||
|
|
||||||
|
@ -128,15 +128,18 @@ class BuildTerraformerCommand < Command
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TerraformCommand < Command
|
class TerraformCommand < Command
|
||||||
|
PRODUCTION_TIME = 60
|
||||||
|
PRODUCTION_VALUE = 5
|
||||||
|
|
||||||
def initialize(@point : Point)
|
def initialize(@point : Point)
|
||||||
end
|
end
|
||||||
|
|
||||||
def start(world : World) : Int32
|
def start(world : World) : Int32
|
||||||
10
|
PRODUCTION_TIME
|
||||||
end
|
end
|
||||||
|
|
||||||
def finish(world : World)
|
def finish(world : World)
|
||||||
world.resources.inc(ResourceType::Terraformation, 5)
|
world.resources.inc(ResourceType::Terraformation, PRODUCTION_VALUE)
|
||||||
world.push(TerraformCommand.new(@point))
|
world.push(TerraformCommand.new(@point))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,15 +26,13 @@ class Resources
|
|||||||
end
|
end
|
||||||
|
|
||||||
class World
|
class World
|
||||||
|
property ts : Int32
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@ts = 0
|
@ts = 0
|
||||||
@resources = Resources.new
|
|
||||||
@map = Map.new
|
@map = Map.new
|
||||||
@queue = App::Queue.new
|
@resources = Resources.new
|
||||||
end
|
@tasks = App::Queue.new
|
||||||
|
|
||||||
private def ts
|
|
||||||
@ts
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def resources
|
def resources
|
||||||
@ -49,12 +47,12 @@ class World
|
|||||||
dur = command.start(self)
|
dur = command.start(self)
|
||||||
done_at = @ts + dur
|
done_at = @ts + dur
|
||||||
printf "world : %d : plan `%s` at %d\n", @ts, typeof(command), done_at
|
printf "world : %d : plan `%s` at %d\n", @ts, typeof(command), done_at
|
||||||
@queue.push(done_at, command)
|
@tasks.push(done_at, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(ts : Int32)
|
def run(ts : Int32)
|
||||||
loop do
|
loop do
|
||||||
item = @queue.pop(ts)
|
item = @tasks.pop(ts)
|
||||||
if item.nil?
|
if item.nil?
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -71,6 +69,6 @@ w.map.print
|
|||||||
w.push(BuildCrystalHarvesterCommand.new(Point.new(2, 3)))
|
w.push(BuildCrystalHarvesterCommand.new(Point.new(2, 3)))
|
||||||
w.push(BuildCrystalRestorerCommand.new(Point.new(1, 2)))
|
w.push(BuildCrystalRestorerCommand.new(Point.new(1, 2)))
|
||||||
w.push(BuildTerraformerCommand.new(Point.new(3, 2)))
|
w.push(BuildTerraformerCommand.new(Point.new(3, 2)))
|
||||||
w.run(240)
|
w.run(2000)
|
||||||
w.map.print
|
w.map.print
|
||||||
pp w.resources
|
pp w.resources
|
||||||
|
Loading…
Reference in New Issue
Block a user