OC 打僵尸

来源:互联网 发布:乐视电视切换网络电视 编辑:程序博客网 时间:2024/05/18 02:06

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;

    }

}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 6激素检查喝水了怎么办 抽血前吃了东西怎么办 怀孕一个月孕酮低怎么办 怀孕了老是有痰怎么办 孕妇有很多白痰怎么办 血糖高怎么办吃什么好 5年糖尿病血糖高怎么办 血糖高引起的视力模糊怎么办 谷丙转氨酶和谷草转氨酶高怎么办 产检血糖有点高怎么办 孕期餐后血糖高怎么办 怀孕12周血糖高怎么办 怀孕2个月血糖高怎么办 怀孕7个月血糖高怎么办 孕妇7个月血糖高怎么办 空腹血糖6%2e7怎么办 血糖和尿酸都高怎么办 血糖高的孕妇便秘怎么办 血糖低怎么办吃什么好 孕检空腹血糖高怎么办 怀孕4个月血糖高怎么办 怀孕3个月血糖高怎么办 怀孕6个月血糖高怎么办 孕29周血糖高怎么办 餐后血糖偶尔高怎么办 歺后血糖9.8高怎么办 怀孕5个月血糖高怎么办 歺后2小时血糖高怎么办 怀孕餐后血糖高怎么办 老人餐后血糖高怎么办 血糖高尿糖不高怎么办 小孩鼻子不通气怎么办特效方法 婴儿20天不大便怎么办 新生儿8天没大便怎么办 新生儿2天没大便怎么办 新生儿4天没大便怎么办 2岁宝宝便秘严重怎么办 婴儿7天没有大便怎么办 新生儿6天没大便怎么办 大便带鲜血 不疼怎么办 宝宝发烧到39度怎么办