关闭

试做游戏

61人阅读 评论(0) 收藏 举报
分类:

‼️  这里没有类


//
//  main.m
//  试做
//
//  Created by 刘佳斌 on 15/11/17.
//  Copyright © 2015年 刘佳斌. All rights reserved.
//

/*
1、定义一个英雄类、怪物类、技能类、武器类、衣服类
2、英雄类:名字、攻击力、血量、防御力、初始技能、初始武器、初始化装备
3、怪物类:名字、攻击力、血量、防御力
4、技能类:名字、伤害
5、武器类:名字、伤害
6、衣服类:名字、防御
7、英雄可以使用选择武器、衣服、技能的方法
8、怪物可以使用技能 的方法
*/

#import <Foundation/Foundation.h>
#import "Hero.h"
#import "Monster.h"
#import "Skills.h"
#import "Weapons.h"
#import "Clothes.h"
#import "NSString+Input.h"
#import "stdlib.h"
int main(int argc, const char * argv[]) {
    
    @autoreleasepool {
        int heroPower = 0;
        int monHp = 0;
        int monDef = 0;
        
        Hero *wuKong = [[Hero alloc] init];
        [wuKong setHeName:@"悟空"];
        [wuKong setHePower:150];
        [wuKong setHeHp:900];
        [wuKong setHeDef:60];
     
        
        Hero *baJie = [[Hero alloc] init];
        [baJie setHeName:@"八戒"];
        [baJie setHePower:100];
        [baJie setHeHp:600];
        [baJie setHeDef:80];
        
        Monster *baiGuJing = [[Monster alloc]init];
        [baiGuJing setMoName:@"白骨精"];
        [baiGuJing setMoPower:60];
        [baiGuJing setMoHp:400];
        [baiGuJing setMoDef:30];
        
        Monster *hongHai = [[Monster alloc]init];
        [hongHai setMoName:@"红孩儿"];
        [hongHai setMoPower:100];
        [hongHai setMoHp:500];
        [hongHai setMoDef:50];
        
        Skills *heroS1 = [[Skills alloc]init];
        [heroS1 setSkName:@"平砍"];
        [heroS1 setSkPower:50];
        
        Skills *heroS2 = [[Skills alloc]init];
        [heroS2 setSkName:@"战吼"];
        [heroS2 setSkPower:80];
        
        Skills *heroS3 = [[Skills alloc]init];
        [heroS3 setSkName:@"怒杀"];
        [heroS3 setSkPower:150];
        
        Weapons *weapon1 = [[Weapons alloc]init];
        [weapon1 setWeName:@"菜刀"];
        [weapon1 setWePower:10];
        
        Weapons *weapon2 = [[Weapons alloc]init];
        [weapon2 setWeName:@"金箍棒"];
        [weapon2 setWePower:50];
        
        Weapons *weapon3 = [[Weapons alloc]init];
        [weapon3 setWeName:@"猪耙"];
        [weapon3 setWePower:30];
        
        Clothes *cloth1 = [[Clothes alloc]init];
        [cloth1 setClName:@"布衣"];
        [cloth1 setClDef:30];
        
        Clothes *cloth2 = [[Clothes alloc]init];
        [cloth2 setClName:@"锁子甲"];
        [cloth2 setClDef:50];
        
        Clothes *cloth3 = [[Clothes alloc]init];
        [cloth3 setClName:@"兰盾"];
        [cloth3 setClDef:80];
        
        
        NSLog(@"请选择你要的英雄 1.孙悟空       2.猪八戒    ");
        NSString *get = [NSString getInputString];
        
        if ([get isEqualToString:@"1"]) {
            NSLog(@"你选择了悟空");
            NSLog(@"你选择了%@,他的战斗力为%d,血量有%d,防御力为%d,初始技能%@,初始武器%@,初始装备%@",[wuKong getHeName],[wuKong getHePower],[wuKong getHeHp],[wuKong getHeDef],[heroS1 getSkName],[weapon1 getWeName],[cloth1 getClName]);
            heroPower = [wuKong getHePower];  //把攻击力赋值给全局变量
        }
        else if([get isEqualToString:@"2"]){
           NSLog(@"你选择了%@,他的战斗力为%d,血量有%d,防御力为%d,初始技能%@,初始武器%@,初始装备%@",[baJie getHeName],[baJie getHePower],[baJie getHeHp],[baJie getHeDef],[heroS1 getSkName],[weapon1 getWeName],[cloth1 getClName]);
            heroPower = [baJie getHePower];  //把攻击力赋值给全局变量
        }
        NSLog(@"请选择是否装备武器  1.YES    2.NO");
        NSString *get1 = [NSString getInputString];
        if ([get1 isEqualToString:@"1"]) {
            NSLog(@"请选择你要的武器 1.菜刀       2.金箍棒      3.猪耙");
            NSString *getW = [NSString getInputString];
            if ([getW isEqualToString:@"1"]&&[get isEqualToString:@"1"]) {
                NSLog(@"你选择了%@,此时英雄%@的战斗力为%d",[weapon1 getWeName],[wuKong getHeName],[wuKong getHePower]+[weapon1 getWePower]);
                heroPower += [weapon1 getWePower];
            }
            else if ([getW isEqualToString:@"1"]&&[get isEqualToString:@"2"])
            {
             NSLog(@"你选择了%@,此时英雄%@的战斗力为%d",[weapon1 getWeName],[baJie getHeName],[baJie getHePower]+[weapon1 getWePower]);
                heroPower += [weapon1 getWePower];
            }
            else if ([getW isEqualToString:@"2"]&&[get isEqualToString:@"1"])
            {
            NSLog(@"你选择了%@,此时英雄%@的战斗力为%d",[weapon2 getWeName],[wuKong getHeName],[wuKong getHePower]+[weapon2 getWePower]);
                 heroPower += [weapon2 getWePower];
            }
            else if ([getW isEqualToString:@"2"]&&[get isEqualToString:@"2"])
            {
             NSLog(@"你选择了%@,此时英雄%@的战斗力为%d",[weapon2 getWeName],[baJie getHeName],[baJie getHePower]+[weapon2 getWePower]);
                heroPower += [weapon2 getWePower];
            }
            else if ([getW isEqualToString:@"3"]&&[get isEqualToString:@"1"])
            {
                NSLog(@"你选择了%@,此时英雄%@的战斗力为%d",[weapon3 getWeName],[wuKong getHeName],[wuKong getHePower]+[weapon3 getWePower]);
                 heroPower += [weapon3 getWePower];
            }
            else if ([getW isEqualToString:@"3"]&&[get isEqualToString:@"2"])
            {
            NSLog(@"你选择了%@,此时英雄%@的战斗力为%d",[weapon3 getWeName],[baJie getHeName],[baJie getHePower]+[weapon3 getWePower]);
                 heroPower += [weapon3 getWePower];
            }
            
        }
        else
        {
            if ([get isEqualToString:@"1"]) {
                NSLog(@"你选择了%@,此时英雄%@的战斗力为%d",[weapon1 getWeName],[wuKong getHeName],[wuKong getHePower]+[weapon1 getWePower]);
                heroPower += [weapon1 getWePower];
            }
            else if ([get isEqualToString:@"2"]){
             NSLog(@"你选择了%@,此时英雄%@的战斗力为%d",[weapon1 getWeName],[baJie getHeName],[baJie getHePower]+[weapon1 getWePower]);
                heroPower += [weapon1 getWePower];
            }
        }
        
        NSLog(@"请选择是否装备衣服  1.YES    2.NO");
        NSString *get2 = [NSString getInputString];
        if([get2 isEqualToString:@"1"]){
            NSLog(@"请选择要选择的衣服  1.布衣    2.锁子甲     3.兰盾");
            NSString *getC = [NSString getInputString];
            if ([getC isEqualToString:@"1"]&&[get isEqualToString:@"1"])  {
                NSLog(@"你选择了%@,此时英雄%@的防御力为%d",[cloth1 getClName],[wuKong getHeName],[wuKong getHeDef]+[cloth1 getClDef]);
            }
            else if ([getC isEqualToString:@"1"]&&[get isEqualToString:@"2"]){
            NSLog(@"你选择了%@,此时英雄%@的防御力为%d",[cloth1 getClName],[baJie getHeName],[baJie getHeDef]+[cloth1 getClDef]);
            }
            
            else if ([getC isEqualToString:@"2"]&&[get isEqualToString:@"1"])
            {
            NSLog(@"你选择了%@,此时英雄%@的防御力为%d",[cloth2 getClName],[wuKong getHeName],[wuKong getHeDef]+[cloth2 getClDef]);
            }
            
            else if ([getC isEqualToString:@"2"]&&[get isEqualToString:@"2"])
            {
            NSLog(@"你选择了%@,此时英雄%@的防御力为%d",[cloth2 getClName],[baJie getHeName],[baJie getHeDef]+[cloth2 getClDef]);
            }
            
            else if ([getC isEqualToString:@"3"]&&[get isEqualToString:@"1"])
            {
             NSLog(@"你选择了%@,此时英雄%@的防御力为%d",[cloth1 getClName],[wuKong getHeName],[wuKong getHeDef]+[cloth1 getClDef]);
            }
            
            else if([getC isEqualToString:@"3"]&&[get isEqualToString:@"2"])
            {
             NSLog(@"你选择了%@,此时英雄%@的防御力为%d",[cloth3 getClName],[baJie getHeName],[baJie getHeDef]+[cloth3 getClDef]);
            }
        }
        NSLog(@"夜深人静杀人夜...");
        NSString *get3 = [NSString stringWithFormat:@"%d",arc4random()%2+1];  //将随机数格式转换成字符
        if ([get3 isEqualToString:@"1"]) {
            NSLog(@"%@出现,她的血量为%d,防御为%d",[baiGuJing getMoName],[baiGuJing getMoHp],[baiGuJing getMoDef]);
            monHp = [baiGuJing getMoHp];
            monDef = [baiGuJing getMoDef];
        }
        else if ([get3 isEqualToString:@"2"])
        {
            NSLog(@"%@出现,她的血量为%d,防御为%d",[hongHai getMoName],[hongHai getMoHp],[hongHai getMoDef]);
            monHp = [hongHai getMoHp];
            monDef = [hongHai getMoDef];
            
        }
        
        NSLog(@"攻击吧少年");
        
        while (1) {
            NSLog(@"选择攻击技能  1.平砍   2.战吼   3.怒杀");
            NSString *getS = [NSString getInputString];
            if([getS isEqualToString:@"1"]){
                heroPower += [heroS1 getSkPower];
                monHp = monHp - heroPower + monDef;
                heroPower -= [heroS1 getSkPower];
                if(monHp <= 0){
                    NSLog(@"妖怪死了");exit(0);
                }
                else NSLog(@"妖怪血量还有%d",monHp);
            }
            else if([getS isEqualToString:@"2"])
            {
                heroPower += [heroS2 getSkPower];
                monHp = monHp - heroPower + monDef;
                heroPower -= [heroS2 getSkPower];
                if(monHp <= 0){
                    NSLog(@"妖怪死了");exit(0);
                }
                else NSLog(@"妖怪血量还有%d",monHp);
            }
            else if ([getS isEqualToString:@"3"])
            {
                heroPower += [heroS3 getSkPower];
                monHp = monHp - heroPower + monDef;
                heroPower -= [heroS3 getSkPower];
                if(monHp <= 0){
                    NSLog(@"妖怪死了"); exit(0);
                }
                else NSLog(@"妖怪血量还有%d",monHp);
            }
                
        }
        
    }
    return 0;
}








0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2536次
    • 积分:363
    • 等级:
    • 排名:千里之外
    • 原创:36篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档