问题如下:
为什么StatusScrip控件没有更新数据?
源代码如下:
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 打字游戏120160802
{
public partial class Form1 : Form
{
Random random = new Random();
Status status = new Status();
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
listBox1.Items.Add((Keys)random.Next(48, 57));
if (listBox1.Items.Count > 10)
{
listBox1.Items.Clear();
listBox1.Items.Add("Game Over");
timer1.Stop();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (listBox1.Items.Contains(e.KeyCode))
{
listBox1.Items.Remove(e.KeyCode);
listBox1.Refresh();
if (timer1.Interval > 400)
timer1.Interval -= 1;
if (timer1.Interval > 250)
timer1.Interval -= 1;
if (timer1.Interval > 100)
timer1.Interval -= 1;
difficultyProgressBar.Value = 800 - timer1.Interval;
status.Update(true);
}
else
{
status.Update(false);
}
correctLabel.Text = "Correct: " + status.Correct;
missedLabel.Text = "Missed: " + status.Missed;
totalLabel.Text = "Total: " + status.Total;
accuracyLabel.Text = "Accuracy: " + status.Accuracy + "%";
}
private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
}
}
类——Status.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 打字游戏120160802
{
class Status
{
public int Total = 0;
public int Missed = 0;
public int Correct = 0;
public int Accuracy = 0;
public void Update(bool correctKey)
{
Total++;
if (!correctKey)
{
Missed++;
}
else
{
Correct++;
}
Accuracy = Correct / (Missed + Correct) * 100;
}
}
}
谢谢!