WEB开发网
开发学院图形图像Flash silverlight2 游戏 1 你能坚持多少秒 阅读

silverlight2 游戏 1 你能坚持多少秒

 2009-05-15 12:08:26 来源:WEB开发网   
核心提示: Page.xaml.cs 1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Net; 5using System.Windows; 6using System.Window

Page.xaml.cs

  1using System;
  2using System.Collections.Generic;
  3using System.Linq;
  4using System.Net;
  5using System.Windows;
  6using System.Windows.Controls;
  7using System.Windows.Documents;
  8using System.Windows.Input;
  9using System.Windows.Media;
 10using System.Windows.Media.Animation;
 11using System.Windows.Shapes;
 12
 13namespace Movebox
 14{
 15    public partial class Page : UserControl
 16    {
 17        GameManager gm;
 18        Owner me;
 19        DragManager dm;
 20        DateTime startTime;
 21
 22        public Page()
 23        {
 24            InitializeComponent();
 25
 26            this.Loaded += new RoutedEventHandler(Page_Loaded);
 27        }
 28
 29        void Page_Loaded(object sender, RoutedEventArgs e)
 30        {
 31            dm = new DragManager(layoutRoot);
 32            uc.Focus();
 33
 34            me = new Owner();
 35            me.X = 205;
 36            me.Y = 205;
 37            layoutRoot.Children.Add(me);
 38
 39            gm = new GameManager(layoutRoot, me);
 40            gm.GameOver += new EventHandler(gm_GameOver);
 41            gm.GrameRun += new EventHandler(gm_GrameRun);
 42            gm.MoveSpeed = 0.9;
 43
 44            foreach (Enemy enemy in gm.enemies)
 45                layoutRoot.Children.Add(enemy);
 46
 47            dm.OnCollision += dm_Collision;
 48            dm.OnFristTimeMove += dm_MoveEventArgs;
 49            dm.OnDragMove += dm_OnDragMove;
 50            dm.EnableDragableElement(me);
 51
 52           
 53        }
 54
 55        void gm_GrameRun(object sender, EventArgs e)
 56        {
 57            levelRect.Height+=.1;
 58            double s=(DateTime.Now - this.startTime).TotalSeconds;
 59            if (s > 10 && s <= 15)
 60            {
 61                levelName.Text = "老鸟";
 62                gm.MoveSpeed = 1.1;
 63            }
 64            if (s > 15 && s <= 20)
 65            {
 66                levelName.Text = "高手";
 67                gm.MoveSpeed = 1.3;
 68            }
 69            if (s > 20)
 70            {
 71                levelName.Text = "天才";
 72                gm.MoveSpeed = 1.5;
 73            }
 74            if (s > 30)
 75            {
 76                levelName.Text = "无敌";
 77                gm.MoveSpeed = 2;
 78            }
 79            runTime.Text = (string.Format("{0}秒", s));
 80        }
 81
 82        /**//// <summary>
 83        /// 拖动
 84        /// </summary>
 85        /// <param name="sender"></param>
 86        /// <param name="e"></param>
 87        void dm_OnDragMove(object sender, EventArgs e)
 88        {
 89            currentPointBox.Text = "x:" + me.X + "  y:" + me.Y;
 90            if (((me.X + me.Width  >= 400)
 91                ||
 92                (me.X  <= 50)) || (((me.Y + me.Height  >= 400)
 93                ||
 94                (me.Y  <= 50))))
 95            {
 96                gm_GameOver(sender, e);
 97                currentPointBox.Text += " 撞上了";
 98
 99               
100            }
101        }
102
103        /**//// <summary>
104        /// 游戏开始
105        /// </summary>
106        /// <param name="sender"></param>
107        /// <param name="e"></param>
108
109        void dm_MoveEventArgs(object sender, EventArgs e)
110        {
111            startTime = DateTime.Now;
112            gm.Play();
113            runTime.Text = "";
114        }
115
116        /**//// <summary>
117        /// 游戏结束
118        /// </summary>
119        /// <param name="sender"></param>
120        /// <param name="e"></param>
121        void gm_GameOver(object sender, EventArgs e)
122        {
123            dm.DisableDragableElement();
124            gm.Pause();
125            resultText.Text="您坚持了" + runTime.Text + ",级别:" + levelName.Text;
126
127        }
128        void dm_Collision(object sender, CollisionEventArgs e)
129        {
130          
131        }
132
133
134    }
135}
136

上一页  1 2 3 4 5  下一页

Tags:silverlight 游戏 坚持

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接