• 大小: 42KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-24
  • 语言: C#
  • 标签: c#  坦克大战  简易  

资源简介

c#做的坦克大战,简易,适合初学。c#做的坦克大战,简易,适合初学。c#做的坦克大战,简易,适合初学。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsApplication87
{
    /// 
    /// Made by wartim 2009.10.12
    /// var 1.0.0.0
    /// 

    public partial class Form1 : Form
    {
        static int HEIGHT = 300;
        static int WIDTH = 300;

        Bitmap OrgBmp = new Bitmap(WIDTH HEIGHT);
        List Tanks = new List();
        UserTank UTank = null;
        List Bullets = new List();
        PictureBox PB = new PictureBox();

        public Form1()
        {
            InitializeComponent();

            this.Size = new Size(WIDTH HEIGHT);
            this.FormBorderstyle = FormBorderstyle.FixedDialog;
            this.KeyPreview = true;
            this.KeyDown += new KeyEventHandler(Form1_KeyDown);

            using (Graphics G = Graphics.FromImage(OrgBmp))
                G.FillRectangle(new SolidBrush(this.BackColor) this.ClientRectangle);

            PB.Parent = this;
            PB.Dock = Dockstyle.Fill;
            PB.Image = OrgBmp;

            for (int i = 0; i < 5; i++)
            {
                Tanks.Add(new Tank(Color.Blue this.BackColor));
                Thread.Sleep(100);
            }

            UTank = new UserTank(Color.Red this.BackColor);

            Thread T = new Thread(new ThreadStart(RunThread));
            T.IsBackground = true;
            T.Start();
        }

        void Form1_KeyDown(object sender KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Up: UTank.ChangeDirection(Direction.UP); UTank.Move(); break;
                case Keys.Down: UTank.ChangeDirection(Direction.DOWN); UTank.Move(); break;
                case Keys.Left: UTank.ChangeDirection(Direction.LEFT); UTank.Move(); break;
                case Keys.Right: UTank.ChangeDirection(Direction.RIGHT); UTank.Move(); break;
                case Keys.Space: Bullets.Add(new Bullet(Color.Black UTank)); break;  // 发射子弹
            }
        }

        void RunThread()
        {
            try
            {
                int Start = Environment.TickCount;
                Random R = new Random();
                int KillCount = 0 DeathCount = 0;

                while (true)
                    if (Environment.TickCount - Start > 100)
                    {
                        Bitmap CacheBmp = new Bitmap(OrgBmp);

                        for (int i = 0; i < Tanks.Count; i++)
                        {
                            Tanks[i].Move();
                            Tanks[i].Draw(ref CacheBmp);
                            if (R.Next(10) == 0) // 电脑发子弹是10分之一的可能
                                Bullets.Add(new Bullet(Color.Red Tanks[i]));
                        }
                        UTank.D

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      24576  2009-10-12 17:13  c#坦克大战\WindowsApplication87\bin\Debug\WindowsApplication87.exe

     文件      36352  2009-10-12 17:13  c#坦克大战\WindowsApplication87\bin\Debug\WindowsApplication87.pdb

     文件       5632  2005-12-08 14:51  c#坦克大战\WindowsApplication87\bin\Debug\WindowsApplication87.vshost.exe

     文件      12645  2009-10-12 17:13  c#坦克大战\WindowsApplication87\Form1.cs

     文件       1170  2009-10-12 11:17  c#坦克大战\WindowsApplication87\Form1.Designer.cs

     文件        784  2009-10-12 11:19  c#坦克大战\WindowsApplication87\obj\Debug\WindowsApplication87.csproj.GenerateResource.Cache

     文件      24576  2009-10-12 17:13  c#坦克大战\WindowsApplication87\obj\Debug\WindowsApplication87.exe

     文件      36352  2009-10-12 17:13  c#坦克大战\WindowsApplication87\obj\Debug\WindowsApplication87.pdb

     文件        180  2009-10-12 11:19  c#坦克大战\WindowsApplication87\obj\Debug\WindowsApplication87.Properties.Resources.resources

     文件       1497  2010-05-31 09:57  c#坦克大战\WindowsApplication87\obj\WindowsApplication87.csproj.FileListAbsolute.txt

     文件        479  2009-10-12 11:17  c#坦克大战\WindowsApplication87\Program.cs

     文件       1212  2009-10-12 11:17  c#坦克大战\WindowsApplication87\Properties\AssemblyInfo.cs

     文件       2896  2009-10-12 11:17  c#坦克大战\WindowsApplication87\Properties\Resources.Designer.cs

     文件       5612  2009-10-12 11:17  c#坦克大战\WindowsApplication87\Properties\Resources.resx

     文件       1105  2009-10-12 11:17  c#坦克大战\WindowsApplication87\Properties\Settings.Designer.cs

     文件        249  2009-10-12 11:17  c#坦克大战\WindowsApplication87\Properties\Settings.settings

     文件       3095  2009-10-12 11:17  c#坦克大战\WindowsApplication87\WindowsApplication87.csproj

     文件        949  2009-10-12 11:17  c#坦克大战\WindowsApplication87.sln

    ..A..H.     12800  2010-05-31 09:57  c#坦克大战\WindowsApplication87.suo

     目录          0  2010-05-31 09:57  c#坦克大战\WindowsApplication87\obj\Debug\TempPE

     目录          0  2010-05-31 09:57  c#坦克大战\WindowsApplication87\bin\Debug

     目录          0  2010-05-31 09:57  c#坦克大战\WindowsApplication87\obj\Debug

     目录          0  2010-05-31 09:57  c#坦克大战\WindowsApplication87\bin

     目录          0  2010-05-31 09:57  c#坦克大战\WindowsApplication87\obj

     目录          0  2010-05-31 09:57  c#坦克大战\WindowsApplication87\Properties

     目录          0  2010-05-31 09:57  c#坦克大战\WindowsApplication87

     目录          0  2010-05-31 09:57  c#坦克大战

----------- ---------  ---------- -----  ----

               172161                    27



............此处省略0个文件信息

评论

共有 条评论