From 47d6857dd777e6dc49928abdd12a32a7c4c1d716 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Tue, 8 Oct 2019 21:11:17 +0300 Subject: [PATCH] Fix score calculation --- src/expansion.cr | 4 ++-- src/game/command.cr | 2 +- src/game/world.cr | 20 +++++++------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/expansion.cr b/src/expansion.cr index 811405b..11a997a 100644 --- a/src/expansion.cr +++ b/src/expansion.cr @@ -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) diff --git a/src/game/command.cr b/src/game/command.cr index 5af426e..e72631b 100644 --- a/src/game/command.cr +++ b/src/game/command.cr @@ -142,7 +142,7 @@ module Game end class BuildTerraformerCommand < Command - CRYSTALS_COST = 100 + CRYSTALS_COST = 300 BUILD_TIME = 120 def initialize(@point : Point) diff --git a/src/game/world.cr b/src/game/world.cr index 459b1dc..a87c697 100644 --- a/src/game/world.cr +++ b/src/game/world.cr @@ -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