| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 758 人关注过本帖
标题:关于模拟一个对战游戏的程序(网易面试题)
只看楼主 加入收藏
kkq292
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-5-24
结帖率:0
收藏
已结贴  问题点数:10 回复次数:3 
关于模拟一个对战游戏的程序(网易面试题)
现在公司准备出一款中世纪背景的战略游戏。
主要兵种有骑士,弓箭手,步兵。
每个兵种有血(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
jinhuaxue
Rank: 1
等 级:新手上路
帖 子:4
专家分:3
注 册:2012-3-16
收藏
得分:3 
大师级别啊,我先是才开始接触C语言,你这些我有的还看不懂啊,不过论坛里高手多得很,会有人帮助你的。祝你好运啊
2012-05-25 00:02
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:3 
却是有难度 我估计做不出来 是让你模拟 而不是让人去选择兵种

你可以考虑下多线程去模拟

                                         
===========深入<----------------->浅出============
2012-05-25 08:55
k8481491
Rank: 1
等 级:新手上路
帖 子:1
专家分:3
注 册:2012-3-20
收藏
得分:3 
呵呵全面战争系列啊
2012-05-29 22:39
快速回复:关于模拟一个对战游戏的程序(网易面试题)
数据加载中...
 
   



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

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