电脑打字游戏 推荐c#怎么控制下落的label中的值不一样

打字游戏c#怎么控制下落的label中的值不一样_百度知道
打字游戏c#怎么控制下落的label中的值不一样
就是掉下来的值,让他们不重复
我有更好的答案
你这样写,根本就是重新创建了一个form1对象,对于已经打开的form1,压根不是同一个,所以你修改的label的值也不是你原来打开的label的值。
label我写的值忽略,该怎么写
采纳率:74%
来自团队:
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。C#—打字游戏
* 利用Random类,结合Timer控件,设计窗体。在窗体上的文本框中显示一个大写字符,如果用户输入正确,则产生另一个大写字符。
* 实现打字游戏。(提示:金山打字通的简易版)窗体中的按钮可以用菜单实现。
* 菜单命令组成:
* (1)“设置”菜单:开始游戏、结束游戏和退出游戏。
* (2)“查看”菜单:查看正确率和打字所用的时间。
* 提示与思考:
* (1)判断输入字符正确与否,采用哪个控件的哪个事件;
* (2)首先考虑如何实现一个静止的字符(不移动)的输入判断;然后考虑如何让字符动起来;
* (3)如果字符移出窗体边界,仍然没有输入正确,如何让该字符重新出现在窗体的顶端某处。
using System.Collections.G
using System.ComponentM
using System.D
using System.D
using System.L
using System.T
using System.Windows.F
namespace WindowsFormsApplication2
public partial class Form1 : Form
public Form1()
InitializeComponent();
private int x=200,y,
private DateTime dt1,dt2;
private int count=0;
//打字总数
private int count1=0;
//打字正确数
private TimeS
Random rd = new Random();
private void Form1_Load(object sender, EventArgs e)
正确率ToolStripMenuItem.Enabled =
所用时间ToolStripMenuItem.Enabled =
this.KeyPreview =
button1.Text = "开始";
button2.Text = "结束";
button3.Text = "退出";
label1.Text = "正确数:";
label2.Text = "错误数:";
label3.Text = "正确率:";
label4.Text = "0";
label5.Text = "0";
label7.Text = "所用时间:";
label8.Text = "0";
label6.Visible =
textBox1.Visible =
pictureBox1.SizeMode = PictureBoxSizeMode.StretchI
pictureBox1.Image = Image.FromFile(Application.StartupPath + @"\g.png");
timer1.Enabled =
timer1.Interval = 5;
timer2.Enabled =
timer2.Interval = 1000;
private void button1_Click(object sender, EventArgs e)
//开始按钮
正确率ToolStripMenuItem.Enabled =
dt1 = DateTime.N
timer1.Start();
timer2.Start();
textBox1.Visible =
num = rd.Next(65, 90);
private void button2_Click(object sender, EventArgs e)
//结束按钮
所用时间ToolStripMenuItem.Enabled =
dt2 = DateTime.N
timer1.Stop();
timer2.Stop();
textBox1.Visible =
MessageBox.Show("游戏结束!", "提示");
private void button3_Click(object sender, EventArgs e)
//退出按钮
timer1.Stop();
textBox1.Visible =
DialogResult dr = MessageBox.Show("确定要退出吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (dr == DialogResult.OK)
Application.Exit();
private void 开始游戏ToolStripMenuItem_Click(object sender, EventArgs e)
dt1 = DateTime.N
timer1.Start();
timer2.Start();
textBox1.Visible =
num = rd.Next(65, 90);
private void 结束游戏ToolStripMenuItem_Click(object sender, EventArgs e)
dt2 = DateTime.N
timer1.Stop();
timer2.Stop();
textBox1.Visible =
MessageBox.Show("游戏结束!", "提示");
private void 退出游戏ToolStripMenuItem_Click(object sender, EventArgs e)
timer1.Stop();
textBox1.Visible =
DialogResult dr= MessageBox.Show("确定要退出吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (dr == DialogResult.OK)
Application.Exit();
private void 正确率ToolStripMenuItem_Click(object sender, EventArgs e)
double truerate = count1 * 1.0 /
string s = string.Format("{0,5:P2}", truerate);
MessageBox.Show("正确率为:" +s, "正确率");
private void 所用时间ToolStripMenuItem_Click(object sender, EventArgs e)
ts=dt2-dt1;
MessageBox.Show("所用时间为:" + ts.Seconds+"(s)", "所用时间");
private void timer1_Tick(object sender, EventArgs e)
if (y & this.ClientSize.Height - 5)
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)
label8.Text = (DateTime.Now - dt1).Seconds.ToString();
private void button1_KeyDown(object sender, KeyEventArgs e)
if (e.KeyCode.ToString() == textBox1.Text || e.KeyCode.ToString() != textBox1.Text)
while (e.KeyCode.ToString() == textBox1.Text)
textBox1.Visible =
textBox1.Clear();
num = rd.Next(65, 90);
textBox1.Visible =
textBox1.Text = ((char)num).ToString();
x = rd.Next(20, 600);
y = rd.Next(20, 300);
textBox1.Location = new Point(x, y);
label6.Visible =
label8.Visible =
label4.Text = count1.ToString();
label5.Text = (count - count1).ToString();
string t = string.Format("{0,5:P2}", count1 * 1.0 / count);
label6.Text = t.ToString();
运行结果:
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!涓婁紶鍙戝竷
禄 c#鎵撳瓧娓告垙
c#鎵撳瓧娓告垙

我要回帖

更多关于 打字游戏 的文章

 

随机推荐