游戏人生Silverlight(3) - 打苍蝇[Silverlight 2.0(c#)]
2009-06-22 08:33:13 来源:WEB开发网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
编辑录入:爽爽 [复制链接] [打 印]- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››人生的“SEO“优化
- ››人生就是一场豪赌 要敢于做第一个吃螃蟹的人
- ››游戏定位成牵引Android发展的火车头
- ››Silverlight for Symbian
- ››游戏场景烘焙贴图制作
- ››游戏植物大战僵尸 iPhone 版9天销售额超100万美元...
更多精彩
赞助商链接