2014年7月6日 星期日

Tutorial 3: Create a Matching Game_第三章: 創造翻牌相同遊戲

http://msdn.microsoft.com/zh-tw/library/dd553235.aspx

首頁:

您將學習如何:
  • 在 List 物件中儲存物件 (例如圖示)。
  • 使用 foreach 迴圈 (Visual C#) 或 For Each 迴圈 (Visual Basic) 逐一查看清單中的項目。
  • 使用參考變數追蹤表單的狀態。
  • 建置您可以搭配多個物件使用的事件處理常式來回應事件。
  • 讓計時器倒數計時,然後讓計時器於啟動後剛好引發一個事件。
當您完成此教學課程時,您的程式看起來類似下列圖片。
您在本教學課程中建立的遊戲

您在本教學課程中建立的遊戲
若要下載這個範例的完整版,請參閱完整的配對遊戲教學課程範例
=============================================================
以下為實際畫面:






















額外再增加部分有計數 以及 錯誤次數 (後續範例 音效 .....還沒實作 )

時間計數:  
時鐘2 主要設定


--------------------------------
        public Form1()
        {
            InitializeComponent();
            timer2.Start();          // 開始命令: 放置於初始化後面 (進入翻牌主程式前)
            AssignIconsToSquares();
        }
-------------------------------
       private void CheckForWinner()
        {
            .................
            .................
            // If the loop didn’t return, it didn't find
            // any unmatched icons
            // That means the user won. Show a message and close the form
            timer2.Stop();    // 當結束框跑出  則停止時鐘2

            MessageBox.Show("You matched all the icons!", "Congratulations");
            Close();

        }
--------------------------
        private void timer2_Tick_1(object sender, EventArgs e)
        {
            // Display the new time left
            // by updating the Time Left label.
            timeBase  = timeBase + 1;               //  10   ms Onetime
            timeRight = (timeBase / 1 ) % 10;       //  10   ms
            timemid   = (timeBase / 10) % 10;       //  100  ms
            timeLeft  = (timeBase / 100);           //  1000 ms  
            timeLabel2.Text = timeLeft + "." + timemid + timeRight + "seconds";   //  記得必須在外面創建同名Lab
        }
--------------------------




沒有留言:

張貼留言