implement Direction

trunk
nate smith 2023-05-09 19:31:02 -07:00
parent 8fd8331a96
commit 3bb94c490e
1 changed files with 52 additions and 7 deletions

View File

@ -14,18 +14,63 @@ type Direction struct {
}
func (d Direction) Reverse() Direction {
// TODO
return Direction{}
raw := ""
switch d.raw {
case dirAbove:
raw = dirBelow
case dirBelow:
raw = dirAbove
case dirEast:
raw = dirWest
case dirWest:
raw = dirEast
case dirNorth:
raw = dirSouth
case dirSouth:
raw = dirNorth
}
return Direction{raw: raw}
}
// NormalizeHuman takes a direction someone might type like "up" or "north" and returns the correct Direction struct
func NormalizeHuman(humanDir string) Direction {
// TODO
return Direction{}
raw := ""
switch humanDir {
case "up":
case "above":
raw = dirAbove
case "down":
case "below":
raw = dirBelow
case "east":
raw = dirEast
case "west":
raw = dirWest
case "north":
raw = dirNorth
case "south":
raw = dirSouth
}
return Direction{raw: raw}
}
// Human returns a string form of this direction like "above" or "north"
func (d Direction) Human() string {
// TODO
return ""
func (d Direction) Human() (humanDir string) {
switch d.raw {
case dirAbove:
humanDir = "above"
case dirBelow:
humanDir = "below"
case dirEast:
humanDir = "east"
case dirWest:
humanDir = "west"
case dirNorth:
humanDir = "north"
case dirSouth:
humanDir = "south"
}
return humanDir
}