Refactoring: buildings
This commit is contained in:
21
spec/building_spec.cr
Normal file
21
spec/building_spec.cr
Normal file
@ -0,0 +1,21 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe Game::Building do
|
||||
it "should create storehouse" do
|
||||
bg = Game::Building.new Game::Building::Type::Storehouse, "Storehouse", storage: 100
|
||||
bg.storage.should eq 100
|
||||
end
|
||||
|
||||
it "should create crystal miner" do
|
||||
bg = Game::Building.new Game::Building::Type::CrystalMiner, "Cryslal Miner", **{
|
||||
production: Game::Production.new(
|
||||
ts: 20,
|
||||
input: Game::Resources.new,
|
||||
output: Game::Resources.new({
|
||||
Game::Resources::Type::Crystals => 100,
|
||||
})
|
||||
),
|
||||
}
|
||||
bg.production.as(Game::Production).ts.should eq 20
|
||||
end
|
||||
end
|
18
spec/command_spec.cr
Normal file
18
spec/command_spec.cr
Normal file
@ -0,0 +1,18 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe Game::Command do
|
||||
it "should complete build command" do
|
||||
world = Game::World.new create_map_2x2
|
||||
point = Game::Point.new 1, 0
|
||||
building = Game::Building.new Game::Building::Type::StartPoint, "Dummy", **{
|
||||
construction: Game::Construction.free 10,
|
||||
}
|
||||
command = Game::BuildCommand.new point, building
|
||||
world.push command
|
||||
tile = world.map.get point
|
||||
tile.should be_a(Game::ConstructionSiteTile)
|
||||
world.run 10
|
||||
tile = world.map.get point
|
||||
tile.should be_a(Game::BuildingTile)
|
||||
end
|
||||
end
|
@ -1,8 +1,29 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe Game::Resources do
|
||||
it "should be created from hash" do
|
||||
res = Game::Resources.new({Game::Resources::Type::Crystals => 100})
|
||||
res[Game::Resources::Type::Crystals].should eq 100
|
||||
module Test::GameResources
|
||||
alias Res = Game::Resources
|
||||
alias ResType = Game::Resources::Type
|
||||
|
||||
describe Game::Resources do
|
||||
it "should be created from hash" do
|
||||
res = Res.new({ResType::Crystals => 100})
|
||||
res[ResType::Crystals].should eq 100
|
||||
end
|
||||
|
||||
it "should check single type" do
|
||||
res = Res.new({ResType::Crystals => 100})
|
||||
res.has(ResType::Crystals, 100).should be_true
|
||||
end
|
||||
|
||||
it "should check resource bag" do
|
||||
res = Res.new({ResType::Crystals => 100})
|
||||
res.has({ResType::Crystals => 50}).should be_true
|
||||
res.has({ResType::Crystals => 150}).should be_false
|
||||
end
|
||||
|
||||
it "should check empty value" do
|
||||
res = Res.new
|
||||
res.has({ResType::Crystals => 50}).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user