-
Notifications
You must be signed in to change notification settings - Fork 1
/
HighScore.cs
49 lines (43 loc) · 917 Bytes
/
HighScore.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Drawing;
using System.IO;
namespace SpaceInvaders
{
/// <summary>
/// Summary description for HighScore.
/// </summary>
public class HighScore : Score
{
public HighScore(int x, int y) : base(x, y)
{
//
// TODO: Add constructor logic here
//
}
public override void Draw(Graphics g)
{
g.DrawString("High Score: " + Count.ToString(), MyFont, Brushes.RoyalBlue, Position.X, Position.Y, new StringFormat());
}
public void Write(int theScore)
{
Read();
if (Count < theScore)
{
Count = theScore;
StreamWriter sw = new StreamWriter("highscore.txt", false);
sw.WriteLine(Count.ToString());
sw.Close();
}
}
public void Read()
{
if (File.Exists("highscore.txt"))
{
StreamReader sr = new StreamReader("highscore.txt");
string score = sr.ReadLine();
Count = Convert.ToInt32(score);
sr.Close();
}
}
}
}