c语言编写坦克大战源代码文档格式.docx
- 文档编号:22432091
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:15
- 大小:17.32KB
c语言编写坦克大战源代码文档格式.docx
《c语言编写坦克大战源代码文档格式.docx》由会员分享,可在线阅读,更多相关《c语言编写坦克大战源代码文档格式.docx(15页珍藏版)》请在冰豆网上搜索。
//初始化游戏空间
for(inty=1;
y!
=high-1;
y++){
for(intx=1;
x!
=wide-1;
x++){
gameSpace[y][x].have=false;
gameSpace[y][x].kind=0;
gameSpace[y][x].no=0;
}
}
//添加地图
map.load(gameSpace,no);
//初始化自己坦克
me.init_xy();
me.trans_direction
(1);
me.set_no(0);
me.init_move(gameSpace,wide/2-2,high-5);
//按顺序诞生敌人坦克
creatPlace=0;
=3;
i++){
freezeTime[i]=REBIRTHTIME;
enemy[i].init_xy();
enemy[i].set_kind
(2);
enemy[i].set_no(i+1);
reset(enemy[i]);
//数目初始化
leftCount=17;
existCount=3;
//显示图片
me.draw_tank();
enemy[i].draw_tank();
map.draw();
~TankGame()
if(wall)
deletewall;
if(gameSpace){
for(inti=0;
delete[]gameSpace[i];
delete[]gameSpace;
reset(Tank&
tank)
boolsuccess=false;
intt=3;
while(t&
&
!
success){
creatPlace++;
if(creatPlace==4)
creatPlace=1;
//诞生地点选择
switch(creatPlace){
case1:
tank.trans_direction(3);
//朝下
if(tank.reset(gameSpace,1,1))
success=true;
break;
case2:
if(tank.reset(gameSpace,wide/2-2,1))
case3:
if(tank.reset(gameSpace,wide-4,1))
if(!
success)
t--;
start()
charcommand;
enter_picture(command);
if(command!
=ENTER)
return;
while(me.blood>
0){
//initdataforruning
load_init();
//runatask
runing_a_task();
//determinewhyreturn
if(me.blood>
no++;
if(no>
map.total){
success_gameover();
break;
}
charcommand;
turn_to_next_task(command);
if(command!
}
elsegame_over();
//void
runing_a_task()
while((leftCount||existCount)&
me.blood){
clock_tnow=clock();
charcommand=-1;
//主人命令
while(clock()-now<
TIME_UNIT)//小于一个时间片,暂停
update_keyBoard_char(command);
/*更新敌人坦克*/
if(enemy[i].blood==0)
continue;
if(enemy[i].freezeTime==0){
enemy[i].rand_direction(gameSpace);
//产生随机方向
}
else{
if(enemy[i].speed==0){
enemy[i].move(gameSpace);
if(bullet[i+1].disapper){
intshot=-1;
bullet[i+1]=enemy[i].rand_shot(gameSpace,i+1,shot);
if(shot==0)
me.be_shot(gameSpace);
bullet[i+1].registration(gameSpace);
}
enemy[i].freezeTime--;
}else{
enemy[i].speed--;
}
/*更新自己坦克*/
if(command>
=0&
command<
4){
me.trans_to_direction(command);
me.move(gameSpace);
/*更新子弹*/
=4;
i++){
if(!
bullet[i].disapper){//存在的子弹
intshot;
bullet[i].move(gameSpace,shot);
//运行,是否射中
if(shot==0)
me.be_shot(gameSpace);
elseif(shot>
=1&
shot<
=3){
enemy[shot-1].be_shot(gameSpace);
existCount--;
}elseif(shot>
=7&
=10){
bullet[shot-7].unregistration(gameSpace);
bullet[shot-7].clear();
bullet[shot-7].init(bullet[shot-7].kind);
/*自己产生子弹*/
if(bullet[0].disapper){
if(command==32){
bullet[0]=me.make_bullet(gameSpace,0,shot);
if(shot>
bullet[0].registration(gameSpace);
/*诞生缺损敌人*/
if(leftCount>
for(inti=0;
if(enemy[i].blood==0){
if(freezeTime[i]==0){
freezeTime[i]=REBIRTHTIME;
reset(enemy[i]);
existCount++;
leftCount--;
}
elsefreezeTime[i]--;
}
update_keyBoard_char(char&
c)
if(_kbhit()){
c=getch();
if(c==-32){
c=getch();
if(c!
=UP&
c!
=DOWN&
=LEFT&
=RIGHT)
c=-1;
elseif(c==RIGHT)
c=0;
elseif(c==UP)
c=1;
elseif(c==LEFT)
c=2;
else
c=3;
else
c=32;
enter_picture(char&
command)
stringcaptions[6];
captions[0]="
◥◣◢◤■■■■■◥◣◢◤"
;
captions[1]="
◥◣◢◤◢◤◥◣◢◤"
captions[2]="
◥◣◢◤◢◤◥◣◢◤"
captions[3]="
◢◤◢◤◢◤◥◣"
captions[4]="
◢◤◢◤◢◤◥◣"
captions[5]="
◢◤■■■■■◢◤◥◣"
strings="
"
color(0x0e);
=6;
grid(7,6+i,captions[i]);
Frameframe(30,15);
frame.draw_frame(4,19,0x09);
stringsentence[3];
sentence[0]="
Thissmallgameismadebyyzxin2010."
sentence[1]="
Wlecometoplayit."
sentence[2]="
AllRightsReserved."
for(intk=0;
k!
=sentence[i].size();
k++){
grid(14+k,21+2*i,sentence[i][k]);
sleep(50);
}
sleep(1000);
grid(7,28,"
Enter:
开始ESC:
退出"
);
while(true){
if(_kbhit()){
command=getch();
if(command==ENTER||command==ESC)
//clearscreenpictureinwall
clear_picture();
turn_to_next_task(char&
command)
grid(18,20,"
第"
grid(20,20,no);
grid(22,20,"
关"
grid(18,20,"
success_gameover()
frame.draw_frame(4,10,0x09);
CongratulationsforSuccessfullyfinishingalltasks"
Thankyouforusingitdeeply."
Andwelcometouseitnexttime."
grid(12+k,14+2*i,sentence[i][k]);
charcommand=getch();
game_over()
frame.draw_frame(4,15,0x09);
stringsentence[4];
Gameover,butyoucantryitagain."
sentence[3]="
Allrightsreserved.(Violatorswillbeprosecuted.)."
=4;
grid(13+k,18+2*i,sentence[i][k]);
clear_picture()
intcirX=wide/2;
intcirY=high/2;
intdepth=cirY>
cirX?
cirY+2:
cirX+2;
intlx,rx,uy,by;
intl,r,u,b;
=depth;
lx=cirX-i;
rx=cirX+i;
uy=cirY-i;
by=cirY+i;
uy<
=0?
u=1:
u=uy;
by>
=high-1?
b=high-2:
b=by;
lx<
l=1:
l=lx;
rx>
=wide-1?
r=wide-2:
r=rx;
if(rx<
wide-1){
for(intk=u;
k<
=b;
k++)
grid(rx,k,"
if(lx>
grid(lx,k,"
if(by<
high-1){
for(intk=l;
=r;
grid(k,by,"
if(uy>
grid(k,uy,"
test()
{
for(inty=0;
=40;
for(intx=0;
if(gameSpace[y][x].have)//&
gameSpace[y][x].kind==3)
grid(x,42+y,(char)gameSpace[y][x].no);
grid(x,42+y,"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 编写 坦克 大战 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)