| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 758 人关注过本帖
标题:关于模拟一个对战游戏的程序(网易面试题)
取消只看楼主 加入收藏
kkq292
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-5-24
结帖率:0
收藏
已结贴  问题点数:10 回复次数:0 
关于模拟一个对战游戏的程序(网易面试题)
现在公司准备出一款中世纪背景的战略游戏。
主要兵种有骑士,弓箭手,步兵。
每个兵种有血(80-200),防御(0-5),攻击力(8-20),造价(50-200)等基本数据
(可选射程,速度也可以增加其他属性)

而兵种间又有相生相克,步兵克骑兵克弓箭克步兵。

游戏策划同时要求骑士要血,功,防等指数相对优秀,但是造价高昂,
步兵指数一般,但是造价低,弓箭手造价一般,但是血和防御很低。

任务:
1:假设各个数据和数量给定,模拟两军交战场面(1000vs1000)。

2: 给定金钱(如100000),测定最优秀的数值平衡计划,
   使任何一个兵种或者战术都占有绝对优势

我写了一些用户操作界面的程序,其实并不完整,但后面的程序不知道怎么写了,还请各位高手指点,谢谢!给你代码接口也行,谢谢!
#include <stdio.h>
#include<stdlib.h>

#define RED "\033[0;32;31m"
#define GREEN "\033[0;32;32m"
#define BLUE "\033[0;32;34m"
#define BROWN "\033[0;33m"
#define CYAN "\033[0;36m"
#define PURPLE "\033[0;35m"
#define NONE "\033[m"

typedef struct type
{
    char symbol;
    int money;
    int attact;
    double rate;
    int defense;
    int blood;
    int area;
    int distance;
}Type;

void move();


int main(void)
{
    int val;

  printf("---------------------------------------------------------------|");
    printf("\n");
    printf(" 兵种   |符号|造价|攻击力|暴击率 |防御力|血量|攻击范围|移动距离");
    printf("\n");
    printf("---------------------------------------------------------------|");   
    printf("\n");
    printf(" 弓箭手 | G  |100 |  18  | 0.05  |   1  | 100|   1~3  |  1  ");
    printf("\n");
    printf("---------------------------------------------------------------|");   
    printf("\n");
    printf(" 步兵   | B  |75  |  15  | 0.08  |   3  | 150|   1    |  1  ");
    printf("\n");
    printf("---------------------------------------------------------------|");
    printf("\n");
    printf(" 骑士   | Q  |150 |  20  |  0.1  |   5  | 200|   1    |  3  ");
    printf("\n");
    printf("---------------------------------------------------------------|");
    printf("\n");

    printf("提示:兵种之间可以有相克的,比如弓箭克骑兵,骑兵克步兵,步兵克弓箭 \n");
    printf("\n");
    printf("请输入战争模式:1--1000vs1000  2--金钱模式\n");
    scanf("%d",&val);

    switch(val)
    {
      case 1:
                            {
                                int m,n;
                                printf("双方可以配置的最大人数为1000人\n");
                                printf("现在是防守方兵力部署:\n");
                                printf("请选择要配置的兵种:1--步兵   2--骑兵   3--弓箭手\n");
                                scanf("%d",&m);
                                switch(m)
                                {
                                case 1:
                                                {
                                                    printf(RED"请输入步兵的人数:\n"NONE);
                                                    scanf("%d",&m);
                                                }
                                case 2:
                                                {
                                                    printf(GREEN"请输入骑兵的人数:\n"NONE);
                                                    scanf("%d",&m);
                                                }
                                case 3:
                                                {
                                                    printf(BLUE"请输入弓箭手的人数:\n"NONE);
                                                    scanf("%d",&m);
                                                }
                                }
                                printf("\n");
                                printf("现在是进攻方兵力部署:\n");
                                printf("请选择要配置的兵种:1--步兵   2--骑兵   3--弓箭手\n");
                                scanf("%d",&n);
                                switch(n)
                                {
                                    case 1:
                                                    {
                                                        printf(BROWN"请输入步兵的人数:\n"NONE);
                                                        scanf("%d",&n);
                                                    }
                                    case 2:
                                                    {
                                                        printf(CYAN"请输入骑兵的人数:\n"NONE);
                                                        scanf("%d",&n);
                                                    }
                                    case 3:
                                                    {
                                                        printf(PURPLE"请输入弓箭手的人数:\n"NONE);
                                                        scanf("%d",&n);
                                                    }
                                }   
                                printf("游戏开始:\n");
                                break;
                        }
    case 2:
                    {
                    int money,m,n;
                    printf("请输入双方拥有的金钱数:\n");
                    scanf("%d",&money);
                    printf("现在是防守方兵力部署:\n");
                    printf("请选择需要购买的兵种:1--步兵   2--骑兵   3--弓箭手\n");
                    scanf("%d",&m);
                    switch(m)
                    {
                        int bu,qi,gj;
                        case 1:
                                        {
                                            printf(RED"请输入购买步兵的人数:\n"NONE);
                                            scanf("%d",&bu);
                                            if(bu*75<money)
                                            printf("还剩余的金钱数%d:\n",money-(bu*75));
                                        }
                        case 2:
                                        {                    
                                            printf(GREEN"请输入购买骑兵的人数:\n"NONE);
                                            scanf("%d",&qi);
                                            if(qi*150<(money-(bu*75)))
                                            printf("还剩余的金钱数%d:\n",money-(qi*150+bu*75));
                                        }
                        case 3:
                                        {
                                            printf(BLUE"请输入购买弓箭手的人数:\n"NONE);
                                            scanf("%d",&gj);
                                            if(gj*100<(money-(qi*150+bu*75)))
                                            printf("还剩余的金钱数%d:\n",money-(gj*100+qi*150+bu*75));
                                        }
                    }
                    printf("现在是进攻方兵力部署:\n");
                    printf("请选择需要购买的兵种:1--步兵   2--骑兵   3--弓箭手\n");
                    scanf("%d",&n);
                    switch(n)
                    {
                        int bu,qi,gj;
                        case 1:
                                        {
                                            printf(RED"请输入购买步兵的人数:\n"NONE);
                                            scanf("%d",&bu);
                                            if(bu*75<money)
                                            printf("还剩余的金钱数%d:\n",money-(bu*75));
                                        }
                        case 2:
                                        {                    
                                            printf(GREEN"请输入购买骑兵的人数:\n"NONE);
                                            scanf("%d",&qi);
                                            if(qi*150<(money-(bu*75)))
                                            printf("还剩余的金钱数%d:\n",money-(qi*150+bu*75));
                                        }
                        case 3:
                                        {
                                            printf(BLUE"请输入购买弓箭手的人数:\n"NONE);
                                            scanf("%d",&gj);
                                            if(gj*100<(money-(qi*150+bu*75)))
                                            printf("还剩余的金钱数%d:\n",money-(gj*100+qi*150+bu*75));
                                        }
                    }
                    printf("游戏开始:\n");
                    break;
                    }
    }

    return 0;
}
搜索更多相关主题的帖子: 造价 攻击力 计划 
2012-05-24 22:50
快速回复:关于模拟一个对战游戏的程序(网易面试题)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027420 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved