OC僵尸 属性 便利构造器 BOOL类型 继承 方法重写
来源:互联网 发布:淘宝店铺运费模板 编辑:程序博客网 时间:2024/06/17 18:12
main.m
CommonZombie *cZomb = [CommonZombiecommonZombieWithHP:50withLose:3];
while (1) { //循环被打
[cZombloseHP];
if ([cZomb die]) {//判断死亡跳出
break;
}
}
BarrierZombie *bZomb = [BarrierZombiebarrierZombieWithHP:80withLose:2withProp:@"路障"];
while (1) {
[bZombloseHP];
if ([bZomb die]) {
break;
}
}
CommonZombie.h
#import <Foundation/Foundation.h>
@interface CommonZombie :NSObject
@property(nonatomic,assign) NSInteger HP;
@property(nonatomic,assign) NSInteger lose;
- (instancetype)initWithHP:(NSInteger )hp withLose:(NSInteger )lose;
+ (instancetype)commonZombieWithHP:(NSInteger )hp withLose:(NSInteger )lose;
- (void)loseHP;
- (BOOL)die;
@end
CommonZombie.m
#import "CommonZombie.h"
@implementation CommonZombie
- (instancetype)initWithHP:(NSInteger )hp withLose:(NSInteger )lose {
self = [superinit];
if (self) {
self.HP = hp;
self.lose = lose;
}
return self;
}
+ (instancetype)commonZombieWithHP:(NSInteger )hp withLose:(NSInteger )lose {
return [[CommonZombiealloc] initWithHP:hpwithLose:lose];
}
- (void)loseHP {
if (self.HP -self.lose <0) {
self.HP = 0;
}else {
self.HP -= self.lose;
}
NSLog(@"僵尸%ld",self.HP);
}
- (BOOL)die {
if (self.HP <=0) {
NSLog(@"die");
return YES;
}else {
return NO;
}
}
@end
BarrierZombie.h
#import "CommonZombie.h"
@interface BarrierZombie :CommonZombie
@property(nonatomic,retain) NSString *prop;
- (instancetype)initWithHP:(NSInteger)hp withLose:(NSInteger)lose withProp:(NSString *)prop;
+ (instancetype)barrierZombieWithHP:(NSInteger )hp withLose:(NSInteger )lose withProp:(NSString *)prop;
@end
BarrierZombie.m
- (instancetype)initWithHP:(NSInteger)hp withLose:(NSInteger)lose withProp:(NSString *)prop {
self = [superinitWithHP:hp withLose:lose];
if (self) {
self.prop = prop;
}
return self;
}
+ (instancetype)barrierZombieWithHP:(NSInteger)hp withLose:(NSInteger)lose withProp:(NSString *)prop {
return [[BarrierZombiealloc] initWithHP:hpwithLose:lose withProp:prop];
}
- (void)loseProp {
NSLog(@"%@头盔掉了",self.prop);
}
- (void)loseHP {
if (self.HP <=0) {
self.HP = 0;
}else {
self.HP -= self.lose;
}
NSLog(@"%ld",self.HP);
}
- (BOOL)die {
if (self.HP ==50) {
[selfloseProp];
return NO;
}else if (self.HP <=0) {
NSLog(@"DIE");
return YES;
}else {
return NO;
}
}
- OC僵尸 属性 便利构造器 BOOL类型 继承 方法重写
- OC-继承-初始化方法-便利构造器(练习题-打僵尸)
- OC第三天-继承,初始化方法,便利构造器 ,self,super,方法重写
- OC之继承,初始化方法,便利构造器
- OC基础:继承.初始化方法,便利构造器
- OC学习-继承,便利构造器,初始化方法
- iOS开发之OC继承、初始化方法、便利构造器
- OC-继承、初始化方法、便利构造器概念
- OC - 第三章 继承、初始化方法、便利构造器
- OC基础 便利构造器 继承,
- OC之继承、初始化、便利构造器
- OC的属性和便利构造器
- oc语言类 便利初始化函数 便利构造器 属性
- oc初始化方法,便利构造器
- OC语言 实例方法与类方法 & setter与getter & 便利初始化函数与便利构造器 & 属性(一)
- OC语言 实例方法与类方法 & setter与getter & 便利初始化函数与便利构造器 & 属性(二)
- iOS前期OC训练OC_02继承,便利构造器,初始化方法
- OC学习_ 第三天 继承、初始化方法、便利构造器
- ios 设计 切图
- CSU1506 Double Shortest Paths 最小费用最大流入门题
- JavaScript基础----20Javascript-DOM操作HTML
- POJ 1007 DNA Sorting
- 界面传值(协议)
- OC僵尸 属性 便利构造器 BOOL类型 继承 方法重写
- swift2.0学习之类型转换
- Maximal Square
- 单例模式
- JavaScript基础----21Javascript-DOM操作CSS
- TCP的连接传输
- 做好软件测试需要具备的思维方式
- Spring MVC 整合 Freemarker
- C++中你仍然不知道的事