坦克大战的游戏代码Word格式.docx
- 文档编号:22361747
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:8
- 大小:15.43KB
坦克大战的游戏代码Word格式.docx
《坦克大战的游戏代码Word格式.docx》由会员分享,可在线阅读,更多相关《坦克大战的游戏代码Word格式.docx(8页珍藏版)》请在冰豆网上搜索。
//坦克的高度
privateinttop;
//坦克位置的纵坐标
privateintleft;
//坦克位置的横坐标
privateinttype;
//坦克的类型(2---5敌方,6己方)
privateintdirect;
//0--上,1--下,2--左,3--右
publicArrayListbList=newArrayList();
//子弹序列
publicTank(inttank_type)//构造函数
Randomr=newRandom();
this.direct=r.Next(0,4);
//产生0—3的数
this.width=32;
this.height=32;
this.left=r.Next(0,1);
//产生0—9的数
this.top=r.Next(0,1);
this.type=tank_type;
}
publicintTop//Top属性
get
returntop;
set
if(top>
=0&
&
top<
=9)
top=value;
//if(top==0||top==9)newDirect();
publicintType//坦克的类型属性
returntype;
=1&
=5)
type=value;
publicintLeft//Left属性
returnleft;
if(left>
left<
left=value;
//if(left==0||left==9)newDirect();
publicintDirect//Direct属性(坦克方向)
returndirect;
direct=value;
publicvoidnewDirect()//改变方向
intnew_Direct=r.Next(0,4);
//产生0—3的数
while(this.direct==new_Direct)
new_Direct=r.Next(0,4);
this.direct=new_Direct;
publicvoidDraw(Graphicsg,inttype)//根据坦克类型选择不同图片
ImagetankImage=Image.FromFile("
BMP/ETANK1.BMP"
);
if(type==2)tankImage=Image.FromFile("
BMP/ETANK2.BMP"
if(type==3)tankImage=Image.FromFile("
BMP/ETANK3.BMP"
if(type==4)tankImage=Image.FromFile("
BMP/ETANK4.BMP"
if(type==5)tankImage=Image.FromFile("
if(type==6)tankImage=Image.FromFile("
BMP/MYTANK.BMP"
//得到绘制这个坦克图形的在游戏面板中的矩形区域
RectangledestRect=newRectangle(this.left*width,this.top*height,width,height);
RectanglesrcRect=newRectangle(direct*width,0,width,height);
g.DrawImage(tankImage,destRect,srcRect,GraphicsUnit.Pixel);
publicvoidExplore(Graphicsg)//坦克爆炸动画
RectangledestRect=newRectangle(this.left*width,this.top*height,width,height);
RectanglesrcRect=newRectangle(0,0,width,height);
BMP/explode1.bmp"
g.DrawImage(tankImage,destRect,srcRect,GraphicsUnit.Pixel);
tankImage=Image.FromFile("
BMP/explode2.bmp"
PlaySound.Play("
Sound/Explode.wav"
publicvoidfire()
bulletb=newbullet(this.type);
//根据坦克产生不同子弹
b.Direct=this.Direct;
//坦克的朝向
b.Top=this.Top;
b.Left=this.Left;
//b.move();
bList.Add(b);
if(this.type==6)PlaySound.Play("
Sound/Shoot.wav"
//己方发射出声
publicvoidMoveBullet(refint[,]Map)
for(inti=bList.Count-1;
i>
=0;
i--)//遍历子弹序列
//for(inti=0;
i<
bList.Count;
i++)
bullett=((bullet)bList[i]);
//移动以前
if(t.Left<
0||t.Left>
9||t.Top<
0||t.Top>
9)
//超出边界
bList.RemoveAt(i);
continue;
//删除此颗子弹
if(Map[t.Left,t.Top]!
Map[t.Left,t.Top]!
=this.type)
//已遇到坦克和墙等障碍物
if(t.hitE(Map[t.Left,t.Top]))//击中对方坦克
Map[t.Left,t.Top]=-1;
//此处坦克被打中
t.move();
//移动以后
0||t.Top>
continue;
=0)//已遇到物体
}
publicvoidDrawBullet(Graphicsg,int[,]Map)//画子弹
MoveBullet(refMap);
foreach(bullettinbList)//遍历子弹序列
t.Draw(g);
//publicvoidNewPosition()//产生新坐标
//{
//Randomr=newRandom();
//this.left=r.Next(0,10);
//this.top=r.Next(0,10);
//}
//publicboolComparePosition(Tanks)//比较坦克位置
//if(this.left==s.left&
this.top==s.top)
//returntrue;
//else
//returnfalse;
//}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 坦克 大战 游戏 代码