// Monster Battle -- starter. // // See the chapter page (project-monster-battle.html) for the full spec. // // As it is, the file runs and prints one placeholder line. When you write hit, // add "math/rand" to the import list. // // Run with: go run projects/monster-battle/starter.go package main import "fmt" // TODO 1: define a monster struct with name, hp, maxHP and attack fields. // // TODO 2: write these, with pointer receivers on the methods: // newMonster(name, hp, attack) -- returns a *monster and an error. It is an // error if hp or attack is below 1. // isAlive() -- returns true while hp is above 0. // hit(other) -- deals rand.Intn(m.attack)+1 damage to // other, never below 0, prints what happened // and returns the damage. // String() -- returns text like "Hero: 19/30 HP". func main() { // TODO 3: make two monsters, a hero and a goblin, with their own hp and // attack values. Check each error. // TODO 4: make a map from a name to the damage dealt. Then loop while both // are alive: the hero hits, then the goblin hits back if it is still // alive. Count the rounds, and add each hit's damage to the map. // TODO 5: after the loop, print which monster won. // TODO 6: put both monsters in a slice, loop over it, and print each one // with %v and the damage it dealt. // Replace this placeholder line: fmt.Println("TODO: replace this line") }