Add MaximumIntegrity to the rover
This commit is contained in:
parent
2eaed1447d
commit
b066277ddf
7 changed files with 88 additions and 50 deletions
|
@ -24,4 +24,7 @@ type Rover struct {
|
|||
|
||||
// Integrity represents current rover health
|
||||
Integrity int `json:"integrity"`
|
||||
|
||||
// MaximumIntegrity is the full integrity of the rover
|
||||
MaximumIntegrity int `json:"maximum-integrity"`
|
||||
}
|
||||
|
|
|
@ -75,10 +75,11 @@ func (w *World) SpawnRover() (string, error) {
|
|||
|
||||
// Initialise the rover
|
||||
rover := Rover{
|
||||
Range: 4.0,
|
||||
Integrity: 10,
|
||||
Capacity: 10,
|
||||
Name: uuid.New().String(),
|
||||
Range: 4.0,
|
||||
Integrity: 10,
|
||||
MaximumIntegrity: 10,
|
||||
Capacity: 10,
|
||||
Name: uuid.New().String(),
|
||||
}
|
||||
|
||||
// Assign a random name if we have words
|
||||
|
@ -417,8 +418,8 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Consume an inventory item to repair
|
||||
if len(r.Inventory) > 0 {
|
||||
// Consume an inventory item to repair if possible
|
||||
if len(r.Inventory) > 0 && r.Integrity < r.MaximumIntegrity {
|
||||
r.Inventory = r.Inventory[:len(r.Inventory)-1]
|
||||
r.Integrity = r.Integrity + 1
|
||||
w.Rovers[rover] = r
|
||||
|
|
|
@ -217,14 +217,15 @@ func TestWorld_RoverRepair(t *testing.T) {
|
|||
originalInfo, err := world.GetRover(a)
|
||||
assert.NoError(t, err, "couldn't get rover info")
|
||||
|
||||
// Pick up something to repair with
|
||||
world.Atlas.SetObject(pos, objects.Object{Type: objects.SmallRock})
|
||||
|
||||
o, err := world.RoverStash(a)
|
||||
assert.NoError(t, err, "Failed to stash")
|
||||
assert.Equal(t, objects.SmallRock, o, "Failed to get correct object")
|
||||
|
||||
world.Atlas.SetObject(vector.Vector{X: 0.0, Y: 1.0}, objects.Object{Type: objects.LargeRock})
|
||||
|
||||
// Try and bump into the rock
|
||||
vec, err := world.MoveRover(a, bearing.North)
|
||||
assert.NoError(t, err, "Failed to move rover")
|
||||
assert.Equal(t, pos, vec, "Rover managed to move into large rock")
|
||||
|
@ -239,4 +240,17 @@ func TestWorld_RoverRepair(t *testing.T) {
|
|||
newinfo, err = world.GetRover(a)
|
||||
assert.NoError(t, err, "couldn't get rover info")
|
||||
assert.Equal(t, originalInfo.Integrity, newinfo.Integrity, "rover should have gained integrity")
|
||||
|
||||
// Check again that it can't repair past the max
|
||||
world.Atlas.SetObject(pos, objects.Object{Type: objects.SmallRock})
|
||||
o, err = world.RoverStash(a)
|
||||
assert.NoError(t, err, "Failed to stash")
|
||||
assert.Equal(t, objects.SmallRock, o, "Failed to get correct object")
|
||||
|
||||
err = world.ExecuteCommand(&Command{Command: CommandRepair}, a)
|
||||
assert.NoError(t, err, "Failed to repair rover")
|
||||
|
||||
newinfo, err = world.GetRover(a)
|
||||
assert.NoError(t, err, "couldn't get rover info")
|
||||
assert.Equal(t, originalInfo.Integrity, newinfo.Integrity, "rover should have kept the same integrity")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue