C语言程序设计报告南海军演模拟系统.docx
- 文档编号:25725385
- 上传时间:2023-06-11
- 格式:DOCX
- 页数:73
- 大小:338.65KB
C语言程序设计报告南海军演模拟系统.docx
《C语言程序设计报告南海军演模拟系统.docx》由会员分享,可在线阅读,更多相关《C语言程序设计报告南海军演模拟系统.docx(73页珍藏版)》请在冰豆网上搜索。
C语言程序设计报告南海军演模拟系统
《C语言程序设计》课程设计
实验报告
南海军演模拟系统
题目:
南海军演模拟系统
班级:
组员:
指导教师:
上交日期:
2015.11.10
一.引言
1.1背景
南海北靠中国大陆和台湾岛,东接菲律宾群岛,南邻加里曼丹岛和苏门答腊岛,西接中南半岛和马来半岛。
南海是联系中国与世界各地非常重要的海上通道,同时也是太平洋和印度洋之间的海上走廊。
从军事战略上而言,控制了南海岛礁,就意味着直接或间接的控制了从马六甲海峡到日本、从新加坡到香港、从中国广东到菲律宾马尼拉,甚至从东亚到西亚、非洲和欧洲的多数海上通道。
南海岛礁附近海域拥有丰富的资源,渔业资源、航道资源,特别是石油、天然气资源。
从航道上来讲,每年大约有4万多艘船只经过南海海域。
日本、韩国和中国台湾省,90%以上的石油输入要依赖南海这个航道;经过南海航道运输的液化天然气,占世界总贸易额的三分之二。
就中国来讲,通往国外的近40条航线中,超过一半以上的航线经过南海海域。
南海自古以来就是中国领土不可分割的一部分,在1949年前,国际上公认南海主权属于中国;80年代后期,随着南海油气田大规模的勘测和中国的崛起,周边国家纷纷插足南海,以美国为首的日本等国更是以调解者自居,罔顾事实,不断在南海搅局,南海问题越来越多边化、复杂化。
1.2编写目的
以南海军演问题为对象,建立简单的军演模型,通过简单的动画模拟出军演中飞机、军舰、潜艇的移动与攻击。
此次C语言课程设计是本专业的第一次课程设计,具有重要的意义:
通过上个学期对C语言的学习,对C语言编程有了初步的了解,获得了一定的基础但是非常缺乏实际的编程经验,无法从质上对自己的编程技巧有一个很大的提高,这次的课程设计给我们提供了一个非常好的锻炼机会。
通过二个人的分工合作,在实际中运用和训练程序设计的模块化和工程化思想和技术,努力掌握C语言精髓;同时提高自己的交流与团队合作的能力.为以后的更专业更复杂的课程设计和实践活动打好基础。
1.3任务概述
本软件旨在模拟南海军演的过程与推演。
分双方开始游戏,每回合可以选取不同种类的单位并进行攻击移动等动作,从而推演南海军演的过程与结果。
通过软件的开发过程,了解掌握软件开发的方法、技巧和基本流程。
二.需求分析
2.1需求分析
1.本软件面向的人群大概有两类:
(1)对南海问题进行军事推演的人群
(2)进行游戏对战娱乐的人群
2.操作机维护人员:
具有良好的C语言编程技术,能够充分了解软件模块,并且熟练掌握软件的数据结构。
3.软件与其使用频率:
预计软件在推广之后,将会在小范围内得到较为广泛的应用。
2.2运行环境(DOS环境)
该系统给予tc2.0和bc31开发,适用于dos3.0以上的所有dos版本和xp操作系统及以下的windows系统;本软件设计中加入了鼠标操作,因此操作过程必须依赖鼠标才能实现所有功能;本软件对于显示卡无特殊要求;本软件可以允许用户自定义一些参数,具有良好的人机交互性。
本软件主要输入方式是根据菜单选项与鼠标输入进行输入,输出则对应于相应的输入选项,除此之外无其他特殊要求。
出现图形无法显示或图形显示效果差——处理办法:
检查显示卡驱动是否正常;出现某些子程序的初始化无法正常完成——处理办法:
显示初始化失败的位置,并退出程序;出现空间分配失败——处理办法:
显示为内存不够,退出程序并检查内存利用情况;
三.系统设计
3.1功能需求描述
进入主界面,选择选项进入游戏或进入帮助界面或退出。
进入帮助界面,查看帮助信息并可返回主界面。
进入游戏,选择开始游戏并随机决定先手队伍。
进入回合,选择单位进行攻击移动或重选。
达到胜利条件,出现菜单,选择返回主界面或退出。
3.2程序流程图
3.3功能和操作简介(界面)
主界面——点击“HELP”进入帮助界面,点击“STARTPLAY”进入决定先手界面,点击“EXIT”退出程序。
帮助界面------点击“RETURN”返回主界面。
决定先手界面------点击“CLICKtoPLAY”开始选择动画。
显示先手信息------然后进入游戏界面。
游戏界面------显示回合动画
选择单位-----出现选项,点击“ATTACK”攻击,点击“MOVE”移动,点击“CANCLE”重新选择单位。
选择单位-----显示胜利队伍,出现菜单。
点击“PLAYAGAIN”返回主菜单,点击“EXIT”退出游戏。
3.4模块划分
一、图像模块:
主要是界面、图形、动画。
二、鼠标模块:
包括鼠标的图形,鼠标状态。
三、游戏模块:
游戏的主要结构与实行。
3.5结构定义
作战单位结构
structArmyunit
{
intteam;队伍信息:
1红队2蓝队
inttype;单位种类:
1ship2plane3sub
inthealthpoint;生命值
intattackpower;攻击力
intmoverange;移动范围
intx;x坐标
inty;y坐标
};
4.算法分析
4.1算法(略,详见源代码)
五.程序总结
5.1编程中的疑难点分析
1.鼠标的点击问题
因为取鼠标点击的状态按下时终止循环,会使下一次取鼠标点击状态为按下,所以选取鼠标按下后松开时终止循环。
2.单位选取的取消问题
因为选取单位后取消需要返回上一层,而循环体太过影响程序的可读性和简洁性,所以采取了函数的互相嵌套来实现。
5.2程序不足之处
1.动画不是特别流畅
2.界面还不是特别美观
3.对对战的模拟还不够贴近实际
六.组员分工
6.1组员分工
1600余行
七.参考资料
王士元.C高级实用程序设计.北京:
清华大学出版社.1996
周纯杰,刘正林等.标准C语言程序及应用.武汉:
华中科技大学出版社.2005
谭浩强.C语言程序设计.北京:
清华大学出版社,2000
陈超C语言常用函数速查手册.北京:
化学工业出版社2010
8.源代码
头文件:
/**********************************game.h**********************************/
#ifndef__game_h__
#define__game_h__
#include"graph.h"
#defineATTACKRANGE4
voidmain_iface(void);
voidhelp_iface(void);
voidstart_game(void);
voidstart_turn(int*pa,structArmyunitred[],structArmyunitblue[]);
voidstart_step(inta,structArmyunitred[],structArmyunitblue[]);
voidstart_choose(inta,inttheone,structArmyunitred[],structArmyunitblue[]);
voidstart_attack(inta,inttheone,structArmyunitred[],structArmyunitblue[]);
voidstart_move(inta,inttheone,structArmyunitred[],structArmyunitblue[]);
voidwin_iface(intt);
voidsetgamedata(structArmyunitred[],structArmyunitblue[]);
#endif
/**********************************graph.h**********************************/
#ifndef__graph_h__
#define__graph_h__
#include"mouse.h"
structArmyunit
{
intteam;//1红队2蓝队
inttype;//1ship2plane3sub
inthealthpoint;
intattackpower;
intmoverange;
intx;
inty;
};
voidarmyunitshape(intx,inty,intteam,inttype);
voidshow_main_iface(void);
voidshow_help_iface(void);
intdecidefirst(void);
voidshow_game_face(void);
voidshowarmy(structArmyunitred[],structArmyunitblue[]);
voidturnimage(inta);
voidshowturn(inta);
voidreadarmyunit(intx,inty,structArmyunitred[],structArmyunitblue[]);
voidshowmenu(inta);
voidattackimage(intx0,inty0,intx1,inty1,intdamage);
voidmoveimage(intteam,inttype,intx0,inty0,intx1,inty1);
voiddieimage(intx,inty);
voidshow_win_iface(intt);
#endif
/**********************************mouse.h**********************************/
#ifndef__mouse_h__
#define__mouse_h__
#include
#include
#include
#include
#include
#include
#include
voidinitmouse(intxmax,intymax);
intreadxy(int*mx,int*my,int*mbutt);
voidnewxy(int*mx,int*my,int*mbutt);
voidarrow(intx,inty);
voidnewchoosexy(int*mx,int*my,int*mbutt);
voidchooseshape(intx,inty);
voidgetclickxy(int*mx,int*my,int*mbutt);
#endif
定义文件:
/**********************************game.c**********************************/
#include"game.h"
voidmain_iface()
{
intx,y,button=0;
intn1,n2,n3;
show_main_iface();
x=320;
y=240;
arrow(x,y);
do
{
getclickxy(&x,&y,&button);
n1=((long)(x-540)*(x-540)+(long)(y-420)*(y-420)<34*34);
n2=((x>20)&&(x<100)&&(y>400)&&(y<440));
n3=((long)(x-320)*(x-320)+(long)(y-240)*(y-240)<80*80);
}while(!
n1&&!
n2&&!
n3);
if(n1)//结束游戏
{
;
}
elseif(n2)//帮助
{
help_iface();
}
elseif(n3)//开始游戏
{
start_game();
}
}
voidhelp_iface()
{
intx,y,button=0;
show_help_iface();
x=320;
y=240;
arrow(x,y);
do
{
getclickxy(&x,&y,&button);
}while(!
(x>10&&x<110&&y>400&&y<440));
main_iface();
}
voidstart_game()
{
inta;
structArmyunitred[15];
structArmyunitblue[15];
a=decidefirst();
setgamedata(red,blue);
start_turn(&a,red,blue);
}
voidstart_turn(int*pa,structArmyunitred[],structArmyunitblue[])
{
inti,rwcondition,bwcondition;
show_game_face();
showarmy(red,blue);
turnimage(*pa);
start_step(*pa,red,blue);
rwcondition=0;
bwcondition=0;
for(i=0;i<15;i++)
{
if(red[i].healthpoint)
rwcondition=1;
if(blue[i].healthpoint)
bwcondition=1;
}
if(rwcondition&&bwcondition)
{
show_game_face();
showarmy(red,blue);
turnimage(*pa);
start_step(*pa,red,blue);
rwcondition=0;
bwcondition=0;
for(i=0;i<15;i++)
{
if(red[i].healthpoint)
rwcondition=1;
if(blue[i].healthpoint)
bwcondition=1;
}
if(rwcondition&&bwcondition)
{
(*pa)++;
start_turn(pa,red,blue);
}
}
if(!
rwcondition)//蓝胜
win_iface
(2);
elseif(!
bwcondition)//红胜
win_iface
(1);
}
voidstart_step(inta,structArmyunitred[],structArmyunitblue[])
{
inttheone;
intx,y,button,xc,yc,buttonc;
intn,k,i;
show_game_face();
showarmy(red,blue);
showturn(a);
x=320;
y=240;
button=0;
xc=320;
yc=240;
buttonc=0;
arrow(x,y);
chooseshape((xc-40)/30*30+40,yc/30*30);
do
{
n=0;
k=0;
while(!
k)
{
newxy(&x,&y,&button);
newchoosexy(&xc,&yc,&buttonc);
readarmyunit(xc,yc,red,blue);
while(button==1)
{
newxy(&x,&y,&button);
newchoosexy(&xc,&yc,&buttonc);
k=1;
}
}
if(a%2==1)
{
for(i=0;i<15;i++)
{
if(((x-40)/30*30+40==red[i].x)&&((y/30*30)==red[i].y))
{
n=1;
theone=i;
}
}
}
else
{
for(i=0;i<15;i++)
{
if((((x-40)/30*30+40)==blue[i].x)&&((y/30*30)==blue[i].y))
{
n=1;
theone=i;
}
}
}
}while(!
n);
arrow(x,y);
chooseshape((xc-40)/30*30+40,yc/30*30);
start_choose(a,theone,red,blue);
}
voidstart_choose(inta,inttheone,structArmyunitred[],structArmyunitblue[])
{
intk,n1,n2,n3;
intx,y,button;
showmenu(a);
if(a%2==1)
chooseshape(red[theone].x,red[theone].y);
else
chooseshape(blue[theone].x,blue[theone].y);
x=320;
y=240;
button=0;
arrow(x,y);
do
{
k=0;
while(!
k)
{
newxy(&x,&y,&button);
readarmyunit(x,y,red,blue);
while(button==1)
{
newxy(&x,&y,&button);
k=1;
}
}
n1=(x>9&&x<30&&y>78&&y<142);//攻击
n2=(x>9&&x<30&&y>158&&y<222);//移动
n3=(x>9&&x<30&&y>238&&y<302);//取消
}while(!
n1&&!
n2&&!
n3);
if(a%2==1)
chooseshape(red[theone].x,red[theone].y);
else
chooseshape(blue[theone].x,blue[theone].y);
if(n1)
start_attack(a,theone,red,blue);
elseif(n2)
start_move(a,theone,red,blue);
elseif(n3)
start_step(a,red,blue);
}
voidstart_attack(inta,inttheone,structArmyunitred[],structArmyunitblue[])
{
intx,y,button;
intk,i,n1,n2;
intdamage;
intd[8]={9,78,30,78,30,222,9,222};
setcolor(WHITE);
setfillstyle(1,WHITE);
fillpoly(4,d);
n1=0;
n2=0;
x=320;
y=240;
button=0;
arrow(x,y);
if(a%2==1)
{
chooseshape(red[theone].x,red[theone].y);
do//red
{
k=0;
while(!
k)
{
newxy(&x,&y,&button);
readarmyunit(x,y,red,blue);
while(button==1)
{
newxy(&x,&y,&button);
k=1;
}
}
if((x>=40)&&(y>=30))
for(i=0;i<15;i++)
if((((x-40)/30*30+40)==blue[i].x)&&((y/30*30)==blue[i].y))
if(abs(red[theone].x-blue[i].x)/30+abs(red[theone].y-blue[i].y)/30<=ATTACKRANGE)
if(red[theone].type==1||blue[i].type==1||red[theone].type==blue[i].type)
{//条件成立,攻击
n1=1;
srand((unsigned)time(NULL));
damage=24-abs(red[theone].x-blue[i].x)/30+abs(red[theone].y-blue[i].y)/30*8;
damage=red[theone].attackpower+damage+red[theone].healthpoint/60-blue[i].healthpoint/30+rand()%10;
blue[i].healthpoint=blue[i].healthpoint-damage;
arrow(x,y);
attackimage(red[theone].x,red[theone].y,blue[i].x,blue[i].y,damage);
if(blue[i].healthpoint<=0)
{
dieimage(blue[i].x,blue[i].y);
blue[i].healthpoint=0;
blue[i].x=0;
blue[i].y=0;
}
//arrow(x,y);
break;
}
n2=(x>9&&x<30&&y>238&&y<302);//取消
}while(!
n1&&!
n2);
chooseshape(red[
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言程序设计 报告 南海 模拟 系统
![提示](https://static.bdocx.com/images/bang_tan.gif)