2.迷宫游戏

2.迷宫游戏

新建Windows 窗体应用程序项目  Maze 为项目名称
 
设置窗体属性
用指针拖动右下角直到窗体的宽度和高度为650像素

Text 迷宫

FormBorderStyle  Fixed3D

MaximizeBox      False

添加panel控件  BorderStyle--Fixed3D

向窗体添加标签Label  AutoSize  False
               BackColor       蓝色
               Text             空

添加一个标签  finishLabel 
               Text            完成
                拖动到迷宫终点

添加  private void finishlabel_MouseEnter(object sender, EventArgs e)
        {
           
            // Show a congratulatory MessageBox, then close the form.
            MessageBox.Show("Congratulations(祝贺,游戏过关提示)!");
            Close();
        }

把结束属性 MouseEnter:为Finshlabel_MouseEnter
  
添加label为 text-开始 name-Startlabel  TextAlign-MiddleCenter

/// <summary>
        /// 找到造用于迷宫的指针起始点
        /// </summary>
        private void MoveToStart()
        {            
             Point startingPoint = Startlabel.Location;
             startingPoint.Offset(20, 20);
             Cursor.Position = PointToScreen(startingPoint);
        }   
       

//调用:
        public Form3()
        {
            InitializeComponent();
            //游戏开始时,鼠标指针放置在开始位置
            MoveToStart();
        }


   private void wall_MouseEnter(object sender, EventArgs e)
        {
             //鼠标指针返回起点
            MoveToStart();
        }

所有的墙 MouseEnter 为wall_MouseEnter

添加声音

public partial class Form1:Form
{
System.Media.SoundPlayer startSoundPlayer = new System.Media.SoundPlayer(@"c:\Windows\Media\Chord.wav");

System.Media.SoundPlayer finishSoundPlayer = new System.Media.SoundPlayer(@"c:\Windows\Media\tada.wav");
}

SoundPlayer startSoundPlayer = new SoundPlayer(@"c:\Windows\Media\chord.wav");
        //鼠标指针到达终点时,播放声音
       private SoundPlayer finishSoundPlayer = new SoundPlayer(@"c:\Windows\Media\tada.wav");


将语句startSoundPlayer.Play();添加到MoveToStart()方法中
将语句finishSoundPlayer.Play();添加到finishLabel_MouseEnter()中

posted @ 2012-04-03 21:04  珍爱贝贝1314  阅读(191)  评论(1编辑  收藏  举报