3、定义铁桶僵尸类:实例变量:僵尸种类、僵尸总血量、僵尸每次失血量,道具,弱点。方法:初始化方法(设置僵尸种类,总血量)、被打击失血、失去装备、死亡。

@interface IronDrumZombie : NSObject
{
    NSString *_species;    //种类
    NSInteger _totalVolume;   //总血量
    NSInteger _everyTimeLoss;  //每次失血量
    NSString *_prop;     //道具
    NSString *_weakness;    //弱点
}
//初始化
- (id)initWithSpecies:(NSString *)species totalVolume:(NSInteger)totalVolume everyTimeLoss:(NSInteger)everyTimeLoss;
//读取
- (NSString *)species;
- (NSInteger)totalVolume;
- (NSInteger)everyTimeLoss;
//剩余血量
- (NSInteger)bloodLoss;
- (NSInteger)bloodLo;
//失去装备
- (void)lossOfEquioment;
//死亡
- (void)death;
@end
@implementation IronDrumZombie
- (id)initWithSpecies:(NSString *)species totalVolume:(NSInteger)totalVolume everyTimeLoss:(NSInteger)everyTimeLoss
{
    _species = species;
    _totalVolume = totalVolume;
    _everyTimeLoss = everyTimeLoss;
    return self;
}
- (NSString *)species
{
    return _species;
}
- (NSInteger)totalVolume
{
    return _totalVolume;
}
- (NSInteger)everyTimeLoss
{
    return _everyTimeLoss;
}
- (NSInteger)bloodLoss
{
    NSInteger i = 0;
    while (_totalVolume > 50) {
        _totalVolume -= _everyTimeLoss;
        i++;
    }
    return i;
}
- (void)lossOfEquioment
{
    NSLog(@"失去装备啦");
}
- (NSInteger)bloodLo
{
    NSInteger i = 0;
    while (_totalVolume > 0) {
        _totalVolume -= 3;
        i++;
    }
    return i;
}
- (void)death
{
    NSLog(@"死亡了");
}
@end
IronDrumZombie *ir = [[IronDrumZombie alloc] initWithSpecies:@"铁桶僵尸" totalVolume:120 everyTimeLoss:1];
        NSLog(@"%@,%ld滴血,每次攻击掉%ld滴血,",[ir species],[ir totalVolume],[ir everyTimeLoss]);
        NSLog(@"僵尸来袭,准备攻击");
        NSLog(@"被打了%ld之后",[ir bloodLoss]);
        [ir lossOfEquioment];
        NSLog(@"被打了%ld之后",[ir bloodLo]);
        [ir death];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值