As we gain further experience, the list of spells we know grows and the number of paths we can take in-combat situations can grow to great lengths.
In order to handle this increasing complexity over time, it may be apt to change how we decide what to return from an if
statement to a switch
statement:
switch attackType {
case "charge":
fmt.Println("dodge")
case "bolt":
fmt.Println("energy shield")
case "stab":
fmt.Println("parry")
default:
fmt.Println("run")
}
Task
The SelectSpell
function takes in an enemy type which is of type string. We need to be able to decide quickly what spell to use with a switch
statement.
- When the type is
rock
-SelectSpell
should returnWaterBolt
- When the type is
water
-SelectSpell
should returnElectroBolt
- When the type is
ghost
-SelectSpell
should returnArcaneExplosion