-
Notifications
You must be signed in to change notification settings - Fork 1
/
Score.cs
67 lines (54 loc) · 1.25 KB
/
Score.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace SpaceInvaders
{
/// <summary>
/// The score of the game
/// </summary>
public class Score
{
public int Count = 0;
public Point Position = new Point(0,0);
public Font MyFont = new Font("Compact", 20.0f, GraphicsUnit.Pixel );
public Score(int x, int y)
{
//
// TODO: Add constructor logic here
//
Position.X = x;
Position.Y = y;
}
public bool GameOver = false;
public virtual void Draw(Graphics g)
{
if (GameOver == false)
g.DrawString("Score: " + Count.ToString(), MyFont, Brushes.RoyalBlue, Position.X, Position.Y, new StringFormat());
else
g.DrawString("Game Over - Final Score: " + Count.ToString(), MyFont, Brushes.RoyalBlue, Position.X, Position.Y, new StringFormat());
}
public Rectangle GetFrame()
{
Rectangle myRect = new Rectangle(Position.X, Position.Y, (int)MyFont.SizeInPoints*Count.ToString().Length, MyFont.Height);
return myRect;
}
/// <summary>
/// Resets the score to 0
/// </summary>
public void Reset()
{
Count = 0;
}
/// <summary>
/// Increments the score by 1
/// </summary>
public void Increment()
{
Count++;
}
public void AddScore(int val)
{
Count += val;
}
}
}