//打僵尸(继承)
#import <Foundation/Foundation.h>
@interface CommonZombie : NSObject
{
NSString *_type;//僵尸种类
int _totleBloodValue;//总血量
int _reduceBloodValue;//被攻击是减少的血量
int _lastBloodValue;//剩余血量
bool _isDeath;//判断死亡状态
}
+ (CommonZombie*)commonZombieWithType:(NSString*)type andTtleBloodValue:(int)totleBloodValue andReduceBloodValue:(int)reduceBloodValue;
- (id)initWithType:(NSString*)type andTotleBloodValue:(int)totleBloodVale andReduceBloodValue:(int)reduceBloodValue;
//- (void)setReduceBloodValue:(int)reduceBloodValue;
- (BOOL)isDeath;
- (void)death;
- (int)byAttackReduceBloodValue;
@end
#import "CommonZombie.h"
@implementation CommonZombie
+ (CommonZombie*)commonZombieWithType:(NSString*)type andTtleBloodValue:(int)totleBloodValue andReduceBloodValue:(int)reduceBloodValue {
CommonZombie *commonZombie = [[CommonZombie alloc] initWithType:type andTotleBloodValue:totleBloodValue andReduceBloodValue:reduceBloodValue];
return commonZombie;
}
- (id)initWithType:(NSString*)type andTotleBloodValue:(int)totleBloodVale andReduceBloodValue:(int)reduceBloodValue
{
if (self = [super init]) {
_totleBloodValue = totleBloodVale;
_type = type;
_lastBloodValue = _totleBloodValue;
_reduceBloodValue = reduceBloodValue;
}
return self;
}
- (void)setReduceBloodValue:(int)reduceBloodValue
{
_reduceBloodValue = reduceBloodValue;
}
- (BOOL)isDeath
{
return _lastBloodValue<=0;
}
- (void)death
{
NSLog(@"已死");
}
- (int)byAttackReduceBloodValue
{
_lastBloodValue -= _reduceBloodValue;
return _lastBloodValue;
}
@end
#import "CommonZombie.h"
@interface roadblockZombie : CommonZombie
{
NSString *_prop;//道具
}
- (id)initWithType:(NSString *)type andTotleBloodValue:(int)totleBloodVale andProp:(NSString*)prop andReduceBloodValue:(int)reduceBloodValue;
+ (roadblockZombie *)roadblockZombieWith:(NSString*)type andTotleBloodValue:(int)totleBloodValue andProp:(NSString*)prop andReduceBloodValue:(int)reduceBloodValue;
- (BOOL)isloseProp;
- (void)setReduceBloodValue:(int)reduceBloodValue;
- (int)byAttackReduceBloodValue;
@end
@implementation roadblockZombie
- (id)initWithType:(NSString *)type andTotleBloodValue:(int)totleBloodVale andProp:(NSString*)prop andReduceBloodValue:(int)reduceBloodValue
{
if (self = [super init]) {
_totleBloodValue = totleBloodVale;
_type = type;
_lastBloodValue = _totleBloodValue;
_reduceBloodValue = reduceBloodValue;
_prop = prop;
}
return self;
}
+ (roadblockZombie *)roadblockZombieWith:(NSString*)type andTotleBloodValue:(int)totleBloodValue andProp:(NSString*)prop andReduceBloodValue:(int)reduceBloodValue
{
roadblockZombie * r = [[roadblockZombie alloc]initWithType:type andTotleBloodValue:totleBloodValue andProp:prop andReduceBloodValue:reduceBloodValue];
return r;
}
- (BOOL)isLoseProp
{
return _lastBloodValue<(_totleBloodValue*0.5);
}
- (int)byAttackReduceBloodValue
{
if ([self isLoseProp]) {
_lastBloodValue -=_reduceBloodValue ;
}else
_lastBloodValue -=(_reduceBloodValue-1) ;
return _lastBloodValue;
}
@end
#import "roadblockZombie.h"
@interface DrumZombie : roadblockZombie
{
NSString *_weakness;//弱点
}
- (id)initWithType:(NSString *)type andTotleBloodValue:(int)totleBloodVale andProp:(NSString*)prop andWeakness:(NSString*)weakness andReduceBloodValue:(int)reduceBloodValue ;
+ (DrumZombie *)drumZombieWith:(NSString*)type andTotleBloodValue:(int)totleBloodValue andProp:(NSString*)prop andWeakness:(NSString*)weakness andReduceBloodValue:(int)reduceBloodValue;
- (BOOL)isloseProp;
- (BOOL)isWeakness;
- (int)byAttackReduceBloodValue;
@end
#import "DrumZombie.h"
@implementation DrumZombie
- (id)initWithType:(NSString *)type andTotleBloodValue:(int)totleBloodVale andProp:(NSString*)prop andWeakness:(NSString*)weakness andReduceBloodValue:(int)reduceBloodValue
{
if (self = [super init]) {
_totleBloodValue = totleBloodVale;
_type = type;
_lastBloodValue = _totleBloodValue;
_prop = prop;
_weakness = weakness;
_reduceBloodValue = reduceBloodValue;
}
return self;
}
+ (DrumZombie *)drumZombieWith:(NSString*)type andTotleBloodValue:(int)totleBloodValue andProp:(NSString*)prop andWeakness:(NSString*)weakness andReduceBloodValue:(int)reduceBloodValue
{
DrumZombie * d = [[DrumZombie alloc]initWithType:type andTotleBloodValue:totleBloodValue andProp:prop andWeakness:weakness andReduceBloodValue:reduceBloodValue];
return d;
}
- (BOOL)isLoseProp
{
return _lastBloodValue<=(_lastBloodValue*0.3);
}
- (int)byAttackReduceBloodValue
{
if ([self isLoseProp]) {
_lastBloodValue -= _reduceBloodValue;
}else
_lastBloodValue -= _reduceBloodValue-2;
return _lastBloodValue;
}
@end
#import <Foundation/Foundation.h>
#import "CommonZombie.h"
#import "DrumZombie.h"
#import "roadblockZombie.h"
int main(int argc, const char * argv[])
{
CommonZombie * c = [CommonZombie commonZombieWithType:@"putongjiangshi" andTtleBloodValue:50
andReduceBloodValue:3];
roadblockZombie *r = [roadblockZombie roadblockZombieWith:@"路障僵尸" andTotleBloodValue:80 andProp:@"路障"andReduceBloodValue:3];
DrumZombie *d = [DrumZombie drumZombieWith:@"铁桶僵尸" andTotleBloodValue:120 andProp:@"铁通"andWeakness:@"citie" andReduceBloodValue:3];
while (1) {
int lastBloodValue = [d byAttackReduceBloodValue];
NSLog(@"剩余血量:%d",lastBloodValue);
if ([d isDeath]){
[d death];
break;
}
}
return 0;
}