首页 > 新闻系统 > 编程天地 > 文章正文

SilverLight开发入门例程

2007-11-05 10:12:18 来源:天极yesky 作者:维维 点击:
Silverlight,一个跨浏览器和跨平台的插件,能在微软.NET上交付炫目的多媒体体验,和有丰富交互功能的Web应用。

  CheckForWin()

  这个帮助函数用来检查棋盘是否处于赢状态,如果所有的徽标都是亮或者都是暗,则玩家胜出。

private bool CheckForWin()
{
   
int onCount = 0; // assume no square on by default
    bool checkForWin = false; // assume player did not win

    // loop through all squares

    for (int i = 0; i < squares.Count; i++)
    {
        if (squares[i].Source == vistaLogoOn.Source)
            onCount++;
    }

    // if all lights are on or off then player wins

    if (onCount == 0 || onCount == 25)
        checkForWin = true;
     return checkForWin;
}

    // loop through all squares

    for (int i = 0; i < squares.Count; i++)
    {
        if (squares[i].Source == vistaLogoOn.Source)
            onCount++;
    }

    // if all lights are on or off then player wins

    if (onCount == 0 || onCount == 25)
        checkForWin = true;
     return checkForWin;
}

  Browser.HtmlTimer

  我发现在Silverlight1.1中有一个HtmlTimer类。这个类没有文档记载而且是被遗弃的类。在编译后VS将会有一个提示:'System.Windows.Browser.HtmlTimer' is obsolete: '这不是一个高精度的计时器,并不适合于短间隔的动画。在未来版本里将会有个高级的计时器版本出现。

...

// use the browser's HtmlTimer to refresh background regularly
System.Windows.Browser.HtmlTimer timer = 
new System.Windows.Browser.HtmlTimer();
timer.Interval = 1;
timer.Enabled = true;
timer.Tick += new EventHandler(timer_Tick);

...

void timer_Tick(object sender, EventArgs e)
{
   double currentLeft = (double)background.GetValue(Canvas.LeftProperty);
   if (currentLeft <= 0)
   {
      // move background pixels over>
      background.SetValue(Canvas.LeftProperty, currentLeft + 2);
   }
   else
   {
      // reset backgrounds position
      background.SetValue(Canvas.LeftProperty, -340);
   }
}

9 7 3 1 2 3 4 4 8 :

精彩推荐
焦点大图推荐
本类热门文章

论坛美图

本周软件下载排行

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203