站立会议的内容(第六次)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;

using System.Windows.Forms;
using System.Drawing;
using Microsoft.DirectX.DirectSound;
using Microsoft.DirectX;
using Microsoft.DirectX.AudioVideoPlayback;

namespace GameAirPlaneCSharip
{

    partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }
        bool _end = false;
        int _count = 3;
        bool yunilix = true;
        bool vertikalYunilix = true;
        Point p1 = new Point();
        //okning orni
        Point p2 = new Point();
        Point p3 = new Point();

        bool _flagBullet = true;

        int _airVerticalSpace = 1;

        int x1_Bullet2;
        int x2_Bullet2;
        int y1_Bullet2;

        int y2_Bullet2;
        int x1_Tank1;
        int x2_Tank1;
        int y1_Tank1;

        int y2_Tank1;

        int x1_Bullet1;
        int x2_Bullet1;
        int y1_Bullet1;

        int y2_Bullet1;
        int x1_Tank2;
        int x2_Tank2;
        int y1_Tank2;

        int y2_Tank2;

        int _stepSpace = 10;

        private void Timer1_Tick(object sender, EventArgs e)
        {
            if (yunilix == true)
            {
                if (Tank2.Location.X > Panel_Main.Width - Tank2.Width)
                {
                    yunilix = false;
                    Tank2.Image = Properties.Resources.airplaneLeft;

                }

                p1 = new Point(Tank2.Location.X + 5, Tank2.Location.Y + _airVerticalSpace);
                Tank2.Location = p1;

            }
            else
            {
                if (Tank2.Location.X < 0)
                {
                    yunilix = true;
                    Tank2.Image = Properties.Resources.airplaneRight;

                }
                p1 = new Point(Tank2.Location.X - 5, Tank2.Location.Y + _airVerticalSpace);
                Tank2.Location = p1;
            }

            if (vertikalYunilix == true)
            {
                if (Tank2.Location.Y > (Panel_Main.Height / 6) * 5)
                {
                    _airVerticalSpace = -1;
                    vertikalYunilix = false;
                }

            }
            else
            {
                if (Tank2.Location.Y < 0)
                {
                    _airVerticalSpace = 1;
                    vertikalYunilix = true;
                }
            }

            x1_Bullet2 = Bullet2.Location.X;
            x2_Bullet2 = Bullet2.Location.X + Bullet2.Width;
            y1_Bullet2 = Bullet2.Location.Y;
            y2_Bullet2 = Bullet2.Location.Y + Bullet2.Height;

            x1_Bullet1 = Bullet1.Location.X;
            x2_Bullet1 = Bullet1.Location.X + Bullet1.Width;
            y1_Bullet1 = Bullet1.Location.Y;
            y2_Bullet1 = Bullet1.Location.Y + Bullet1.Height;

            /////////////////
            x1_Tank1 = Tank1.Location.X;
            x2_Tank1 = Tank1.Location.X + Tank1.Width;
            y1_Tank1 = Tank1.Location.Y;
            y2_Tank1 = Tank1.Location.Y + Tank1.Height;

            x1_Tank2 = Tank2.Location.X;
            x2_Tank2 = Tank2.Location.X + Tank2.Width;
            y1_Tank2 = Tank2.Location.Y;
            y2_Tank2 = Tank2.Location.Y + Tank2.Height;

            if (((x1_Bullet2 >= x1_Tank1 & x1_Bullet2 <= x2_Tank1) | (x2_Bullet2 >= x1_Tank1 & x2_Bullet2 <= x2_Tank1)) & ((y1_Bullet2 >= y1_Tank1 & y1_Bullet2 <= y2_Tank1) | (y2_Bullet2 >= y1_Tank1 & y2_Bullet2 <= y2_Tank1)))
            {
                //Tank2.Image = GaPanel_Main.My.Resources.boom
                //Tank2.Visible = False
                Timer1.Enabled = false;
                _end = true;
                Button2.Visible = false;
                PlaySound("boom.wav", BufferPlayFlags.Default);
                Tank1.Image = Properties.Resources.boom;
                MessageBox.Show("Game Over!");

                return;
            }

            if (((x1_Bullet1 >= x1_Tank2 & x1_Bullet1 <= x2_Tank2) | (x2_Bullet1 >= x1_Tank2 & x2_Bullet1 <= x2_Tank2)) & ((y1_Bullet1 >= y1_Tank2 & y1_Bullet1 <= y2_Tank2) | (y2_Bullet1 >= y1_Tank2 & y2_Bullet1 <= y2_Tank2)))
            {
                _flagBullet = true;

                p3 = new Point(Tank1.Location.X + Tank1.Width / 2, Panel_Main.Height + Tank1.Location.Y);
                Bullet1.Location = p3;
                Bullet1.Image = Properties.Resources.boom;
                Bullet1.Visible = false;

                if (_count > 0)
                    _count = _count - 1;
                Lab_Life.Text = _count.ToString();

                if (_count == 0)
                {
                    Timer1.Enabled = false;
                    _end = true;
                    Button2.Visible = false;
                    PlaySound("boom.wav", BufferPlayFlags.Default);
                    Tank2.Image = Properties.Resources.boom;
                    //Timer2.Enabled = True

                    MessageBox.Show("You Win!!!!!!!");
                    return;
                }

            }

            if (Bullet1.Location.Y <= 0)
            {
                _flagBullet = true;
                GetBullet1DefaultLocation();
                Bullet1.Visible = false;
            }
            if (_flagBullet == false)
            {
                Bullet1.Location = new Point(p3.X, Bullet1.Location.Y - 2);
            }

            //bullet2
            if (Bullet2.Location.Y >= Panel_Main.Height)
            {
                p2 = new Point(Tank2.Location.X + Tank2.Width / 2, Tank2.Location.Y + Tank2.Height);
                Bullet2.Location = p2;
                PlaySound("tank2_ok.wav", BufferPlayFlags.Default);
            }
            Bullet2.Location = new Point(p2.X, Bullet2.Location.Y + 2);

        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (_end == false)
            {
                Keys key = keyData;

                switch (key)
                {

                    case Keys.A:
                        if (Tank1.Location.X > 0)
                        {
                            Tank1.Location = new Point(Tank1.Location.X - _stepSpace, Tank1.Location.Y);
                            if (_flagBullet == true)
                            {
                                GetBullet1DefaultLocation();
                            }
                        }

                        break;
                    case Keys.D:
                        if (Tank1.Location.X + Tank1.Width < Panel_Main.Width)
                        {
                            Tank1.Location = new Point(Tank1.Location.X + _stepSpace, Tank1.Location.Y);
                            if (_flagBullet == true)
                            {
                                GetBullet1DefaultLocation();
                            }
                        }

                        break;
                    case Keys.W:
                        if (Tank1.Location.Y > 0)
                        {
                            Tank1.Location = new Point(Tank1.Location.X, Tank1.Location.Y - _stepSpace);
                            if (_flagBullet == true)
                            {
                                GetBullet1DefaultLocation();
                            }
                        }
                        break;
                    case Keys.S:
                        if (Tank1.Location.Y + Tank1.Height < Panel_Main.Height)
                        {
                            Tank1.Location = new Point(Tank1.Location.X, Tank1.Location.Y + _stepSpace);
                            if (_flagBullet == true)
                            {
                                GetBullet1DefaultLocation();
                            }

                        }

                        break;
                    case Keys.J:
                        if (_flagBullet == true)
                        {
                            PlaySound("tank1_ok.wav", BufferPlayFlags.Default);

                            GetBullet1DefaultLocation();

                            Bullet1.Image = Properties.Resources.Bullet2;
                            Bullet1.Visible = true;
                            _flagBullet = false;
                        }

                        break;
                }

            }
            if (keyData == Keys.A | keyData == Keys.D | keyData == Keys.W | keyData == Keys.S)
            {
                return false;
            }
            else
            {
                return base.ProcessDialogKey(keyData);
            }
        }

        private void GetBullet1DefaultLocation()
        {
            p3 = new Point(Tank1.Location.X + Tank1.Width / 2, Tank1.Location.Y);
            Bullet1.Location = p3;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ReSet();
            //背景音乐
            //PlaySound("1.wav", BufferPlayFlags.Looping);
            _audio = new Audio("back.mp3");
            //_audio.Stopping += new EventHandler(BackMusic_Stopping);
            _audio.Ending += new EventHandler(BackMusic_Ending);
            _audio.Play();
        }

        private void BackMusic_Ending(object sender, EventArgs e)
        {
            _audio.CurrentPosition = 0;
            _audio.Play();
        }
        Audio _audio;
        private void Button1_Click(object sender, EventArgs e)
        {
            GetBullet1DefaultLocation();
            Tank2.Image = Properties.Resources.airplaneRight;
            Tank1.Image = Properties.Resources.mytank;
            ReSet();
            Timer1.Enabled = true;
            Tank1.Visible = true;
            _count = 3;
            Lab_Life.Text = _count.ToString();
            Tank2.Visible = true;
        }

        //重置

        private void ReSet()
        {
            PictureBox pic = new PictureBox();
            pic.Image = Properties.Resources.airplane1;
            Tank1.Image = Properties.Resources.airplane1;
            Tank1.Location = new Point(Panel_Main.Width / 2, Panel_Main.Height - Tank1.Height);
            Tank2.Image = Properties.Resources.airplaneRight;
            Tank2.Location = new Point(0, 0);

            Button2.Text = "Stop";
            Button2.Visible = true;
            _end = false;
            Bullet1.Visible = false;
            p2 = new Point(Tank2.Location.X + Tank2.Width / 2, Tank2.Location.Y + Tank2.Height);
            Bullet2.Location = p2;
            p3 = new Point(Tank1.Location.X + Tank1.Width / 2, Tank1.Location.Y);
            Bullet1.Location = p3;
        }

        SecondaryBuffer backBuffer;
        Device backDev = new Device();
        //播放音乐

        public void PlaySound(string path, BufferPlayFlags playState)
        {
            backDev.SetCooperativeLevel(this, CooperativeLevel.Normal);
            backBuffer = new SecondaryBuffer(path, backDev);
            backBuffer.Play(0, playState);

        }

        private void Button2_Click(object sender, EventArgs e)
        {
            if (Timer1.Enabled == true)
            {
                Timer1.Enabled = false;
                Button2.Text = "Play";
            }
            else
            {
                Timer1.Enabled = true;
                Button2.Text = "Stop";
            }

        }

    }
}
时间: 2024-10-13 11:48:55

