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;
}
}
- OC打僵尸
- OC 打僵尸
- OC打僵尸小样
- oc 打僵尸 定义僵尸类
- oc 打僵尸 定义僵尸类
- OC:打僵尸问题(类的问题)
- OC继承课后练习_打僵尸
- 模拟打僵尸(OC-继承题)
- OC:打僵尸问题(类的问题)
- OC前三讲小结及打僵尸的继承练习
- OC第三讲继承-模拟打僵尸
- OC-继承-初始化方法-便利构造器(练习题-打僵尸)
- Objective-C语言编写(OC)打僵尸小游戏源码
- 打僵尸。
- 打僵尸代码
- Objective-C打僵尸代码
- 植物打僵尸休闲花园外挂代码
- Objective-C中打僵尸问题解析
- .net reflactor反编译以及依赖项处理——添加新表步骤
- 引用形参可以一个函数返回多个值
- Java中Interface的用法
- 中国剩余定理
- MySql按日期进行统计(前一天、本周、某一天)
- OC 打僵尸
- Ubuntu DNS server 设置
- scala学习笔记2(类,继承,抽象类)
- github版本库使用详细教程(命令行及图形界面版)
- Leetcode--Permutation Sequence
- XMPP协议----IQ
- viewstate
- oracle public redo thread and private redo thread
- XMPP协议原理介绍