首页 坦克大战的游戏代码

坦克大战的游戏代码

举报
开通vip

坦克大战的游戏代码using System; using System.Collections.Generic; using System.Text; using System.Drawing; //add using System.Collections;//add namespace 坦克 { class Tank { private int width; //坦克的宽度 private int height; //坦克的高度 private int top; //坦克位置的纵坐标 private in...

坦克大战的游戏代码
using System; using System.Collections.Generic; using System.Text; using System.Drawing; //add using System.Collections;//add namespace 坦克 { class Tank { private int width; //坦克的宽度 private int height; //坦克的高度 private int top; //坦克位置的纵坐标 private int left; //坦克位置的横坐标 private int type; //坦克的类型(2---5敌方,6己方) private int direct; //0--上,1--下,2--左,3--右 public ArrayList bList=new ArrayList();//子弹序列 public Tank(int tank_type)//构造函数 { Random r = new Random(); 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);//产生0—9的数 this.type = tank_type; } public int Top//Top属性 { get { return top; } set { if (top >= 0 && top <= 9) { top = value; //if (top == 0 || top == 9) newDirect(); } } } public int Type//坦克的类型属性 { get { return type; } set { if (top >= 1 && top <= 5) { type = value; } } } public int Left//Left属性 { get { return left; } set { if (left >= 0 && left <= 9) { left = value; //if (left == 0 || left == 9) newDirect(); } } } public int Direct//Direct属性(坦克方向) { get { return direct; } set { direct = value; } } public void newDirect()//改变方向 { Random r = new Random(); int new_Direct=r.Next(0, 4);//产生0—3的数 while(this.direct == new_Direct) new_Direct = r.Next(0, 4);//产生0—3的数this.direct = new_Direct; } public void Draw(Graphics g,int type)//根据坦克类型选择不同图片 { Image tankImage = 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("BMP/ETANK1.BMP"); if (type == 6) tankImage = Image.FromFile("BMP/MYTANK.BMP"); //得到绘制这个坦克图形的在游戏面板中的矩形区域 Rectangle destRect = new Rectangle(this.left * width, this.top * height, width,height); Rectangle srcRect = new Rectangle(direct * width, 0, width, height);
本文档为【坦克大战的游戏代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_036899
暂无简介~
格式:doc
大小:18KB
软件:Word
页数:0
分类:互联网
上传时间:2019-08-05
浏览量:44