站立会议的内容(第六次)的相关文章

站立会议的内容(第十次)

今天我们针对form主窗体的Form1.Designer.cs文件进行了编写 1 namespace PlayPlane_01 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量. 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在

站立会议的内容(第一次)

我们这次是第一次会议,我们这次主要是项目的完全启动,并做了简单测试.下面是我们开会的照片和燃点图. 会议照片 燃点图

站立会议的内容(第二次)——补

昨天进行的第二次会议,由于时间问题今天补上,希望老师见谅. 五月十号,我们进一步确认了初级阶段游戏设计目标并搜集了游戏图像素材. 我们初级阶段的 游戏目标 是 先有 一个电脑飞机,并且它有自己的运动轨迹并且投放子弹,自己的飞机通过键盘W,A,S,D  移动.. 虽然初级目标很少但也是这个游戏最核心的部分,我们会下功夫做好这里的设计的!

站立会议的内容(第四次)

5月12日,星期四. 今天下午我们有软件工程课,我们的会议也就是这堂课了,我们今天已经完成了,初级阶段飞机大战的大部分功能,下图为部分代码截图:

站立会议的内容(第八次)

今天利用了软件工程课以及之后的晚自习时间,我们成功完成了对主窗体form.cs的编写 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using

站立会议的内容(第九次)

今天我们小组共同完成了对Program.cs的编写,并且讨论了对主窗体form的改进. 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Windows.Forms; 5 6 namespace PlayPlane_01 7 { 8 static class Program 9 { 10 /// <summary> 11 /// 应用程序的主入口点. 12 /// &l

站立会议的内容(第十三次)

今天我们针对程序进行了有效的测试,结果非常令人满意.

站立会议的内容(第十一次)

今天的下午和晚上,我们共同完成了对MCIPlay.cs文件的编写和测试. 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Runtime.InteropServices; 6 7 namespace PlayPlane_01 8 { 9 class MCIPlay 10 { 11 public static uint SND_A

站立会议的内容(第十四次)

今天我们对团队项目进行了最后的修改和测试,程序运行状况良好.而且我们进行了团队项目的整体总结,这使我们受益良多.