Course Solutions Uncategorized (Solved) : Exercise Class Memberwise Initializers References Note Exercises Based Game Spaceship Avoi Q31764506 . . . .

(Solved) : Exercise Class Memberwise Initializers References Note Exercises Based Game Spaceship Avoi Q31764506 . . . .

 

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

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post