Add supports feat
This commit is contained in:
parent
64e27f916d
commit
5a717b5961
@ -21,10 +21,15 @@ abstract class Command
|
|||||||
@ts
|
@ts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
abstract def supports?(world : World) : Bool
|
||||||
abstract def run(world : World)
|
abstract def run(world : World)
|
||||||
end
|
end
|
||||||
|
|
||||||
class BuildMillCommand < Command
|
class BuildMillCommand < Command
|
||||||
|
def supports?(world : World) : Bool
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
def run(world : World)
|
def run(world : World)
|
||||||
puts "build mill"
|
puts "build mill"
|
||||||
c = GetWoodCommand.new(@ts + 5)
|
c = GetWoodCommand.new(@ts + 5)
|
||||||
@ -33,6 +38,10 @@ class BuildMillCommand < Command
|
|||||||
end
|
end
|
||||||
|
|
||||||
class GetWoodCommand < Command
|
class GetWoodCommand < Command
|
||||||
|
def supports?(world : World) : Bool
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
def run(world : World)
|
def run(world : World)
|
||||||
res = world.resources
|
res = world.resources
|
||||||
res.add_wood(10)
|
res.add_wood(10)
|
||||||
@ -52,12 +61,16 @@ class World
|
|||||||
@resources
|
@resources
|
||||||
end
|
end
|
||||||
|
|
||||||
def push(command : Command)
|
def push(command : Command) : Bool
|
||||||
|
if !command.supports?(self)
|
||||||
|
return false
|
||||||
|
end
|
||||||
printf "push command %d\n", command.ts
|
printf "push command %d\n", command.ts
|
||||||
@queue.push(command)
|
@queue.push(command)
|
||||||
@queue.sort! do |c|
|
@queue.sort! do |c|
|
||||||
-c.ts
|
-c.ts
|
||||||
end
|
end
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(ts : Int32)
|
def run(ts : Int32)
|
||||||
|
Loading…
Reference in New Issue
Block a user