pokecli/internal/poketrainer/trainer.go
Dan Anglin 80d1b5b6c0
feat: add internal trainer package
Added an internal package for the Pokemon trainer (the user of the
application). The new Trainer type keeps track of the Pokemon in the
trainer's Pokedex and the location where the trainer is visiting.

Added the visit command to allow the Pokemon trainer to visit and
explore an area within the Pokemon world. The explore command no longer
reads any arguments and uses the trainer's current location to get a
list of Pokemon encounters.

Updated the catch command to ensure that the Pokemon the trainer
attempts to catch is in the same location area that the trainer is
visiting.
2024-09-21 15:19:53 +01:00

71 lines
1.5 KiB
Go

package poketrainer
import (
"fmt"
"maps"
"codeflow.dananglin.me.uk/apollo/pokedex/internal/api/pokeapi"
)
type Trainer struct {
previousLocationArea *string
nextLocationArea *string
currentLocationAreaName string
pokedex map[string]pokeapi.Pokemon
}
func NewTrainer() *Trainer {
trainer := Trainer{
previousLocationArea: nil,
nextLocationArea: nil,
currentLocationAreaName: "",
pokedex: make(map[string]pokeapi.Pokemon),
}
return &trainer
}
func (t *Trainer) UpdateLocationAreas(previous, next *string) {
t.previousLocationArea = previous
t.nextLocationArea = next
}
func (t *Trainer) PreviousLocationArea() *string {
return t.previousLocationArea
}
func (t *Trainer) NextLocationArea() *string {
return t.nextLocationArea
}
func (t *Trainer) AddPokemonToPokedex(name string, details pokeapi.Pokemon) {
t.pokedex[name] = details
}
func (t *Trainer) GetPokemonFromPokedex(name string) (pokeapi.Pokemon, bool) {
details, ok := t.pokedex[name]
return details, ok
}
func (t *Trainer) ListAllPokemonFromPokedex() {
if len(t.pokedex) == 0 {
fmt.Println("You have no Pokemon in your Pokedex.")
return
}
fmt.Println("Your Pokedex:")
for name := range maps.All(t.pokedex) {
fmt.Println(" -", name)
}
}
func (t *Trainer) CurrentLocationAreaName() string {
return t.currentLocationAreaName
}
func (t *Trainer) UpdateCurrentLocationAreaName(locationName string) {
t.currentLocationAreaName = locationName
}