• 大小: 70KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-18
  • 语言: C#
  • 标签: 坦克大战  

资源简介

用C#语言写的一个开发小游戏,坦克大战,源代码和实现都有

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace TankWar
{
    //子弹类
    class Bullet
    {
        #region 私有字段
        //子弹坐标位置(需要添加System.Drawing命名空间)
        private Point _position = new Point(200 200);
        //子弹发射方向
        private Direction _direction=Direction.Up;
        //子弹运动步长
        private int _step=9;
        //敌我方子弹标志
        Side _side;
        //子弹位图(与子弹发射方向相对应)
        private Bitmap _bulletBmp=new Bitmap(1616);

        #endregion

        #region 公有属性
        //子弹坐标位置
        public Point _Position
        {
          get { return _position; }
          set { _position = value; }
        }
        //子弹发射方向
        public Direction _Direction
        {
          get { return _direction; }
          set { _direction = value; }
        }
         //子弹运动步长
        public int _Step
        {
          get { return _step; }
          set { _step = value; }
        }
         //敌我方子弹标志
        public Side _Side
        {
          get { return _side; }
          set { _side = value; }
        }
        #endregion

        //类构造方法
        public Bullet(Side sideDirection direction)
        {
            //保存敌我方标志
            _side=side;
            //保存子弹发射方向
            _direction=direction;
            //根据子弹发射方向,装载相应的子弹位图图片
            if(side==Side.Me)
            {
                if(direction==Direction.Up)
                    _bulletBmp=new Bitmap(“Images\\MyBulletUp.gif“);
                if(direction==Direction.Down)
                    _bulletBmp=new Bitmap(“Images\\MyBulletDown.gif“);
                if(direction==Direction.Left)
                    _bulletBmp=new Bitmap(“Images\\MyBulletLeft.gif“);
                if(direction==Direction.Right)
                    _bulletBmp=new Bitmap(“Images\\MyBulletRight.gif“);
            }
            else
            {
                if(direction==Direction.Up)
                    _bulletBmp=new Bitmap(“Images\\EnemyBulletUp.gif“);
                if(direction==Direction.Down)
                    _bulletBmp=new Bitmap(“Images\\EnemyBulletDown.gif“);
                if(direction==Direction.Left)
                    _bulletBmp=new Bitmap(“Images\\EnemyBulletLeft.gif“);
                if(direction==Direction.Right)
                    _bulletBmp=new Bitmap(“Images\\EnemyBulletRight.gif“);
            }
            //设置坦克位图的透明色
            _bulletBmp.MakeTransparent(Color.Black);
        }

        //子弹移动
        public void Move()
        {
            //设置子弹所在位置
            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=

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         911  2018-06-04 16:32  TankWar\TankWar.sln
     文件       16896  2018-06-11 17:59  TankWar\TankWar.suo
     目录           0  2018-06-16 16:19  TankWar\TankWar\
     目录           0  2018-06-16 16:19  TankWar\TankWar\bin\
     目录           0  2018-06-16 16:19  TankWar\TankWar\bin\Debug\
     目录           0  2018-06-16 16:19  TankWar\TankWar\bin\Debug\Images\
     文件         145  2014-12-07 15:59  TankWar\TankWar\bin\Debug\Images\EnemyBulletDown.gif
     文件         143  2014-12-07 16:00  TankWar\TankWar\bin\Debug\Images\EnemyBulletLeft.gif
     文件         141  2014-12-07 16:01  TankWar\TankWar\bin\Debug\Images\EnemyBulletRight.gif
     文件         144  2014-12-07 16:02  TankWar\TankWar\bin\Debug\Images\EnemyBulletUp.gif
     文件         209  2011-04-02 22:26  TankWar\TankWar\bin\Debug\Images\EnemyTankDown1.gif
     文件         208  2011-04-02 22:26  TankWar\TankWar\bin\Debug\Images\EnemyTankDown2.gif
     文件         178  2011-04-02 22:30  TankWar\TankWar\bin\Debug\Images\EnemyTankLeft1.gif
     文件         179  2011-04-02 22:31  TankWar\TankWar\bin\Debug\Images\EnemyTankLeft2.gif
     文件         178  2011-04-02 22:32  TankWar\TankWar\bin\Debug\Images\EnemyTankRight1.gif
     文件         177  2011-04-02 22:32  TankWar\TankWar\bin\Debug\Images\EnemyTankRight2.gif
     文件         207  2011-04-02 22:27  TankWar\TankWar\bin\Debug\Images\EnemyTankUp1.gif
     文件         210  2011-04-02 22:27  TankWar\TankWar\bin\Debug\Images\EnemyTankUp2.gif
     文件         894  2014-12-11 11:16  TankWar\TankWar\bin\Debug\Images\Main.ico
     文件         145  2011-04-02 22:39  TankWar\TankWar\bin\Debug\Images\MyBulletDown.gif
     文件         143  2011-04-02 22:38  TankWar\TankWar\bin\Debug\Images\MyBulletLeft.gif
     文件         141  2011-04-02 22:38  TankWar\TankWar\bin\Debug\Images\MyBulletRight.gif
     文件         144  2011-04-02 22:39  TankWar\TankWar\bin\Debug\Images\MyBulletUp.gif
     文件         209  2014-12-06 21:26  TankWar\TankWar\bin\Debug\Images\MyTankDown1.gif
     文件         224  2014-12-06 21:24  TankWar\TankWar\bin\Debug\Images\MyTankDown2.gif
     文件         193  2014-12-06 21:23  TankWar\TankWar\bin\Debug\Images\MyTankLeft1.gif
     文件         194  2014-12-06 21:25  TankWar\TankWar\bin\Debug\Images\MyTankLeft2.gif
     文件         178  2014-12-06 21:26  TankWar\TankWar\bin\Debug\Images\MyTankRight1.gif
     文件         177  2014-12-06 21:27  TankWar\TankWar\bin\Debug\Images\MyTankRight2.gif
     文件         207  2014-12-06 21:27  TankWar\TankWar\bin\Debug\Images\MyTankUp1.gif
     文件         210  2014-12-06 21:27  TankWar\TankWar\bin\Debug\Images\MyTankUp2.gif
............此处省略27个文件信息

评论

共有 条评论