求用控制台应用程序(不使用MFC)C++语言编写的坦克大战游戏源代码 . 本人新手 写了一个
求用控制台应用程序(不使用MFC)C++语言编写的坦克大战游戏源代码.本人新手写了一个礼拜想要一份参考代码O求高人指点!...
求用控制台应用程序(不使用MFC)C++语言编写的坦克大战游戏源代码 . 本人新手 写了一个礼拜想要一份参考代码 O 求高人指点 !
展开
2个回答
2016-06-05
展开全部
C++实例编程:简单坦克大战2010-11-2212:40:22 作者:佚名 来源:IT哇咔搜集整理 我要评论 进入论坛 字号:T|T 核心提示: 因为有些东西以前练过了,而有些东西没练过,还有很多不足之处.#include#include#include#include#include#defineKEY_ESC0x01#defineKEY_SPACE0x39#defineKEY_UP0x48#defineKEY_LEFT0x4b#defineKEY_RIGHT0x4d#defineKEY_DOWN0x50/*1石头,2砖块,3水,5老家,8玩家,9敌人*/intmap[20][20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,2,2,2,0,0,2,2,2,2,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,2,0,0,2,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,2,2,2,2,2,2,0,0,0,0,0,0,0,2,2,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,1,1,0,1,1,1,1,3,3,3,3,0,0,0,0,0,0,0,2,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,3,3,3,0,1,1,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,3,3,3,1,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,2,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,1,1,0,2,2,0,0,0,0,2,2,2,0,0,0,2,2,0,0,0,1,1,0,0,0,0,0,0,8,2,5,2,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};strUCtf{intx;inty;intdirection;};structplay{intx;/*行坐标*/inty;/*列坐标*/intdirection;/*方向*/structffire[5];/*5颗子弹*/intscore;/*分数*/}Playone;structa{intx;inty;intcolor;intdirection;intdirectiontwo;/*用来判断走的路是否往返*/intfireplay;/*是否攻击的变量,随机生成*/structffire;}amy[5];/*敌人的结构体,其实可以添加不同的颜色来表示不同种类的坦克*/charkey_state[128],key_pressed[128];voidInit();/*图象驱动开始*/voidEnd();/*图象驱动结束*/voidDrawMap();/*画地图*/voidDrawWater(intx,inty);/*画水*/voidDrawBrick(intx,inty);/*画砖*/voidDrawTone(intx,inty);/*画石头*/voidDrawHome(intx,inty);/*画老家*/voidDrawBlack(intx,inty);/*去除内容*/voidDrawPlay(intx,inty);/*画玩家*/voidDrawAmy(intx,inty,inti);/*画敌人*/voidScore();/*输出分数*/voidGamePlay();/*玩游戏过程*/voidGameOver();/*游戏失败*/voidTimeDelay(unsignedlongmicrosec);/*延时函数传入微秒数*/intGetKey(intScanCode);/*这里开始都是按键函数*/voidinterruptfar(*OldInt9Handler)();voidfarinterruptNewInt9();voidInstallKeyboard();voidShutDownKeyboard();voidmain(void){Init();DrawMap();GamePlay();End();}voidTimeDelay(unsignedlongmicrosec)/*延时函数传入微秒数*/{unionREGSr;r.h.ah=0x86;r.x.cx=microsec>>16;r.x.dx=microsec;int86(0x15,&r,&r);}voidInit()/*图象驱动开始*/{intgd=DETECT,gm;initgraph(&gd,&gm,"d:\\tc\\tc");cleardevice();InstallKeyboard();}voidEnd()/*图象驱动结束*/{ShutDownKeyboard();closegraph();}voidDrawTone(intx,inty)/*画石头*/{setfillstyle(SOLID_FILL,7);bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);}voidDrawWater(intx,inty)/*画水*/{setfillstyle(SOLID_FILL,BLUE);bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);}voidDrawBrick(intx,inty)/*画砖*/{setfillstyle(SOLID_FILL,6);bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);setcolor(15);line(100+x*20-9,50+y*20-4,100+x*20+9,50+y*20-4);line(100+x*20-9,50+y*20+4,100+x*20+9,50+y*20+4);line(100+x*20-4,50+y*20-9,100+x*20-4,50+y*20+9);line(100+x*20+4,50+y*20-9,100+x*20+4,50+y*20+9);}voidDrawHome(intx,inty)/*画老家*/{setcolor(0);setfillstyle(SOLID_FILL,GREEN);fillellipse(100+x*20,50+y*20,9,9);}voidDrawBlack(intx,inty)/*去除内容*/{setcolor(0);setfillstyle(SOLID_FILL,0);bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);}voidDrawPlay(intx,inty)/*画玩家*/{setcolor(4);/*玩家为红色*/circle(100+x*20,50+y*20,7);switch(Playone.direction)/*判断玩家方向*/{case1:line(100+x*20,50+y*20,100+x*20,50+y*20-9);break;/*上*/case2:line(100+x*20,50+y*20,100+x*20+9,50+y*20);break;/*右*/case3:line(100+x*20,50+y*20,100+x*20,50+y*20+9);break;/*下*/case4:line(100+x*20,50+y*20,100+x*20-9,50+y*20);break;/*左*/}}voidDrawAmy(intx,inty,inti)/*画敌人*/{if(amy[i].color==12)setcolor(12);elseif(amy[i].color==13)setcolor(13);else/*这里是判断三种颜色的坦克*/setcolor(14);circle(100+x*20,50+y*20,7);switch(amy[i].direction)/*判断玩家方向*/{case1:line(100+x*20,50+y*20,100+x*20,50+y*20-9);break;/*上*/case2:line(100+x*20,50+y*20,100+x*20+9,50+y*20);break;/*右*/case3:line(100+x*20,50+y*20,100+x*20,50+y*20+9);break;/*下*/case4:line(100+x*20,50+y*20,100+x*20-9,50+y*20);break;/*左*/}}voidScore()/*输出分数*/{chars[10];Playone.score+=10;sprintf(s,"%d",Playone.score);setfillstyle(SOLID_FILL,0);bar(550,100,640,130);settextstyle(0,0,2);setcolor(YELLOW);outtextxy(550,115,s);}voidDrawMap()/*画地图*/{inti,j,k;for(i=0;i<20;i++){for(j=0;j<20;j++)if(map[i][j]==1)DrawTone(j,i);elseif(map[i][j]==2)DrawBrick(j,i);elseif(map[i][j]==3)DrawWater(j,i);elseif(map[i][j]==5)DrawHome(j,i);elseif(map[i][j]==8){Playone.x=i;Playone.y=j;Playone.direction=1;DrawPlay(j,i);for(k=0;k<5;k++)Playone.fire[k].direction=-1;/*5颗子弹的方向都为-1,表示不存在*/}elseif(map[i][j]==9){amy[0].x=1;amy[0].y=1;amy[0].direction=amy[0].directiontwo=3;/*第一个敌人*/--
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询