C#打字練習小程序

          本程序寫于剛剛學習C#線程時,游戲者可以選擇四個不同級別的速度進行打字練習,在規定的時間內,用鍵盤敲擊屏幕中出現的相應字母后,該字母便會消失,分數也隨即加2,由于時間原因并沒有實現太多其他功能,如級別的自動增加,點擊相應字母后在該字母上出現相應效果,只是簡單的對C#中的線程練習了一把,希望對初學線程的朋友能夠有所幫助。

          以下為運行效果圖:


          以下為程序源代碼:
          Game.cs文件:

          using System;
          using System.Drawing;
          using System.Collections;
          using System.ComponentModel;
          using System.Windows.Forms;
          using System.Data;
          using System.Threading;

          namespace P195
          {
              
          public class frmGame : System.Windows.Forms.Form
              
          {
                  
          成員變量

                  
          構造

                  
          Windows 窗體設計器生成的代碼

                  
          程序入口

                  
          級別選擇菜單事件處理

                  
          判斷是否正在游戲,改變菜單按鈕的可用性

                  
          窗體加載事件

                  
          計時器(處理隨機產生字母及速度)

                  
          計時器(處理隨游戲時間)

                  
          隨機產生字母

                  
          隨機產生字母標簽的橫坐標

                  
          玩家鍵盤響應事件

                  
          退出事件處理

                  
          放棄本局游戲事件處理

                  
          關于
              }

          }


          MyThread.cs文件:
          using System;
          using System.Windows.Forms;
          using System.Threading;

          namespace P195
          {
              
          public class MyThread
              
          {
                  
          private int _speed = 0;
                  
          private Control _myControl;

                  
          public int Speed
                  
          {
                      
          set
                      
          {
                          
          this._speed = value;
                      }

                      
          get
                      
          {
                          
          return this._speed;
                      }

                  }


                  
          public Control MyControl
                  
          {
                      
          set
                      
          {
                          
          this._myControl = value;
                      }

                      
          get
                      
          {
                          
          return this._myControl;
                      }

                  }


                  
          public void LableMove()
                  
          {
                      
          while(true)
                      
          {
                          
          if(!this._myControl.Visible)
                          
          {
                              Thread.CurrentThread.Abort();
                              
          return;
                          }

                          
          if(this._myControl.Location.Y >= 300)
                          
          {
                              
          this._myControl.Visible = false;
                              Thread.CurrentThread.Abort();
                              
          return;
                          }

                          System.Drawing.Point lablePos 
          = this._myControl.Location;
                          lablePos.Offset(
          0,10);
                          
          this._myControl.Location = lablePos;
                          Thread.Sleep(
          1000);
                      }

                  }

              }

          }


          點擊下載源代碼:/Files/daizhenghenry/TypewriterPractise.rar

          posted on 2008-03-06 09:43 非凡DZ 閱讀(3236) 評論(1)  編輯  收藏 所屬分類: .NET

          評論

          # re: C#打字練習小程序 2012-06-05 21:15 賈秀文

          這個界面沒有啊,光有代碼,能弄個完整的發到我郵箱里,謝謝了,我們留的作業  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2008年3月>
          2425262728291
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類(19)

          隨筆檔案(19)

          友情鏈接

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 栾城县| 商洛市| 含山县| 西昌市| 彰化市| 华宁县| 扎鲁特旗| 昌宁县| 琼中| 徐汇区| 噶尔县| 琼结县| 昔阳县| 睢宁县| 大冶市| 衡阳县| 武胜县| 怀集县| 墨脱县| 通江县| 铁力市| 万荣县| 沙河市| 同仁县| 呈贡县| 三明市| 黑山县| 宁远县| 明光市| 突泉县| 定安县| 焦作市| 门源| 偃师市| 曲周县| 方城县| 盐边县| 手机| 瑞安市| 灵山县| 安陆市|