OC 打僵尸

OC继承:打僵尸

#import <Foundation/Foundation.h>


@interface Jiangshi :NSObject

{

   NSString *_type;

   NSInteger _totleBloodValue;//总血量

   NSInteger _reduceBloodValue;//被攻击时减少的血量

   int _lastBloodValue;//剩余血量

   bool _isDeath;//判断死亡状态

}


-(id)initWithNameType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue;


+(id)jiangshiWithType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue;

-(void)setType:(NSString *)type;

-(void)setTotleBloodValue:(NSInteger)totleBloodValue;

-(void)setReduceBloodValue:(NSInteger)reduceBloodValue;

-(NSString *)type;

-(NSInteger)totleBloodValue;

-(NSInteger)reduceBloodValue;

- (BOOL)isDeath;

- (void)death;

- (int)byAttackReduceBloodValue;


@end


#import "Jiangshi.h"


@implementation Jiangshi

-(id)initWithNameType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue

{

   self = [superinit];

   if (self) {

       _type = type;

       _totleBloodValue = totileBloodValue;

       _reduceBloodValue = reduceBloodValue;

    }

    return self;

}


+(id)jiangshiWithType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue

{

    Jiangshi *i = [[Jiangshialloc]

                  initWithNameType:type totileBloodValue:totileBloodValuereduceBloodValue:reduceBloodValue];

   return i;

}


-(void)setType:(NSString *)type

{

   _type = type;

}

-(void)setTotleBloodValue:(NSInteger)totleBloodValue

{

   _totleBloodValue = totleBloodValue;

}

-(void)setReduceBloodValue:(NSInteger)reduceBloodValue

{

   _reduceBloodValue = reduceBloodValue;

}


-(NSString *)type

{

   return _type;

}

-(NSInteger)totleBloodValue

{

    return_totleBloodValue;

}

-(NSInteger)reduceBloodValue

{

    return_reduceBloodValue;

}


- (BOOL)isDeath

{

      return_lastBloodValue<=0;

}

- (void)death

{

    NSLog(@"已死");

}

- (int)byAttackReduceBloodValue

{

    _lastBloodValue -=_reduceBloodValue;

    return_lastBloodValue;

}

@end


#import "Jiangshi.h"


@interface Daojujiangshi :Jiangshi

{

   NSString *_daoju;

}

-(id)initWithNameType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue

                daoju:(NSString *)daoju;

+(id)daojujiangshiWithType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue

                daoju:(NSString *)daoju;

- (BOOL)isloseProp;

- (void)setReduceBloodValue:(int)reduceBloodValue;


- (int)byAttackReduceBloodValue;

@end


@implementation Daojujiangshi

-(id)initWithNameType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue

                daoju:(NSString *)daoju

{

   self = [superinitWithNameType:type totileBloodValue:totileBloodValuereduceBloodValue:reduceBloodValue];

   if (self) {

       _daoju = daoju;

    }

    return self;

}

+(id)daojujiangshiWithType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue

                daoju:(NSString *)daoju

{

    Daojujiangshi *d = [[Daojujiangshialloc]

                       initWithNameType:type totileBloodValue:totileBloodValuereduceBloodValue:reduceBloodValuedaoju:daoju];

   return d;

}

- (BOOL)isloseProp

{

      return_lastBloodValue<(_totleBloodValue*0.5);

}

- (int)byAttackReduceBloodValue

{

   if ([self isloseProp]) {

        _lastBloodValue -=_reduceBloodValue ;

    }else

        _lastBloodValue -=(_reduceBloodValue-1) ;

    return_lastBloodValue;

}


@end


#import "Daojujiangshi.h"


@interface Tietongjiangshi :Daojujiangshi

{

   NSString *_weakness;

}

-(id)initWithNameType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue

                daoju:(NSString *)daoju

             weakness:(NSString *)weakness;

+(id)tietongjiangshiWithType:(NSString *)type

          totileBloodValue:(NSInteger)totileBloodValue

          reduceBloodValue:(NSInteger)reduceBloodValue

                     daoju:(NSString *)daoju

                  weakness:(NSString *)weakness;

- (BOOL)isloseProp;

- (BOOL)isWeakness;

- (int)byAttackReduceBloodValue;

@end


#import "Tietongjiangshi.h"


@implementation Tietongjiangshi

-(id)initWithNameType:(NSString *)type

     totileBloodValue:(NSInteger)totileBloodValue

     reduceBloodValue:(NSInteger)reduceBloodValue

                daoju:(NSString *)daoju

             weakness:(NSString *)weakness

{

   self = [superinitWithNameType:type totileBloodValue:totileBloodValuereduceBloodValue:reduceBloodValuedaoju:daoju];

   if (self) {

       _weakness = weakness;

    }

    return self;

}

+(id)tietongjiangshiWithType:(NSString *)type

            totileBloodValue:(NSInteger)totileBloodValue

            reduceBloodValue:(NSInteger)reduceBloodValue

                       daoju:(NSString *)daoju

                    weakness:(NSString *)weakness

{

    Tietongjiangshi *z = [[Tietongjiangshialloc]

                         initWithNameType:type totileBloodValue:totileBloodValuereduceBloodValue:reduceBloodValuedaoju:daoju weakness:weakness];

   return z;

}

- (BOOL)isloseProp

{

    return_lastBloodValue<=(_lastBloodValue*0.3);

}

- (int)byAttackReduceBloodValue

{

   if ([self isloseProp]) {

        _lastBloodValue -=_reduceBloodValue;

    }else

        _lastBloodValue -=_reduceBloodValue-2;

    return_lastBloodValue;

}

@end


int main(int argc,const char * argv[])

{


    @autoreleasepool {

     

        Jiangshi *i = [JiangshijiangshiWithType:@"普通僵尸"totileBloodValue:50reduceBloodValue:3];

//        [i byAttackReduceBloodValue];

        Daojujiangshi *d = [DaojujiangshidaojujiangshiWithType:@"道具僵尸"totileBloodValue:80reduceBloodValue:2 daoju:@"飞镖"];

        Tietongjiangshi *z = [TietongjiangshitietongjiangshiWithType:@"铁桶僵尸"totileBloodValue:120reduceBloodValue:1 daoju:@"飞镖" weakness:@"头部"];

//        [z byAttackReduceBloodValue];

       while (1) {

           int lastBloodValue =  [i byAttackReduceBloodValue];

           NSLog(@"剩余血量:%d",lastBloodValue);

           if ([i isDeath]){

                [ideath];

               break;

            }

            

        }

       while (1) {

           int lastBloodValue =  [d byAttackReduceBloodValue];

           NSLog(@"剩余血量:%d",lastBloodValue);

           if ([d isDeath]){

                [ddeath];

               break;

            }

            

        }

       while (1) {

           int lastBloodValue =  [z byAttackReduceBloodValue];

           NSLog(@"剩余血量:%d",lastBloodValue);

           if ([z isDeath]){

                [zdeath];

               break;

            }

            

        }


   return 0;

    }

}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值