OC----第三讲作业

//打僵尸(继承)

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值