开发学院软件开发C语言 游戏人生Silverlight(3) - 打苍蝇[Silverlight 2.... 阅读

游戏人生Silverlight(3) - 打苍蝇[Silverlight 2.0(c#)]

 2009-06-22 08:33:13 来源:WEB开发网   
核心提示: 2、苍蝇控件的ViewIFlyView.csusing System;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using Syste

2、苍蝇控件的View

IFlyView.cs


using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace YYFly.View
{
    public interface IFlyView
    {
        /**//// <summary>
        /// 更新苍蝇的位置
        /// </summary>
        /// <param name="x">X 轴坐标</param>
        /// <param name="y">Y 轴坐标</param>
        /// <param name="z">Z 轴方向上的缩放比例</param>
        void Update(double x, double y, double z);

        /**//// <summary>
        /// 苍蝇开始飞的事件处理器
        /// </summary>
        event EventHandler Start;
        /**//// <summary>
        /// 苍蝇停止飞的事件处理器
        /// </summary>
        event EventHandler Stop;
        /**//// <summary>
        /// 打死苍蝇后的计分事件
        /// </summary>
        event EventHandler Score;
    }
}


Fly.xaml.cs


using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace YYFly.View
{
    public partial class Fly : UserControl, IFlyView
    {
        public Fly()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(Fly_Loaded);
        }

        void Fly_Loaded(object sender, RoutedEventArgs e)
        {
           
        }

        /**//// <summary>
        /// 更新苍蝇的位置
        /// </summary>
        /// <param name="x">X 轴坐标</param>
        /// <param name="y">Y 轴坐标</param>
        /// <param name="z">Z 轴方向上的缩放比例</param>
        public void Update(double x, double y, double z)
        {
            fly.SetValue(Canvas.LeftProperty, x);
            fly.SetValue(Canvas.TopProperty, y);
            st.ScaleX = st.ScaleY = z;
        }

        /**//// <summary>
        /// 打到苍蝇后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fly_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (aniWing.GetCurrentState() != ClockState.Stopped)
            {
                aniFlyDisappear.Begin();

                OnScore();
            }
        }

        /**//// <summary>
        /// 苍蝇消失的动画结束后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void aniFlyDisappear_Completed(object sender, EventArgs e)
        {
            OnStop();
        }

        /**//// <summary>
        /// 初始化苍蝇的位置
        /// </summary>
        public void InitPosition()
        {
            fly.SetValue(Canvas.LeftProperty, -300d);
        }

        public event EventHandler Start;
        public void OnStart()
        {
            InitPosition();

            aniFlyDisappear.Stop();

            if (Start != null)
                Start(this, EventArgs.Empty);
        }

        public event EventHandler Stop;
        public void OnStop()
        {
            InitPosition();

            if (Stop != null)
                Stop(this, EventArgs.Empty);
        }

        public event EventHandler Score;
        public void OnScore()
        {
            if (Score != null)
                Score(this, EventArgs.Empty);
        }
    }
}

Tags:游戏 人生 Silverlight

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接