Fix score calculation

This commit is contained in:
Anton Vakhrushev 2019-10-08 21:11:17 +03:00
parent 5f9abcbddf
commit 47d6857dd7
3 changed files with 10 additions and 16 deletions

View File

@ -15,14 +15,14 @@ router.add "harv {x} {y}", "Build harvester at x,y" do |p|
printf "Build harvester at %d %d\n", x, y printf "Build harvester at %d %d\n", x, y
end end
router.add "rest {x} {y}", "Build restorer at x,y" do |p| router.add "rest {x} {y}", "Build restorer at x,y (100 cr)" do |p|
x = p["x"].to_i32 x = p["x"].to_i32
y = p["y"].to_i32 y = p["y"].to_i32
point = Game::Point.new(x, y) point = Game::Point.new(x, y)
world.push(Game::BuildCrystalRestorerCommand.new(point)) world.push(Game::BuildCrystalRestorerCommand.new(point))
end end
router.add "terr {x} {y}", "Build terraformator at x,y" do |p| router.add "terr {x} {y}", "Build terraformator at x,y (300 cr)" do |p|
x = p["x"].to_i32 x = p["x"].to_i32
y = p["y"].to_i32 y = p["y"].to_i32
point = Game::Point.new(x, y) point = Game::Point.new(x, y)

View File

@ -142,7 +142,7 @@ module Game
end end
class BuildTerraformerCommand < Command class BuildTerraformerCommand < Command
CRYSTALS_COST = 100 CRYSTALS_COST = 300
BUILD_TIME = 120 BUILD_TIME = 120
def initialize(@point : Point) def initialize(@point : Point)

View File

@ -2,19 +2,21 @@ require "./resources"
class Game::World class Game::World
property ts : Int64 property ts : Int64
property win_ts : Int64?
def initialize(@ts = 0_i64) def initialize(@ts = 0_i64)
@start_ts = @ts
@map = Map.new @map = Map.new
@resources = Resources.new @resources = Resources.new
@queue = Queue.new @queue = Queue.new
@finished = false
@score = 0
end end
getter ts getter ts
getter resources getter resources
getter map getter map
getter queue getter queue
getter win_ts getter score
def push(command : Command) def push(command : Command)
dur = command.start(self) dur = command.start(self)
@ -31,8 +33,9 @@ class Game::World
command = item.command command = item.command
@ts = item.ts @ts = item.ts
command.finish(self) command.finish(self)
if win? if win? && !@finished
@win_ts = @ts @finished = true
@score = Math.max(0, (@start_ts + 3600 - @ts).to_i32)
end end
end end
@ts = ts @ts = ts
@ -41,13 +44,4 @@ class Game::World
def win? def win?
@resources[ResourceType::Terraformation] >= 100 @resources[ResourceType::Terraformation] >= 100
end end
def score
case @win_ts
when Int64
Math.max(0, 3600_i64 - @win_ts.as(Int64))
else
0
end
end
end end