Simplify duplicate command types

This commit is contained in:
Marc Di Luzio 2020-06-06 12:45:45 +01:00
parent 97d3583384
commit e3ce87e964
8 changed files with 28 additions and 56 deletions

View file

@ -1,14 +1,14 @@
package game
import "github.com/google/uuid"
const (
CommandMove = "move"
)
// A command is simply a function that acts on the a given rover in the world
type Command func() error
// Command represends a single command to execute
type Command struct {
Command string `json:"command"`
// CommandMove will move the rover in question
func (w *World) CommandMove(id uuid.UUID, bearing Direction, duration int) Command {
return func() error {
_, err := w.MoveRover(id, bearing, duration)
return err
}
// Used in the move command
Bearing string `json:"bearing,omitempty"`
Duration int `json:"duration,omitempty"`
}