Rewrite mine command
This commit is contained in:
@ -3,16 +3,36 @@ require "./spec_helper"
|
||||
module Game::TestCommand
|
||||
extend self
|
||||
|
||||
def create_map_2x2 : Map
|
||||
def create_empty_map_2x2 : Map
|
||||
Map.new 2, 2
|
||||
end
|
||||
|
||||
def create_map_with_resource : Map
|
||||
map = Map.new 2, 2
|
||||
map.set(MainBaseTile.new(Point.new(0, 0)))
|
||||
map.set(CrystalTile.new(Point.new(1, 1), 100))
|
||||
map.set BuildingTile.new(
|
||||
Point.new(0, 0),
|
||||
Building.new(
|
||||
Building::Type::StartPoint,
|
||||
storage: 200
|
||||
)
|
||||
)
|
||||
map.set DepositTile.new(
|
||||
Point.new(1, 1),
|
||||
Deposit.new(Resource::Type::Crystals, 100)
|
||||
)
|
||||
map.set BuildingTile.new(
|
||||
Point.new(0, 1),
|
||||
Building.new(
|
||||
Building::Type::CrystalMiner,
|
||||
mining: Mining.new(20, Resource.new(Resource::Type::Crystals, 40))
|
||||
)
|
||||
)
|
||||
map
|
||||
end
|
||||
|
||||
describe Command do
|
||||
it "should complete build command" do
|
||||
world = World.new create_map_2x2
|
||||
world = World.new create_empty_map_2x2
|
||||
point = Point.new 1, 0
|
||||
building = Building.new Building::Type::StartPoint, **{
|
||||
construction: Construction.free 10,
|
||||
@ -27,7 +47,7 @@ module Game::TestCommand
|
||||
end
|
||||
|
||||
it "should restrict building if not enought resources" do
|
||||
world = World.new create_map_2x2
|
||||
world = World.new create_empty_map_2x2
|
||||
point = Point.new 1, 0
|
||||
building = Building.new Building::Type::StartPoint, **{
|
||||
construction: Construction.new(
|
||||
@ -42,5 +62,13 @@ module Game::TestCommand
|
||||
world.push(command)
|
||||
end
|
||||
end
|
||||
|
||||
it "should complete mining command" do
|
||||
world = World.new create_map_with_resource
|
||||
command = MineCommand.new Point.new(0, 1)
|
||||
world.push command
|
||||
world.run 20
|
||||
world.resources[Resource::Type::Crystals].should eq 40
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -16,23 +16,26 @@ module Game::Test
|
||||
|
||||
it "should be decreased with span" do
|
||||
dep = Deposit.new(Resource::Type::Crystals, 100)
|
||||
dep.dec Resource.new(Resource::Type::Crystals, 20)
|
||||
res = dep.dec Resource.new(Resource::Type::Crystals, 20)
|
||||
dep.cap.should eq 100
|
||||
dep.cur.should eq 80
|
||||
res.amount.should eq 20
|
||||
end
|
||||
|
||||
it "should not be increased above capacity" do
|
||||
dep = Deposit.new(Resource::Type::Crystals, 100, 20)
|
||||
dep.inc Resource.new(Resource::Type::Crystals, 100)
|
||||
res = dep.inc Resource.new(Resource::Type::Crystals, 100)
|
||||
dep.cap.should eq 100
|
||||
dep.cur.should eq 100
|
||||
res.amount.should eq 80
|
||||
end
|
||||
|
||||
it "should not be decreased below zero" do
|
||||
dep = Deposit.new(Resource::Type::Crystals, 100)
|
||||
dep.dec Resource.new(Resource::Type::Crystals, 120)
|
||||
res = dep.dec Resource.new(Resource::Type::Crystals, 120)
|
||||
dep.cap.should eq 100
|
||||
dep.cur.should eq 0
|
||||
res.amount.should eq 100
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user