59 lines
859 B
Go

package actions
import (
"dk/internal/control"
"dk/internal/towns"
"dk/internal/users"
"fmt"
)
type Direction int
const (
North Direction = iota
East
South
West
)
func (d Direction) String() string {
switch d {
case North:
return "North"
case East:
return "East"
case South:
return "South"
case West:
return "West"
default:
return "Unknown"
}
}
func Move(user *users.User, dir Direction) (string, int, int, error) {
control := control.Get()
newX, newY := user.X, user.Y
switch dir {
case North:
newY++
case East:
newX++
case South:
newY--
case West:
newX--
}
if !control.IsWithinWorldBounds(newX, newY) {
return user.Currently, user.X, user.Y, fmt.Errorf("You've hit the edge of the world.")
}
if towns.ExistsAt(newX, newY) {
return "In Town", newX, newY, nil
}
return "Exploring", newX, newY, nil
}