Make moving and stashing cost rover charge
This commit is contained in:
parent
8b83672dcc
commit
15c337c067
2 changed files with 75 additions and 0 deletions
|
@ -134,6 +134,25 @@ func (w *World) GetRover(rover string) (Rover, error) {
|
|||
return i, nil
|
||||
}
|
||||
|
||||
// ChargeRover charges up a rover
|
||||
func (w *World) ChargeRover(rover string) (int, error) {
|
||||
w.worldMutex.Lock()
|
||||
defer w.worldMutex.Unlock()
|
||||
|
||||
i, ok := w.Rovers[rover]
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("Failed to find rover with name: %s", rover)
|
||||
}
|
||||
|
||||
// Add one charge
|
||||
if i.Charge < i.MaximumCharge {
|
||||
i.Charge++
|
||||
}
|
||||
w.Rovers[rover] = i
|
||||
|
||||
return i.Charge, nil
|
||||
}
|
||||
|
||||
// DestroyRover Removes an rover from the game
|
||||
func (w *World) DestroyRover(rover string) error {
|
||||
w.worldMutex.Lock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue