博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
植物大战僵尸
阅读量:6613 次
发布时间:2019-06-24

本文共 5325 字,大约阅读时间需要 17 分钟。

#import 
@interface CommonZomble : NSObject{ NSString * _zombleKind;//僵尸种类 NSInteger _totalBloodVolume;//总血量 NSInteger _everyTimeBloodloss;//每次被攻击的血量 NSInteger _residualVolume;//剩余血量 BOOL _zombleDeath;//僵尸是否死亡}- (instancetype)initWithZombleKind:(NSString *)zombleKind totalBloodVolume:(NSInteger)totalBloodVolume everyTimeBloodloss:(NSInteger)everyTimeBloodloss;- (void)attack;- (BOOL)death;- (BOOL)takeDeath;+ (CommonZomble *)commonZombleInitWithZombleKind:(NSString *)zombleKind totalBloodVolume:(NSInteger)totalBloodVolume everyTimeBloodloss:(NSInteger)everyTimeBloodloss;@end
#import "CommonZomble.h"@implementation CommonZomble- (instancetype)initWithZombleKind:(NSString *)zombleKind totalBloodVolume:(NSInteger)totalBloodVolume everyTimeBloodloss:(NSInteger)everyTimeBloodloss{    self = [super init];    if (self) {        _totalBloodVolume = totalBloodVolume;        _residualVolume = _totalBloodVolume;        _zombleKind = zombleKind;        _everyTimeBloodloss = everyTimeBloodloss;        _zombleDeath = NO;    }    return self;}- (void)attack{    _residualVolume = _residualVolume - _everyTimeBloodloss;    NSLog(@"%@,剩余血量%ld,每次失血量%ld",_zombleKind,_residualVolume,_everyTimeBloodloss);}- (BOOL)death{    BOOL result = NO;    if (_residualVolume < _everyTimeBloodloss) {        _zombleDeath=YES;         NSLog(@"%@已死",_zombleKind);        result = YES;    }    return result;}- (BOOL)takeDeath{    return _zombleDeath;}+ (CommonZomble *)commonZombleInitWithZombleKind:(NSString *)zombleKind totalBloodVolume:(NSInteger)totalBloodVolume everyTimeBloodloss:(NSInteger)everyTimeBloodloss{    return [[CommonZomble alloc]initWithZombleKind:zombleKind totalBloodVolume:totalBloodVolume everyTimeBloodloss:everyTimeBloodloss];}@end
 
 
 
 
#import "CommonZomble.h"@interface BarricadeZombie : CommonZomble{    NSString * _prop;//道具    NSString * _weakness;//弱点}- (instancetype)initWithZombleKind:(NSString *)zombleKind totalBloodVolume:(NSInteger)totalBloodVolume everyTimeBloodloss:(NSInteger)everyTimeBloodloss prop:(NSString *)prop weakness:(NSString *)weakness;- (void)attack;- (void)lossProp;- (BarricadeZombie *)barricadeZombieInitWithZombleKind:(NSString *)zombleKind totalBloodVolume:(NSInteger)totalBloodVolume everyTimeBloodloss:(NSInteger)everyTimeBloodloss prop:(NSString *)prop weakness:(NSString *)weakness;@end
 

#import "BarricadeZombie.h"@implementation BarricadeZombie- (instancetype)initWithZombleKind:(NSString *)zombleKind totalBloodVolume:(NSInteger)totalBloodVolume everyTimeBloodloss:(NSInteger)everyTimeBloodloss prop:(NSString *)prop weakness:(NSString *)weakness{    self = [super initWithZombleKind:zombleKind totalBloodVolume:totalBloodVolume everyTimeBloodloss:everyTimeBloodloss];    if (self) {        _prop = prop;        _weakness = weakness;    }    return self;}- (void)attack{    _residualVolume = _residualVolume - _everyTimeBloodloss;      NSLog(@"%@,剩余血量%ld,每次失血量%ld",_zombleKind,_residualVolume,_everyTimeBloodloss);    if (_residualVolume<= _totalBloodVolume/2 && _residualVolume > _totalBloodVolume/2 - _everyTimeBloodloss) {        NSLog(@"%@丢失",_prop);        [self lossProp];    }}- (void)lossProp{    _everyTimeBloodloss = 3;}- (BarricadeZombie *)barricadeZombieInitWithZombleKind:(NSString *)zombleKind totalBloodVolume:(NSInteger)totalBloodVolume everyTimeBloodloss:(NSInteger)everyTimeBloodloss prop:(NSString *)prop weakness:(NSString *)weakness{    return [[BarricadeZombie alloc]            barricadeZombieInitWithZombleKind:zombleKind totalBloodVolume:totalBloodVolume everyTimeBloodloss:everyTimeBloodloss prop:prop weakness:weakness];}@end

#import "BarricadeZombie.h"@interface DrumZomble : BarricadeZombie- (void)attack;@end
#import "DrumZomble.h"@implementation DrumZomble- (void)attack{    _residualVolume = _residualVolume - _everyTimeBloodloss;     NSLog(@"%@,剩余血量%ld,每次失血量%ld",_zombleKind,_residualVolume,_everyTimeBloodloss);    if (_residualVolume <= _totalBloodVolume/3 && _residualVolume > _totalBloodVolume/3 - _everyTimeBloodloss) {        [self lossProp];        NSLog(@"%@掉了",_prop);    }}@end
 
 
#import 
#import "CommonZomble.h"#import "BarricadeZombie.h"#import "DrumZomble.h"int main(int argc, const char * argv[]){ @autoreleasepool { CommonZomble * commonZomble = [[CommonZomble alloc]initWithZombleKind:@"普通僵尸" totalBloodVolume:50 everyTimeBloodloss:3]; BarricadeZombie * barricadeZombie = [[BarricadeZombie alloc]initWithZombleKind:@"路障僵尸" totalBloodVolume:80 everyTimeBloodloss:2 prop:@"路障" weakness:@"怕我"]; DrumZomble * drumZomble = [[DrumZomble alloc]initWithZombleKind:@"铁桶僵尸" totalBloodVolume:120 everyTimeBloodloss:1 prop:@"铁桶" weakness:@"磁铁"]; NSInteger count = 0; while (1) { count++; NSLog(@"count = %ld",count); if (![commonZomble death]) { [commonZomble attack]; } if (![barricadeZombie death]) { [barricadeZombie attack]; } if (![drumZomble death]) { [drumZomble attack]; } if ([commonZomble takeDeath] && [barricadeZombie takeDeath] && [drumZomble takeDeath]) { break; } } NSLog(@"count = %ld",count); } return 0;}
 

转载地址:http://hweso.baihongyu.com/

你可能感兴趣的文章
祝各位2019
查看>>
ubuntu16.0.4安装ganglia
查看>>
js模拟点击事件实现代码
查看>>
【★】独创多播超级教程!
查看>>
Scala之美 - Future & map & flatMap
查看>>
Java获取随机数生成随机字符串用于验证码等之类的工具
查看>>
简单的下单程序
查看>>
Golang面试题解析(三)
查看>>
前端与后台之间的乱码问题
查看>>
关于GitHub迁移到K8S的最佳实践,你最看重哪方面?
查看>>
openstack核心路由和扩展路由及路由对应的api函数调用流程分析
查看>>
java操作mongodb数据库
查看>>
自己动手写一个查询cet成绩的API
查看>>
http:与https:到底有哪些区别?
查看>>
细节决定成败----Android应用程序的优化(一)
查看>>
mac 下 gem安装 compass 遇到 '-multiply_defineds'
查看>>
怎样在MyEclipse中恢复误删的java文件方法
查看>>
redis-spring
查看>>
索引优缺点
查看>>
golang 组合class 输出
查看>>