Move part of game code to Game namespace
This commit is contained in:
parent
d4b37377b9
commit
ce9d9afd31
@ -4,7 +4,7 @@ require "./../src/game/command"
|
||||
|
||||
macro define_dummy_classes(count)
|
||||
{% for i in (1...count) %}
|
||||
class Test::DummyCommand{{ i }} < Command
|
||||
class Test::DummyCommand{{ i }} < Game::Command
|
||||
def start(world) : Int32
|
||||
end
|
||||
|
||||
|
@ -3,18 +3,18 @@ require "../src/game/world"
|
||||
|
||||
describe "World" do
|
||||
it "should build crystal harvester" do
|
||||
world = World.new
|
||||
world = Game::World.new
|
||||
point = Point.new(2, 3)
|
||||
cmd = BuildCrystalHarvesterCommand.new(point)
|
||||
cmd = Game::BuildCrystalHarvesterCommand.new(point)
|
||||
world.push(cmd)
|
||||
world.run(100)
|
||||
world.map.get(point).has_role(TileRole::CrystalHarvester)
|
||||
end
|
||||
|
||||
it "should fail when not enought resources" do
|
||||
world = World.new
|
||||
world = Game::World.new
|
||||
point = Point.new(2, 3)
|
||||
cmd = BuildCrystalRestorerCommand.new(point)
|
||||
cmd = Game::BuildCrystalRestorerCommand.new(point)
|
||||
expect_raises(NotEnoughtResources) do
|
||||
world.push(cmd)
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ require "./game/resources"
|
||||
require "./game/world"
|
||||
require "./cli/command_router"
|
||||
|
||||
world = World.new
|
||||
world = Game::World.new
|
||||
|
||||
router = CLI::CommandRouter.new
|
||||
|
||||
@ -29,20 +29,20 @@ end
|
||||
router.add "harv {x} {y}" do |p|
|
||||
x = p["x"].to_i32
|
||||
y = p["y"].to_i32
|
||||
world.push(BuildCrystalHarvesterCommand.new(Point.new(x, y)))
|
||||
world.push(Game::BuildCrystalHarvesterCommand.new(Point.new(x, y)))
|
||||
printf "Build harvester at %d %d\n", x, y
|
||||
end
|
||||
|
||||
router.add "rest {x} {y}" do |p|
|
||||
x = p["x"].to_i32
|
||||
y = p["y"].to_i32
|
||||
world.push(BuildCrystalRestorerCommand.new(Point.new(x, y)))
|
||||
world.push(Game::BuildCrystalRestorerCommand.new(Point.new(x, y)))
|
||||
end
|
||||
|
||||
router.add "terr {x} {y}" do |p|
|
||||
x = p["x"].to_i32
|
||||
y = p["y"].to_i32
|
||||
world.push(BuildTerraformerCommand.new(Point.new(x, y)))
|
||||
world.push(Game::BuildTerraformerCommand.new(Point.new(x, y)))
|
||||
end
|
||||
|
||||
def normalize_command(cmd)
|
||||
|
@ -1,5 +1,6 @@
|
||||
require "./tile"
|
||||
|
||||
module Game
|
||||
abstract class Command
|
||||
abstract def start(world : World) : Int32
|
||||
abstract def finish(world : World)
|
||||
@ -147,3 +148,4 @@ class TerraformCommand < Command
|
||||
world.push(TerraformCommand.new(@point))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
class App::Queue
|
||||
struct Item
|
||||
def initialize(@ts : Int32, @command : Command)
|
||||
def initialize(@ts : Int32, @command : Game::Command)
|
||||
end
|
||||
|
||||
getter ts
|
||||
@ -11,7 +11,7 @@ class App::Queue
|
||||
@data = [] of Item
|
||||
end
|
||||
|
||||
def push(ts : Int32, value : Command)
|
||||
def push(ts : Int32, value : Game::Command)
|
||||
# very unoptimal algo
|
||||
@data.push(Item.new(ts, value))
|
||||
@data.sort! do |a, b|
|
||||
|
@ -1,10 +1,9 @@
|
||||
require "./resources"
|
||||
|
||||
class World
|
||||
class Game::World
|
||||
property ts : Int32
|
||||
|
||||
def initialize
|
||||
@ts = 0
|
||||
def initialize(@ts = 0)
|
||||
@map = Map.new
|
||||
@resources = Resources.new
|
||||
@tasks = App::Queue.new
|
||||
|
Loading…
Reference in New Issue
Block a user