Finish moving game components to Game namespace

This commit is contained in:
Anton Vakhrushev
2019-10-04 16:45:42 +03:00
parent ce9d9afd31
commit de5a36d6d6
10 changed files with 193 additions and 187 deletions

View File

@ -2,9 +2,9 @@ require "./spec_helper"
require "./../src/game/map"
require "./../src/game/queue"
describe Point do
p1 = Point.new(0, 0)
p2 = Point.new(5, 5)
describe Game::Point do
p1 = Game::Point.new(0, 0)
p2 = Game::Point.new(5, 5)
it "can calc distance" do
p1.distance(p2).should eq 10
end

View File

@ -16,32 +16,32 @@ end
define_dummy_classes(5)
describe App::Queue do
describe Game::Queue do
it "should pop nil on empty queue" do
queue = App::Queue.new
queue = Game::Queue.new
item = queue.pop(50)
item.should be_nil
end
it "should pop command on one element queue" do
queue = App::Queue.new
queue = Game::Queue.new
queue.push(10, Test::DummyCommand1.new)
item = queue.pop(50)
item.nil?.should be_false
item.as(App::Queue::Item).ts.should eq 10
item.as(App::Queue::Item).command.should be_a(Test::DummyCommand1)
item.as(Game::Queue::Item).ts.should eq 10
item.as(Game::Queue::Item).command.should be_a(Test::DummyCommand1)
end
it "should pop commands in proper order" do
queue = App::Queue.new
queue = Game::Queue.new
queue.push(10, Test::DummyCommand1.new)
queue.push(50, Test::DummyCommand2.new)
queue.push(30, Test::DummyCommand3.new)
item1 = queue.pop(100)
item1.as(App::Queue::Item).command.should be_a(Test::DummyCommand1)
item1.as(Game::Queue::Item).command.should be_a(Test::DummyCommand1)
item2 = queue.pop(100)
item2.as(App::Queue::Item).command.should be_a(Test::DummyCommand3)
item2.as(Game::Queue::Item).command.should be_a(Test::DummyCommand3)
item3 = queue.pop(100)
item3.as(App::Queue::Item).command.should be_a(Test::DummyCommand2)
item3.as(Game::Queue::Item).command.should be_a(Test::DummyCommand2)
end
end

View File

@ -4,18 +4,18 @@ require "../src/game/world"
describe "World" do
it "should build crystal harvester" do
world = Game::World.new
point = Point.new(2, 3)
point = Game::Point.new(2, 3)
cmd = Game::BuildCrystalHarvesterCommand.new(point)
world.push(cmd)
world.run(100)
world.map.get(point).has_role(TileRole::CrystalHarvester)
world.map.get(point).has_role(Game::TileRole::CrystalHarvester)
end
it "should fail when not enought resources" do
world = Game::World.new
point = Point.new(2, 3)
point = Game::Point.new(2, 3)
cmd = Game::BuildCrystalRestorerCommand.new(point)
expect_raises(NotEnoughtResources) do
expect_raises(Game::NotEnoughtResources) do
world.push(cmd)
end
end