Add score calculation
This commit is contained in:
parent
bc57cae1e1
commit
5f9abcbddf
@ -108,7 +108,7 @@ end
|
||||
def render_world(world)
|
||||
printf "Now:\n %s\n\n", render_time(world.ts)
|
||||
if world.win?
|
||||
printf "YOU WIN!!!\n\n"
|
||||
printf "YOU WIN!!! Score: %d\n\n", world.score
|
||||
end
|
||||
render_commands world
|
||||
printf "\n"
|
||||
|
@ -2,6 +2,7 @@ require "./resources"
|
||||
|
||||
class Game::World
|
||||
property ts : Int64
|
||||
property win_ts : Int64?
|
||||
|
||||
def initialize(@ts = 0_i64)
|
||||
@map = Map.new
|
||||
@ -13,6 +14,7 @@ class Game::World
|
||||
getter resources
|
||||
getter map
|
||||
getter queue
|
||||
getter win_ts
|
||||
|
||||
def push(command : Command)
|
||||
dur = command.start(self)
|
||||
@ -29,6 +31,9 @@ class Game::World
|
||||
command = item.command
|
||||
@ts = item.ts
|
||||
command.finish(self)
|
||||
if win?
|
||||
@win_ts = @ts
|
||||
end
|
||||
end
|
||||
@ts = ts
|
||||
end
|
||||
@ -36,4 +41,13 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user