我想知道我将如何去创建一个高分系统。我制作了一个带有分数的简单游戏,但我希望将高分保存在一个文件中,因此当应用程序运行时,您可以看到带有名称的高分。到目前为止,我的游戏代码,如果需要的话:
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 Guess_the_number_1
{
public partial class Form1 : Form
{
int randomNumber;
int score;
Random random;
public Form1()
{
InitializeComponent();
random = new Random();
}
private void Form1_Load(object sender, EventArgs e)
{
score = 0;
label1.Text = score.ToString();
}
private void buttonCheckGuess_Click(object sender, EventArgs e)
{
randomNumber = random.Next(0, 10);
if (Convert.ToInt32(textboxGuess.Text) == randomNumber)
{
MessageBox.Show("Your Guessed Correctly! The Number Is: " + textboxGuess.Text);
score += 10;
}
else if (Convert.ToInt32(textboxGuess.Text) < randomNumber)
{
MessageBox.Show("The Number Is Larger Than: " + textboxGuess.Text);
score -= 2;
}
else if (Convert.ToInt32(textboxGuess.Text) > randomNumber)
{
MessageBox.Show("The Number Is Smaller Than: " + textboxGuess.Text);
score -= 2;
}
else
{
MessageBox.Show("Your Guessed Incorrectly. The Random Number Is Not: " + textboxGuess.Text);
}
label1.Text = score.ToString();
}
private void buttonScore_Click(object sender, EventArgs e)
{
MessageBox.Show("Your score is " + score);
}
private void listScore_SelectedIndexChanged(object sender, EventArgs e) { }
private void label1_Click(object sender, EventArgs e) { }
}
}