博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OC:打僵尸问题(类的问题)
阅读量:7197 次
发布时间:2019-06-29

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

1、定义普通僵尸类:

 实例变量:僵尸种类、僵尸总血量、僵尸每次失血量。

 方法:初始化方法(设置僵尸种类,总血量)、被打击失血、死亡。

   2、定义路障僵尸类:

 实例变量:僵尸种类、僵尸总血量、僵尸每次失血量,道具,弱点。

  方法:初始化方法(设置僵尸种类,总血量)、被打击失血、失去装备、死亡。

3、定义铁桶僵尸类:

  实例变量:僵尸种类、僵尸总血量、僵尸每次失血量,道具,弱点。

  方法:初始化方法(设置僵尸种类,总血量)、被打击失血、失去装备、死亡。

4、在main.m中创建普通僵尸对象,设置总血量50,每次失血量为 3,没有道具。

5、在main.m中创建路障僵尸对象,设置总血量80,每次失血量为 2,设置道具为路障。

6、在main.m中创建铁桶僵尸对象,设置总血量120,每次失血量为 1,设置道具为铁桶。

main.m文件

 

#import #import "CommonZombie.h"#import "BarrierZombie.h"#import "BucketZombie.h"int main(int argc, const char * argv[]){    @autoreleasepool {            //创建普通僵尸对象        CommonZombie *xiaoGuang = [[CommonZombie alloc] initWithKind:@"普通僵尸" totalBlood:50];        //设置每次失血量        [xiaoGuang setReduceBlood:3];                //创建路障僵尸        BarrierZombie *xiaoMeng = [[BarrierZombie alloc] initWithKind:@"路障僵尸" totalBlood:80];        //设置每次失血量        [xiaoMeng setReduceBlood:2];        //设置装备        [xiaoMeng setProp:@"路障"];                //创建铁桶僵尸        BucketZombie *xiaoCui = [[BucketZombie alloc] initWithKind:@"铁桶僵尸" totalBlood:120];        //设置每次失血量        [xiaoCui setReduceBlood:1];        //设置装备        [xiaoCui setProp:@"铁桶"];    }    return 0;}

 

普通僵尸CommonZombie.m文件

 

#import "CommonZombie.h"@implementation CommonZombie//customized init method- (id)initWithKind:(NSString *)kind totalBlood:(NSInteger)totalBlood{    _kind = kind;    _totalBlood = totalBlood;    return self;}//失血- (void)loseBlood{    NSLog(@"哎呀,哎呀,要死啦要死啦,掉了3滴血");    _totalBlood -= _reduceBlood;}//死亡- (void)death{    NSLog(@"哎呀,哎呀,死啦死啦,这次是真死啦");}//设置每次的失血量- (void)setReduceBlood:(NSInteger)reduceBlood{    _reduceBlood = reduceBlood;}@end

 

路障僵尸BarrierZombie.m


#import "BarrierZombie.h"@implementation BarrierZombie//customized init method- (id)initWithKind:(NSString *)kind totalBlood:(NSInteger)totalBlood{    _kind = kind;    _totalBlood = totalBlood;    return self;}//失血- (void)loseBlood{    NSLog(@"哎呀,哎呀,要死啦要死啦,掉了3滴血");    _totalBlood -= _reduceBlood;}//死亡- (void)death{    NSLog(@"哎呀,哎呀,死啦死啦,这次是真死啦");}//失去装备- (void)loseProp{    NSLog(@"哎呀,哎呀,要死啦,要死啦,装备没了");}//设置每次的失血量- (void)setReduceBlood:(NSInteger)reduceBlood{    _reduceBlood = reduceBlood;}//设置装备- (void)setProp:(NSString *)prop{    _prop = prop;}@end


铁桶僵尸BucketZombie.m

#import "BucketZombie.h"@implementation BucketZombie//customized init method- (id)initWithKind:(NSString *)kind totalBlood:(NSInteger)totalBlood{    _kind = kind;    _totalBlood = totalBlood;    return self;}//失血- (void)loseBlood{    NSLog(@"哎呀,哎呀,要死啦要死啦,掉了3滴血");    _totalBlood -= _reduceBlood;}//死亡- (void)death{    NSLog(@"哎呀,哎呀,死啦死啦,这次是真死啦");}//失去装备- (void)loseProp{    NSLog(@"哎呀,哎呀,要死啦,要死啦,装备没了");}//设置每次的失血量- (void)setReduceBlood:(NSInteger)reduceBlood{    _reduceBlood = reduceBlood;}//设置装备- (void)setProp:(NSString *)prop{    _prop = prop;}@end
 
 

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

你可能感兴趣的文章
Win7、Ubuntu双系统正确卸载Ubuntu系统
查看>>
两数互换的例子
查看>>
我的友情链接
查看>>
网络拓扑自动发现-Sugarnms智能网管软件的基础
查看>>
线程的状态转换图
查看>>
VMware vSphere 5.0 五大改变
查看>>
spring注解性的事物@Transactional不起作用
查看>>
使用aulayout自适应uitableviewcell高度
查看>>
让我们一起Go(三)
查看>>
简单的Linux数据备份方案
查看>>
RIP协议和RIP2
查看>>
linux postgresql 安装配置详解
查看>>
一个监控tomcat运行的脚本分享
查看>>
电脑可以上网但网络连接显示感叹号
查看>>
我的友情链接
查看>>
MaxCompute用户初体验
查看>>
阿里云十年再出发,边缘计算已启航
查看>>
代理服务器与网络地址转换NAT
查看>>
我的友情链接
查看>>
SQL Server 镜像
查看>>