Let's extend the ship class using the following steps:
Open the
Ship.h
file.Add
enum
for the eight directions of the ship, as shown in the following code:typedef NS_ENUM(NSInteger, ShipDirection) { DirectionNorth, DirectionSouth, DirectionWest, DirectionEast, DirectionNorthWest, DirectionNorthEast, DirectionSouthWest, DirectionSouthEast };
Add another
enum
for the type of the ship, as shown in the following code:typedef NS_ENUM(NSInteger, ShipType) { ShipPirate, ShipNormal };
Change the
_shootingClip
instance variable to be a pointer to theNSArray
class and remove the_idleImage
instance variable, as shown in the following code:NSArray *_shootingClip;
Add a property for the ship's
hitpoints
, as shown in the following line of code:@property int hitpoints;
Add another property for
type
, as shown in the following line of code:@property ShipType type;
The third property is the direction of the ship...