@interface BarricadeZombie : NSObject
{
NSString *_species; //種類
NSInteger _totalVolume; //總血量
NSInteger _everyTimeLoss; //每次失血量
NSString *_prop; //道具
NSString *_weakness; //弱點
}
- (NSString *)species;
- (NSInteger)totalVolume;
- (NSInteger)everyTimeLoss;
//初始化
- (id)initWithSpecies:(NSString *)species totalVolume:(NSInteger)totalVolume everyTimeLoss:(NSInteger)everyTimeLoss;
//剩餘血量
- (NSInteger)bloodLoss;
////失去道具
//- (void)lossOfEquioment;
//死亡
- (void)death;
@end
@implementation BarricadeZombie
- (id)initWithSpecies:(NSString *)species totalVolume:(NSInteger)totalVolume everyTimeLoss:(NSInteger)everyTimeLoss
{
_species = species;
_totalVolume = totalVolume;
_everyTimeLoss = everyTimeLoss;
return self;
}
- (NSString *)species
{
return _species;
}
- (NSInteger)totalVolume
{
return _totalVolume;
}
- (NSInteger)everyTimeLoss
{
return _everyTimeLoss;
}
- (NSInteger)bloodLoss
{
NSInteger i = 0;
while (_totalVolume > 0) {
if (_totalVolume > 50) {
_totalVolume -= _everyTimeLoss;
}else{
_totalVolume -= 3;
}
i++;
}
return i;
}
- (void)death
{
NSLog(@"死亡");
}
@end
BarricadeZombie *ba = [[BarricadeZombie alloc] initWithSpecies:@"路障殭屍" totalVolume:80 everyTimeLoss:2];
NSLog(@"%@,%ld滴血,每次攻擊掉%ld滴血",[ba species],[ba totalVolume],[ba everyTimeLoss]);
NSLog(@"殭屍來襲,準備攻擊");
NSLog(@"被打%ld之後",[ba bloodLoss]);
[ba death];