Exercise – Class Memberwise Initializers and References
note.
The exercises below are based on a game where a spaceship avoidsobstacles in space. The ship is positioned at the bottom of acoordinate system and can only move left and right while obstacles”fall” from top to bottom. The base class Spaceship and subclassesFighter and ShieldedShip have been provided for you below. You willuse these to complete the exercises.
class Spaceship {
let name: String
var health: Int
var position: Int
func moveLeft() {
position -= 1
}
func moveRight() {
position += 1
}
func wasHit() {
health -= 5
}
}
class Fighter: Spaceship {
let weapon: String
var remainingFirePower: Int
func fire() {
if remainingFirePower > 0 {
remainingFirePower -= 1
} else
PayPal Gateway not configured
PayPal Gateway not configured