内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

C#如何實(shí)現(xiàn)簡(jiǎn)單打字游戲-創(chuàng)新互聯(lián)

這篇文章主要為大家展示了C#如何實(shí)現(xiàn)簡(jiǎn)單打字游戲,內(nèi)容簡(jiǎn)而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來(lái)看看吧。

創(chuàng)新互聯(lián)公司擁有一支富有激情的企業(yè)網(wǎng)站制作團(tuán)隊(duì),在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)深耕十年,專業(yè)且經(jīng)驗(yàn)豐富。十年網(wǎng)站優(yōu)化營(yíng)銷經(jīng)驗(yàn),我們已為上千余家中小企業(yè)提供了做網(wǎng)站、網(wǎng)站制作解決方案,定制網(wǎng)站制作,設(shè)計(jì)滿意,售后服務(wù)無(wú)憂。所有客戶皆提供一年免費(fèi)網(wǎng)站維護(hù)!

運(yùn)行效果圖如下:

C#如何實(shí)現(xiàn)簡(jiǎn)單打字游戲

功能:程序運(yùn)行后,點(diǎn)擊開(kāi)始按鈕,窗體中的文本框中出現(xiàn)字母,用戶通過(guò)鍵盤輸入文本框中字母,窗體顯示用時(shí)、正確數(shù)、錯(cuò)誤數(shù)和正確率。
按鈕:開(kāi)始、結(jié)束、退出。

菜單:設(shè)置(開(kāi)始游戲、結(jié)束游戲、退出游戲),查看(正確率、所用時(shí)間)。

頁(yè)面:

C#如何實(shí)現(xiàn)簡(jiǎn)單打字游戲

控件屬性:

timer1:

enabled選擇false,Interval設(shè)置為5.

timer2:

enabled選擇false,Interval設(shè)置為1000.

代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication3
{
 public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }
 
  private int x = 200, y, num;
  private DateTime dt1, dt2;
  private int count_all = 0;
  private int count_correct = 0;
  private TimeSpan ts;
  Random rd = new Random();
 
 
  private void btnStart_Click(object sender, EventArgs e)
  {
   tsmiRate.Enabled = true;//啟用控件
   dt1 = DateTime.Now;
   timer1.Start();
   timer2.Start();
   textBox1.Visible = true;
   num = rd.Next(65, 90);
  }
 
 
  private void btnStop_Click(object sender, EventArgs e)
  {
   tsmiTime.Enabled = true;
   dt2 = DateTime.Now;
   timer1.Stop();
   timer2.Stop();
   textBox1.Visible = false;
   MessageBox.Show("游戲結(jié)束。", "提示");
  }
 
  private void btnQuit_Click(object sender, EventArgs e)
  {
   timer1.Stop();
   textBox1.Visible = false;
   DialogResult dr = MessageBox.Show("確定要退出嗎?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
   if (dr == DialogResult.OK)
    Application.Exit(); 
  }
 
  private void tsmiStart_Click(object sender, EventArgs e)
  {
   dt1 = DateTime.Now;
   timer1.Start();
   timer2.Start();
   textBox1.Visible = true;
   num = rd.Next(65, 90); 
  }
 
  private void tsmiStop_Click(object sender, EventArgs e)
  {
   dt2 = DateTime.Now;
   timer1.Stop();
   timer2.Stop();
   textBox1.Visible = false;
   MessageBox.Show("游戲結(jié)束!", "提示"); 
  }
 
  private void tsmiQuit_Click(object sender, EventArgs e)
  {
   timer1.Stop();
   textBox1.Visible = false;
   DialogResult dr = MessageBox.Show("確定要退出嗎?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
   if (dr == DialogResult.OK)
    Application.Exit();
  }
 
  private void tsmiRate_Click(object sender, EventArgs e)
  {
   double corr_rate = count_correct * 1.0 / count_all;
   string s = string.Format("{0,5:P2}",corr_rate);
   MessageBox.Show("正確率為:" + s, "正確率"); 
  }
 
  private void tsmiTime_Click(object sender, EventArgs e)
  {
   ts = dt2 - dt1;
   MessageBox.Show("所用時(shí)間為:" + ts.Seconds + "(s)", "所用時(shí)間"); 
  }
 
  private void timer1_Tick(object sender, EventArgs e)//???
  {
   y++;
   if (y > this.ClientSize.Height - 5)
    y = 20;
   textBox1.Text = ((char)num).ToString().ToUpper();
   textBox1.Location = new Point(x, y);
   textBox1.ForeColor = Color.FromArgb(rd.Next(0, 255), rd.Next(0, 255), rd.Next(0, 255));
  }
 
  private void timer2_Tick(object sender, EventArgs e)
  {
   label2.Text = (DateTime.Now - dt1).Seconds.ToString();
 
  }
 
  private void btnStart_KeyDown(object sender, KeyEventArgs e)
  {
   if (e.KeyCode.ToString() == textBox1.Text || e.KeyCode.ToString()!=textBox1.Text)
   {
    count_all++;
    while (e.KeyCode.ToString() == textBox1.Text)
    {
     count_correct++;
     textBox1.Visible = false;
     textBox1.Clear();
     num = rd.Next(65, 90);
     textBox1.Visible = true;
     textBox1.Text = ((char)num).ToString();
     x = rd.Next(20, 400);
     y = rd.Next(20, 400);
     textBox1.Location = new Point(x, y);
 
    }
   }
   label2.Visible = true;
   label8.Visible = true;
   label6.Text = count_correct.ToString();
   label7.Text = (count_all - count_correct).ToString();
   string t = string.Format("{0,5:P2}", count_correct * 1.0 / count_all);
   label8.Text = t.ToString(); 
  }
 }
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

分享題目:C#如何實(shí)現(xiàn)簡(jiǎn)單打字游戲-創(chuàng)新互聯(lián)
分享路徑:http://www.rwnh.cn/article20/igcjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、企業(yè)建站、商城網(wǎng)站、Google、定制網(wǎng)站網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化
永和县| 察哈| 西乌珠穆沁旗| 万宁市| 桐乡市| 汤原县| 凭祥市| 洛隆县| 平定县| 阿坝县| 府谷县| 晋江市| 温宿县| 边坝县| 泰安市| 彭泽县| 永州市| 巫山县| 龙胜| 石门县| 常德市| 济源市| 平定县| 阜南县| 孝义市| 瓮安县| 平塘县| 且末县| 嘉峪关市| 涟源市| 松原市| 泸水县| 台东市| 花莲县| 安义县| 洱源县| 怀集县| 德州市| 昌平区| 和田县| 特克斯县|