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

@ -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
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
y = p["y"].to_i32
point = Game::Point.new(x, y)
world.push(Game::BuildCrystalRestorerCommand.new(point))
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
y = p["y"].to_i32
point = Game::Point.new(x, y)

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

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