Add restore command
This commit is contained in:
@ -18,13 +18,26 @@ module Game::TestCommand
|
||||
)
|
||||
map.set DepositTile.new(
|
||||
Point.new(1, 1),
|
||||
Deposit.new(Resource::Type::Crystals, 100)
|
||||
Deposit.new(Resource::Type::Crystals, 1000, 500)
|
||||
)
|
||||
map.set DepositTile.new(
|
||||
Point.new(1, 0),
|
||||
Deposit.new(Resource::Type::Crystals, 1000, 0)
|
||||
)
|
||||
map.set BuildingTile.new(
|
||||
Point.new(0, 1),
|
||||
Building.new(
|
||||
Building::Type::CrystalMiner,
|
||||
mining: Mining.new(20, Resource.new(Resource::Type::Crystals, 40))
|
||||
mining: Mining.new(
|
||||
ts: 20,
|
||||
resource: Resource.new(Resource::Type::Crystals, 40),
|
||||
input: ResourceBag.new
|
||||
),
|
||||
restoration: Mining.new(
|
||||
ts: 20,
|
||||
resource: Resource.new(Resource::Type::Crystals, 40),
|
||||
input: ResourceBag.new({Resource::Type::Crystals => 5})
|
||||
)
|
||||
)
|
||||
)
|
||||
map
|
||||
@ -65,10 +78,27 @@ module Game::TestCommand
|
||||
|
||||
it "should complete mining command" do
|
||||
world = World.new create_map_with_resource
|
||||
command = MineCommand.new Point.new(0, 1)
|
||||
command = MineCommand.new Point.new(0, 1), once: true
|
||||
world.push command
|
||||
world.run 20
|
||||
# Check world resources
|
||||
world.resources[Resource::Type::Crystals].should eq 40
|
||||
# Check tile deposit
|
||||
tile = world.map.get(1, 1).as(DepositTile)
|
||||
tile.dep.cur.should eq 460
|
||||
end
|
||||
|
||||
it "should complete restore command" do
|
||||
world = World.new create_map_with_resource
|
||||
world.resources.inc(Resource::Type::Crystals, 20)
|
||||
command = RestoreCommand.new Point.new(0, 1), once: true
|
||||
world.push command
|
||||
world.run 20
|
||||
# Check world resources
|
||||
world.resources[Resource::Type::Crystals].should eq 15
|
||||
# Check tile deposit
|
||||
tile = world.map.get(1, 0).as(DepositTile)
|
||||
tile.dep.cur.should eq 40
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,5 +25,29 @@ module Game::TestResourceBag
|
||||
res = Res.new
|
||||
res.has({ResType::Crystals => 50}).should be_false
|
||||
end
|
||||
|
||||
it "should inc single value" do
|
||||
res = Res.new ({ResType::Crystals => 10})
|
||||
res.inc ResType::Crystals, 5
|
||||
res[ResType::Crystals].should eq 15
|
||||
end
|
||||
|
||||
it "should inc resource" do
|
||||
res = Res.new ({ResType::Crystals => 10})
|
||||
res.inc Resource.new(ResType::Crystals, 5)
|
||||
res[ResType::Crystals].should eq 15
|
||||
end
|
||||
|
||||
it "should inc hash" do
|
||||
res = Res.new ({ResType::Crystals => 10})
|
||||
res.inc ({ResType::Crystals => 5})
|
||||
res[ResType::Crystals].should eq 15
|
||||
end
|
||||
|
||||
it "should inc other bag" do
|
||||
res = Res.new ({ResType::Crystals => 10})
|
||||
res.inc Res.new({ResType::Crystals => 5})
|
||||
res[ResType::Crystals].should eq 15
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user