Time for action – being able to win or lose
To be able to win or lose the game, use the following steps:
In
Ship.h
, add a callback property using the following line of code:@property (nonatomic, copy) ShipCallbackonDead;
This callback property gets invoked if the ship is equal to or less than zero hit points, as shown in the following code:
if (_hitpoints<= 0) { self.visible = FALSE; if (self.onDead) { [_onDead invoke]; } }
In the
Battlefield.h
file, add two properties for our new text fields as shown:@property SPTextField *textGameWon; @property SPTextField *textGameLost;
In the initializer, add the following piece of code:
_textGameLost = [SPTextField textFieldWithWidth:Sparrow.stage.width height:Sparrow.stage.height text:@"Game Over"]; _textGameLost.fontName = @"PirateFont"; _textGameLost.color = SP_WHITE; _textGameLost.visible = NO; _textGameWon = [SPTextField textFieldWithWidth:Sparrow.stage.width height:Sparrow.stage.height text:@"You won the game. Well done"]; _textGameWon...