From the course: Swift 5 Essential Training

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Solution: Battle actions

Solution: Battle actions - Swift Tutorial

From the course: Swift 5 Essential Training

Solution: Battle actions

(upbeat music) - [Instructor] All right, let's dive into our last challenge solution here and handle some errors. Our first task is going to be to create an enum that adopts the error protocol and has three cases. I'm going to say enum, I'm going to call this action error, It's going to adopt the air protocol, and for the first case, I'm going to say insufficient MP, second case out of range and third case unknown error. The second task we need to create a function, that's going to take in an integer and a double and return an optional Boolean. I'm going to say func attack enemy, parameter name is going to be MP for the first one and distance as a double. I'm also going to kick back an optional Boolean. And task three is pretty simple, we're going to mark attack enemy as a throw bool function with the throws keyword. For task number four, we need to add two guard statements to make sure that our MP and distance parameters…

Contents