基本信息
源码名称:C# 坦克大战 游戏代码
源码大小:0.05M
文件格式:.zip
开发语言:C#
更新时间:2015-06-10
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 4 元×
微信扫码支付:4 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Collections.Generic; using System.Linq; using System.Drawing; using System.Text; namespace Tank { //游戏状态 public enum GameState { close = 1, open = 2 } //方向 public enum Direction { left = 1, up = 2, right = 3, down = 4 } //坦克类 public class tank { //坦克坐标位置 public Point _position = new Point(300, 300); //运动方向 public Direction _direction = Direction.up; //运动步长 public int _step = 4; //坦克运动状态图片 public Boolean _imgstate = true; //坦克位图数组 Bitmap[] _tankBmp = new Bitmap[8]; //当前坦克位图 public Bitmap _nowTankBmp = new Bitmap(30, 30); //(方法)构造方法 public tank() { //装载所有的坦克位图图片 _tankBmp[0] = new Bitmap("MyTankUp1.gif"); _tankBmp[1] = new Bitmap("MyTankUp2.gif"); _tankBmp[2] = new Bitmap("MyTankDown1.gif"); _tankBmp[3] = new Bitmap("MyTankDown2.gif"); _tankBmp[4] = new Bitmap("MyTankLeft1.gif"); _tankBmp[5] = new Bitmap("MyTankLeft2.gif"); _tankBmp[6] = new Bitmap("MyTankRight1.gif"); _tankBmp[7] = new Bitmap("MyTankRight2.gif"); //设置坦克位图的透明色 for (int i = 0; i <= 7; i ) _tankBmp[i].MakeTransparent(Color.Black); //当前坦克位图为向上运动的位图 _nowTankBmp = _tankBmp[0]; } //坦克运动 public void Go(Direction direction) { _direction = direction; if (_direction == Direction.up) { _position.Y = _position.Y - _step; if (_imgstate == true) _nowTankBmp = _tankBmp[0]; else _nowTankBmp = _tankBmp[1]; } else if (_direction == Direction.down) { _position.Y = _position.Y _step; if (_imgstate == true) _nowTankBmp = _tankBmp[2]; else _nowTankBmp = _tankBmp[3]; } else if (_direction == Direction.left) { _position.X = _position.X - _step; if (_imgstate == true) _nowTankBmp = _tankBmp[4]; else _nowTankBmp = _tankBmp[5]; } else if (_direction == Direction.right) { _position.X = _position.X _step; if (_imgstate == true) _nowTankBmp = _tankBmp[6]; else _nowTankBmp = _tankBmp[7]; } _imgstate = !_imgstate; } //(方法)坦克图像绘制 public void DrawMe(Graphics g) { g.DrawImage(_nowTankBmp, _position); } } //子弹类 public class Bullet { //子弹坐标位置 public Point _position; //子弹运动方向 public Direction _direction = Direction.up; //子弹运动步长 public int _step = 15; //子弹位图数组 Bitmap[] _BulletBmp = new Bitmap[4]; //当前子弹位图 public Bitmap _nowBulletBmp = new Bitmap(16, 16); //方法 public Bullet(Direction direction, Point point) { _direction = direction; _position = point; //装载所有的坦克位图图片 _BulletBmp[0] = new Bitmap("BulletLeft.gif"); _BulletBmp[1] = new Bitmap("BulletUp.gif"); _BulletBmp[2] = new Bitmap("BulletRight.gif"); _BulletBmp[3] = new Bitmap("BulletDown.gif"); //设置子弹位图的透明色 for (int i = 0; i <= 3; i ) _BulletBmp[i].MakeTransparent(Color.Black); if (_direction == Direction.left) _nowBulletBmp = _BulletBmp[0]; else if (_direction == Direction.up) _nowBulletBmp = _BulletBmp[1]; else if (_direction == Direction.right) _nowBulletBmp = _BulletBmp[2]; else if (_direction == Direction.down) _nowBulletBmp = _BulletBmp[3]; } //(方法)子弹图像绘制 public void DrawBullet(Graphics g) { g.DrawImage(_nowBulletBmp, _position); } //(方法)子弹运动 public void Go() { //设置子弹所在位置 if (_direction == Direction.up) _position.Y = _position.Y - _step; else if (_direction == Direction.down) _position.Y = _position.Y _step; else if (_direction == Direction.left) _position.X = _position.X - _step; else if (_direction == Direction.right) _position.X = _position.X _step; } } }