C++课程设计报告.docx
- 文档编号:25451459
- 上传时间:2023-06-08
- 格式:DOCX
- 页数:31
- 大小:165.02KB
C++课程设计报告.docx
《C++课程设计报告.docx》由会员分享,可在线阅读,更多相关《C++课程设计报告.docx(31页珍藏版)》请在冰豆网上搜索。
C++课程设计报告
《面向对象编程技术》
课程设计实验报告
——————坦克二
班级:
软124
姓名:
张景东
学号:
129074282
指导教师:
胡增涛
设计完成时间:
2013/12/24
1、程序名称
2、设计目的
3、程序设计的意义
4、功能介绍
5、开发平台
6、课程设计总体规划
1、处理流程图
2、结构模块分析
7、主要代码
8、运行效果抓图
9、创新和难点
10、课程设计中目前存在的问题
11、心得体会
1、程序名称
以《坦克大战》游戏为题材,自己动手,从零开始,写出简单坦克小游戏-----坦克二。
二、设计目的
1、进一步掌握C++进行类的定义和操作方法;
2、学习和掌握C++程序设计方法以及上机调试技巧,为以后学校其他专业课程打好基础;
3、能够培养我们独立分析问题、解决问题、查阅资料以及自学的能力,以适应计算机只是日新月异发展的形式;
4、程序设计的目的不单单是课堂上的学习,我觉得最重要的是让我们学生掌握程序设计的思想与方法。
在课程设计的过程中,我们充分运用我们课堂上学习到的知识,并且复习C语言中的函数等知识点。
在这个过程中,我们能够不断提高对C++面向对象程序设计的理解,最终能够独立自主解决一些问题。
三、程序设计的意义
大学最重要无疑是动手能力与自学能力的培养,课程设计明显给了我们这样的一个机会。
遇到瓶颈的时候,我们需要去图书馆查阅书籍,代码错误的时候我们需要反复的调试,在这个过程中,我们的动手能力以及自学能力都在不知不觉中得到了很大的提升。
回顾起此次课程设计,我还是感慨颇多,从理论到实践,在这几乎一个学期的时间里(课程设计是C++第一次上课的时候提出来的),我学到了很多很多的东西,不仅巩固了以前所学过的C语言方面的知识,而且自己也去图书馆查阅资料学到了很多。
通过这次的课程设计使我懂得了理论与实际结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践结合起来,从理论中得出结论,才是自己真正掌握了的,属于自己的知识,才能提高自己的实际动手能力和独立思考的能力。
在课程设计的过程中遇到了各种各样的问题,同时在设计的过程中也发现了自己的不足之处,对以前所学的知识理解的不够深刻,掌握的不够牢固,通过这次课程设计,把以前所学的知识重新温故,巩固了所学的知识。
4、功能介绍
在坦克二程序中,小坦克能够上下左右自由移动,飞机能够左右移动,并且能够发射子弹,飞机每次只能发一颗子弹但是坦克可以多发子弹连续发射,在坦克子弹打中飞机或者飞机子弹打中坦克之后,游戏结束。
5、开发平台
操作系统:
win7
开发软件:
MirosoftVisualC++6.0
6、课程设计总体规划
1、处理流程图
N
Y
N
Y
2、结构模块分析
Tankwar类是Bullet类、Tank类、Plane类的服务类,Tankwar类内部只有几个函数。
7、主要代码
/*子弹类*/
classBullet{
public:
voidshowTankBullet(){
printf("T");
}
voidshowPlaneBullet(){
printf("F");
}
Bullet(intX,intY){
x=X;
y=Y;
next=NULL;
}
Bullet(){
x=36;
y=23;
next=NULL;
}
voidsetlocationBullet(intX,intY){
x=X;
y=Y;
}
voidmove_up(){
gotoxy(x,y);
printf("");
//setlocationBullet(x,y-1);
if(y!
=0)
{
y--;
gotoxy(x,y);
showTankBullet();
}
}
intgetX(){
returnx;
}
intgetY(){
returny;
}
~Bullet(){}
Bullet*next;
private:
intx,y;
};
//飞机类
classPlane{
public:
voidshowPlane(){
gotoxy(x,y-2);
printf("Y");
gotoxy(x,y-1);
printf("Y");
gotoxy(x-1,y);
printf("YYY");
gotoxy(x,y+1);
printf("Y");
}
Plane(intX=1,intY=2){
x=X;
y=Y;
mmm=0;
}
voidsetlocationPlane(intX,intY){
x=X;
y=Y;
}
voidmove(){
if(mmm==2)
{
intX=x,Y=y;
mmm=0;
deletePlane(X,Y);
if(X==78)X=0;//飞机如果到达最右边,则返回最左边
setlocationPlane(X+1,Y);
showPlane();
}
mmm++;
}
voiddeletePlane(intx_myplane,inty_myplane){
gotoxy(x_myplane,y_myplane-2);
printf("");
gotoxy(x_myplane,y_myplane-1);
printf("");
gotoxy(x_myplane-1,y_myplane);
printf("");
gotoxy(x_myplane,y_myplane+1);
printf("");
}
intgetX(){
returnx;
}
intgetY(){
returny;
}
~Plane(){}
intjudge_bulletoftank_plane(Bullet*head);
private:
intx,y,mmm;
};
intPlane:
:
judge_bulletoftank_plane(Bullet*head)
{
Bullet*p1;
inta,b;
p1=head;
while(p1!
=NULL)
{
a=p1->getX();b=p1->getY();
if((a==(x-1)&&b==y)||(a==x&&b==(y+1))||(a==x+1&&b==y)||(a==x&&b==y))
return1;
p1=p1->next;
}
return0;
}
/*TANK类*/
classTank{
public:
voidshowTank(){
gotoxy(x+1,y-1);
printf("W");
gotoxy(x,y);
printf("WWW");
}
voidsetLocationofTank(intX,intY){
x=X;
y=Y;
}
Tank(intX=35,intY=24)
{
x=X;
y=Y;
}
intgetX(){
returnx;
}
intgetY(){
returny;
}
~Tank(){}
voiddeleteTank(intx_myTank,inty_myTank){
gotoxy(x_myTank+1,y_myTank-1);
printf("");
gotoxy(x_myTank,y_myTank);
printf("");
}
voidmove_to_left()
{
intX=x,Y=y;
if(X==0)X++;
setLocationofTank(X-1,Y);
deleteTank(X,Y);
//gotoxy(x_myTank-1,y_myTank);
showTank();
}
Bullet*creat_bullet(Bullet*head,Bullet*bullet);
voidbullet_fired(Bullet*head);
Bullet*destroy_bullet(Bullet*head);
intjudge_bullet_of_plane_tank(Bullet*head,intx_plane_bullet,inty_plane_bullet);
voidmove_to_right();
voidmove_to_up();
voidmove_to_down();
voidmove(charch);
private:
intx,y;
};
intTank:
:
judge_bullet_of_plane_tank(Bullet*head,intx_plane_bullet,inty_plane_bullet)
{
Bullet*p1;
inta,b;
p1=head;
while(p1!
=NULL)
{
a=p1->getX();b=p1->getY();
if(a==x_plane_bullet&&b==y_plane_bullet)
return1;
p1=p1->next;
}
return0;
}
Bullet*Tank:
:
destroy_bullet(Bullet*head)
{
Bullet*p1,*p2;
if(head==NULL)
returnhead;
else
p1=head;
while(0!
=p1->getY()&&p1->next!
=NULL)
{
p2=p1;
p1=p1->next;
}
if(0==p1->getY())
{
if(p1==head)
{
gotoxy(p1->getX(),p1->getY());
printf("");
head=p1->next;
deletep1;
}
else
{
gotoxy(p1->getX(),p1->getY());
printf("");
p2->next=p1->next;
deletep1;
}
}
returnhead;
}
voidTank:
:
bullet_fired(Bullet*head)
{
Bullet*p1;
p1=head;
if(p1!
=NULL)
{
p1->move_up();
while(p1->next!
=NULL)
{
p1=p1->next;
p1->move_up();
}
}
}
Bullet*Tank:
:
creat_bullet(Bullet*head,Bullet*bullet)
{
Bullet*p0,*p1;
p1=head;
p0=bullet;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
elseif(head!
=NULL)
{
if(p1->next==NULL)
{
p1->next=p0;
p0->next=NULL;
}
else
{
while
(1)
{
p1=p1->next;
if(p1->next==NULL)
{
p1->next=p0;
p0->next=NULL;
break;
}
}
}
}
returnhead;
}
voidTank:
:
move_to_right()
{
intX=x,Y=y;
if(X==77)X--;
setLocationofTank(X+1,Y);
deleteTank(X,Y);
//gotoxy(x_myTank+1,y_myTank);
showTank();
}
voidTank:
:
move_to_up()
{
intX=x,Y=y;
if(Y==5)Y++;
setLocationofTank(X,Y-1);
deleteTank(X,Y);
//gotoxy(x_myTank,y_myTank-1);
showTank();
}
voidTank:
:
move_to_down()
{
intX=x,Y=y;
if(Y==24)Y--;
setLocationofTank(X,Y+1);
deleteTank(X,Y);
showTank();
}
voidTank:
:
move(charch)
{
if(ch=='a')//左移动
move_to_left();
elseif(ch=='d')//右移动
move_to_right();
elseif(ch=='w')//上移动
move_to_up();
elseif(ch=='s')//下移动
move_to_down();
}
//坦克大战处理类
classtankwar{
public:
intcover();
voidshowsuccess(intx_myplane,inty_myplane);
voidshowfailure(intx,inty);
voidthe_picture_of_success(inttemp,intcount);
//voiddelay(DWORDdur);
voidshow_unexpected(intx_plane_bullet,inty_plane_bullet);
voidinitialization()
{
gotoxy(35,24);
myTank.showTank();
myPlane.showPlane();
}
private:
voidthe_way_to_play_game();
voidattention_place();
TankmyTank;
PlanemyPlane;
};
inttankwar:
:
cover(){
printf("\n\n\n");
cout<<"********************************************"< cout<<"**设计者: 张景东**"< cout<<"**设计时间: 2013/10/25**"< cout<<"****"< cout<<"**欢迎使用! ! ! **"< cout<<"********************************************"< cout<<"Doyouwanttostartthegame? (yorn)"< charch; cin>>ch; if(ch=='y'||ch=='Y') { while (1){ system("cls"); printf("\n\n\n"); cout<<"********************************************"< cout<<"**1.使用方法**"< cout<<"**2.注意事项**"< cout<<"**3.开始游戏**"< cout<<"**请选择: **"< cout<<"********************************************"< intn; scanf("%d",&n); if(n==3)return1; if(n==1) { system("cls"); the_way_to_play_game(); } if(n==2){ system("cls"); attention_place(); } } } if(ch=='n'||ch=='N')return0; } voidtankwar: : the_way_to_play_game() { printf("\n\n\n"); cout<<"********************************************"< cout<<"**W上**"< cout<<"**ASD左下右J发射子弹**"< cout<<"****"< cout<<"**注意: 按空格键可以中途退出游戏**"< cout<<"********************************************"< delay(3000); } voidtankwar: : attention_place(){ printf("\n\n\n"); cout<<"********************************************************************************"< cout<<"1.你不打飞机的话,飞机也不会打你的"< cout<<"2.最开始你发两颗子弹飞机才会打你一次,把握住这个机会消灭飞机"< cout<<"3.在打飞机的过程中,你移动的越频繁飞机发射子弹打你的次数会越多"< cout<<"********************************************************************************"< delay(6000); } voidtankwar: : showsuccess(intx_myplane,inty_myplane) { inti=15; while(i--){ gotoxy(x_myplane,y_myplane-2); printf("-"); gotoxy(x_myplane,y_myplane-1); printf("-"); gotoxy(x_myplane-1,y_myplane); printf("---"); gotoxy(x_myplane,y_myplane+1); printf("-"); delay(100); gotoxy(x_myplane,y_myplane-2); printf("*"); gotoxy(x_myplane,y_myplane-1); printf("*"); gotoxy(x_myplane-1,y_myplane); printf("***"); gotoxy(x_myplane,y_myplane+1); printf("*"); delay(100); } } voidtankwar: : showfailure(intx_myTank,inty_myTank) { system("cls"); inti=15; while(i--) { gotoxy(x_myTank-1,y_myTank); printf("+"); gotoxy(x_myTank,y_myTank); printf("+"); gotoxy(x_myTank+1,y_myTank); printf("+"); gotoxy(x_myTank,y_myTank-1); printf("+"); delay(90); gotoxy(x_myTank-1,y_myTank); printf("-"); gotoxy(x_myTank,y_myTank); printf("-"); gotoxy(x_myTank+1,y_myTank); printf("-"); gotoxy(x_myTank,y_myTank-1); printf("-"); delay(90); } } voidtankwar: : the_picture_of_success(inttemp,intcount) { if(temp==1){ printf("\n\n\n\n"); printf("恭喜你成功打掉灰机! ! ! ! 您的命中率为百分之%.2f! ! ! ! \n继续加油哈,亲。 。 。 。 满意的话记得给个赞哈",100.0/count); } else{ system("cls"); printf("\n\n\n\n"); printf("很遗憾你没有打掉灰机! ! ! ! 你以后还是不要打飞机了吧。 。 。 。 "); } } voidtankwar: : show_unexpected(intx_plane_bullet,inty_plane_bullet) { inti=5; while(i--) { gotoxy(x_plane_bullet,y_plane_bullet); printf("*"); delay(90); gotoxy(x_plane_bullet-1,y_plane_bullet); printf("***"); delay(90); gotoxy(x_plane_bullet-1,y_plane_bullet); printf(""); } } 8、运行效果抓图 1、主界面 2、选择界面 3、使用方法界面 4、注意事项界面 5、游戏初始化界面 6、坦克连续多发子弹与飞机发子弹界面 7、飞机被打中界面(飞机在闪烁) 8、坦克被打中界面(坦克在闪烁) 9、飞机子弹与坦克子弹相碰,也会爆炸,出现闪烁,但因为抓拍不到此界面,故这里就不显示出来了 9、创新和难点 创新: 坦克
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 课程设计 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)