From 6c676332c9cbf5f1dd3f6a78f587eeac7268c104 Mon Sep 17 00:00:00 2001 From: Darius Rapalis Date: Mon, 10 Mar 2025 22:36:41 +0200 Subject: [PATCH] #10 --- main.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/main.go b/main.go index 4ddb92e..7761bea 100644 --- a/main.go +++ b/main.go @@ -65,6 +65,16 @@ func main() { description: "Attempt to catch a pokemon", callback: commandCatch, }, + "inspect": { + name: "inspect ", + description: "View details about a caught Pokemon", + callback: commandInspect, + }, + "pokedex": { + name: "pokedex", + description: "View list of pokemons caught", + callback: commandPokedex, + }, } for { // read user input @@ -188,3 +198,37 @@ func commandCatch(cfg *config, args ...string) error { cfg.caughtPokemon[pokemon.Name] = pokemon return nil } + +func commandInspect(cfg *config, args ...string) error { + if len(args) != 1 { + return errors.New("you must provide a pokemon name") + } + + name := args[0] + pokemon, ok := cfg.caughtPokemon[name] + if !ok { + return errors.New("you have not caught that pokemon") + } + + fmt.Println("Name:", pokemon.Name) + fmt.Println("Height:", pokemon.Height) + fmt.Println("Weight:", pokemon.Weight) + fmt.Println("Stats:") + for _, stat := range pokemon.Stats { + fmt.Printf(" -%s: %v\n", stat.Stat.Name, stat.BaseStat) + } + fmt.Println("Types:") + for _, typeInfo := range pokemon.Types { + fmt.Println(" -", typeInfo.Type.Name) + } + return nil +} + +func commandPokedex(cfg *config, _ ...string) error { + + for name := range cfg.caughtPokemon { + fmt.Println(cfg.caughtPokemon[name].Name) + } + + return nil +}