实例介绍
【实例截图】
【核心代码】
void GamePlay()/*玩游戏的过程*/
{
int i,j,lose=0;/*lose是1的时候表示失败*/
int t=0;
randomize();
while(1)
{
for(i=0;i<5;i )/*画敌人的子弹*/
{
if(amy[i].fire.direction>0)
putpixel(100 amy[i].fire.y*20,50 amy[i].fire.x*20,11);
}
for(i=0;i<=4;i )/*画玩家子弹*/
{
if(Playone.fire[i].direction>0)/*大于0表示玩家子弹存在*/
putpixel(100 Playone.fire[i].y*20,50 Playone.fire[i].x*20,11);
}
TimeDelay(500000);/*要害的时间改动*/
for(i=0;i<5;i )/*去敌人的子弹*/
{
if(amy[i].fire.direction>0)
putpixel(100 amy[i].fire.y*20,50 amy[i].fire.x*20,0);
}
for(i=0;i<=4;i )/*去玩家除子弹*/
{
if(Playone.fire[i].direction>0)
putpixel(100 Playone.fire[i].y*20,50 Playone.fire[i].x*20,0);
}
for(i=0;i<=4;i )/*玩家子弹位置的变化*/
{
if(Playone.fire[i].direction<0)
continue;
if(Playone.fire[i].direction==1)
{Playone.fire[i].x--;Playone.fire[i].y=Playone.fire[i].y;}
else if(Playone.fire[i].direction==2)
{Playone.fire[i].y ;Playone.fire[i].y=Playone.fire[i].y;}
else if(Playone.fire[i].direction==3)
{Playone.fire[i].x ;Playone.fire[i].y=Playone.fire[i].y;}
else if(Playone.fire[i].direction==4)
{Playone.fire[i].y--;Playone.fire[i].y=Playone.fire[i].y;}
/*打到石头或者砖头的情况下减少子弹*/
if(map[Playone.fire[i].x][Playone.fire[i].y]==1)/*打到石头*/
Playone.fire[i].direction=-1;/*子弹消失*/
if(map[Playone.fire[i].x][Playone.fire[i].y]==2)/*打到砖头*/
{
Playone.fire[i].direction=-1;
DrawBlack(Playone.fire[i].y,Playone.fire[i].x);/*砖头打掉*/
map[Playone.fire[i].x][Playone.fire[i].y]=0;/*被打掉的地方变成可走的地方*/
}
if(map[Playone.fire[i].x][Playone.fire[i].y]==5)/*自己打到老家*/
{lose=1;break;}
for(j=0;j<5;j )
{
if(amy[j].direction<0)/*不存在的不判定*/
continue;
if(amy[j].x==Playone.fire[i].x&&amy[j].y==Playone.fire[i].y)/*打中敌人*/
{
Playone.fire[i].direction=-1;
DrawBlack(Playone.fire[i].y,Playone.fire[i].x);
map[Playone.fire[i].x][Playone.fire[i].y]=0;/*被打掉的地方变成可走的地方*/
amy[j].fire.direction=amy[j].direction=-1;/*这个敌人消失*/
Score();/*输出得分*/
}
}
}
for(i=0;i<5;i )/*敌人子弹位置的变化*/
{
if(amy[i].direction<0||amy[i].fire.direction<0)
continue;
if(amy[i].fire.direction==1)
{amy[i].fire.x--;amy[i].fire.y=amy[i].fire.y;}
else if(amy[i].fire.direction==2)
{amy[i].fire.y ;amy[i].fire.x=amy[i].fire.x;}
else if(amy[i].fire.direction==3)
{amy[i].fire.x ;amy[i].fire.y=amy[i].fire.y;}
else if(amy[i].fire.direction==4)
{amy[i].fire.y--;amy[i].fire.x=amy[i].fire.x;}
/*打到石头或者砖头的情况下减少子弹*/
if(map[amy[i].fire.x][amy[i].fire.y]==1)/*打到石头*/
amy[i].fire.direction=-1;/*子弹消失*/
if(map[amy[i].fire.x][amy[i].fire.y]==2)/*打到砖头*/
{
amy[i].fire.direction=-1;
DrawBlack(amy[i].fire.y,amy[i].fire.x);/*砖头打掉*/
map[amy[i].fire.x][amy[i].fire.y]=0;/*被打掉的地方变成可走的地方*/
}
if(map[amy[i].fire.x][amy[i].fire.y]==5)/*敌人打到老家*/
{lose=1;break;}
if(amy[i].fire.x==Playone.x&&amy[i].fire.y==Playone.y)/*打中玩家*/
{
for(j=0;j<5;j )
Playone.fire[j].direction=-1;/*玩家子弹都消失*/
amy[i].fire.direction=-1;
DrawBlack(amy[i].fire.y,amy[i].fire.x);
map[amy[i].fire.x][amy[i].fire.y]=0;/*被打掉的地方变成可走的地方*/
lose=1;break;/*好人被打掉后就失败*/
}
}
nosound();
for(i=0;i<5;i )/*敌人方向随机的改变*/
{
if(amy[i].direction<0)
continue;
while(1)
{
amy[i].directiontwo=random(4) 1;
if(amy[i].direction==1&&amy[i].directiontwo==3)
continue;
if(amy[i].direction==3&&amy[i].directiontwo==1)
continue;
if(amy[i].direction==2&&amy[i].directiontwo==4)
continue;
if(amy[i].direction==4&&amy[i].directiontwo==2)/*这里4个if是判定有没有往返走*/
continue;
if(amy[i].directiontwo==3&&(map[amy[i].x 1][amy[i].y]==3||map[amy[i].x 1][amy[i].y]==1||map[amy[i].x 1][amy[i].y]==2))
continue;
if(amy[i].directiontwo==1&&(map[amy[i].x-1][amy[i].y]==3||map[amy[i].x-1][amy[i].y]==1||map[amy[i].x-1][amy[i].y]==2))
continue;
if(amy[i].directiontwo==2&&(map[amy[i].x][amy[i].y 1]==3||map[amy[i].x][amy[i].y 1]==1||map[amy[i].x][amy[i].y 1]==2))
continue;
if(amy[i].directiontwo==4&&( map[amy[i].x][amy[i].y-1]==3||map[amy[i].x][amy[i].y-1]==1||map[amy[i].x][amy[i].y-1]==2))
continue;/*以上4个是是否碰到了墙壁或者水什么的*/
DrawBlack(amy[i].y,amy[i].x);/*把原来的地方擦掉*/
amy[i].direction=amy[i].directiontwo;
if(amy[i].direction==1)
{amy[i].x--;amy[i].y=amy[i].y;}
if(amy[i].direction==3)
{amy[i].x ;amy[i].y=amy[i].y;}
if(amy[i].direction==2)
{amy[i].y ;amy[i].x=amy[i].x;}
if(amy[i].direction==4)
{amy[i].y--;amy[i].x=amy[i].x;}
if(amy[i].x==Playone.x&&amy[i].y==Playone.y)/*相撞*/
lose=1;
if(map[amy[i].x][amy[i].y]==5)/*敌人撞到老家*/
lose=1;
DrawAmy(amy[i].y,amy[i].x,i);/*画敌人*/
if(amy[i].fire.direction<0)
amy[i].fireplay=random(4);
if(amy[i].fireplay==1&&amy[i].fire.direction<0)/*发射*/
{
amy[i].fire.direction=amy[i].direction;/*子弹方向与敌人方向一致*/
amy[i].fire.x=amy[i].x;
amy[i].fire.y=amy[i].y;
}
break;
}
}
if(lose)/*因为失败而跳出循环显示失败*/
{GameOver();break;}
if(GetKey(KEY_ESC))
break;
if(GetKey(KEY_UP))/*往上*/
{
if(Playone.direction==1&&map[Playone.x-1][Playone.y]!=1&&map[Playone.x-1][Playone.y]!=2)
{
if(map[Playone.x-1][Playone.y]==3)
continue;
DrawBlack(Playone.y,Playone.x);/*这个if是移动,前提是方向与按下的到向一致*/
Playone.x--;
Playone.direction=1;
DrawPlay(Playone.y,Playone.x);
}
else/*只调整炮头方向*/
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=1;
DrawPlay(Playone.y,Playone.x);
}
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论