OC初识(类的定义方式以及WHILE循环在OC里的运用)

#import
#import "Zombie.h"
#import "RoadblockZombie.h"
#import "DrumZombie.h"
int main(int argc, const char * argv[])
{

    @autoreleasepool {
        Zombie *ptjs=[[Zombie alloc] initWithZombietype:@"num1" allBlood:50 per:3 hurt:NO];
        while ([ptjs getall]>0) {
            [ptjs setHurt:YES];
            [ptjs loseBlood];
        }
        [ptjs end];
        RoadblockZombie *rbjs=[[RoadblockZombie alloc] initWithZombietype:@"rbjs1" allBlood:80 per:2 rb:5 hurt:NO];
        while ([rbjs getall]>0) {
            if ([rbjs rbHurt]>0) {
                [rbjs setHurt:YES];
                NSLog(@"防御力太强,不过马上就要被瓦解了");
            }
            [rbjs setHurt:YES];
            [rbjs loseBlood];
            
        }
        [rbjs end];
        DrumZombie *drjs=[[DrumZombie alloc] initWithZombietype:@"drjs" allBlood:100 per:1 drum:5 hurt:NO];
        while ([drjs getall]>0) {
            if ([drjs drum]>0) {
                [drjs setHurt:YES];
                NSLog(@"水桶僵尸防御力太强,请坚持住!!");
            }
            [drjs setHurt:YES];
            [drjs loseBlood];
        }

        [drjs end];


通过一个小"僵尸循环至死亡"的程序,了解了WHIle循环语句在OC里的用法规范,也对类的"类名","方法"以及#import循环导入问题,有很深刻的印象,不会再犯这样的错误 了

你可能感兴趣的:(OC初识(类的定义方式以及WHILE循环在OC里的运用))