-
Notifications
You must be signed in to change notification settings - Fork 1
/
Score.cs
89 lines (79 loc) · 2.2 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
namespace Asteroids
{
/// <summary>
/// Maintains the score information for the game
/// </summary>
public class Score : CommonOps
{
protected int iScore;
protected int iShips;
protected int iHiScore;
protected int iFreeShip;
const int iFreeShipIncrement = 10000;
public Score()
{
iShips = 0;
iScore = 0;
iHiScore = 0;
iFreeShip = iFreeShipIncrement;
}
public void GetNewShip()
{
iShips -= 1;
}
public bool HasReserveShips()
{
// current ship doesn't count
return (iShips > 1);
}
public void ResetGame()
{
iShips = 3;
iScore = 0;
iFreeShip = iFreeShipIncrement;
}
public void CancelGame()
{
iShips = 0;
}
public void AddScore(int iAddScore)
{
iScore += iAddScore;
if (iScore >= iFreeShip)
{
iShips += 1;
iFreeShip += iFreeShipIncrement;
PlaySound("life.wav");
}
if (iScore >= 1000000)
iScore = iScore % 1000000;
if (iScore > iHiScore)
iHiScore = iScore;
}
public void Draw(ScreenCanvas screenCanvas, int iPictX, int iPictY)
{
const int iWriteTop = 100;
const int iLetterWidth = 200;
const int iLetterHeight = iLetterWidth * 2;
String strScore;
// Draw Score + Ships left justified
strScore = iScore.ToString("000000") + " ";
if (iShips > 10)
{
strScore += "^x" + (iShips-1);
}
else
{
for (int i=0; i<iShips-1; i++)
strScore += "^";
}
TextDraw.DrawText(screenCanvas, strScore, TextDraw.Justify.LEFT,
iWriteTop, iLetterWidth, iLetterHeight, iPictX, iPictY);
// Draw HiScore Centered
strScore = iHiScore.ToString("000000");
TextDraw.DrawText(screenCanvas, strScore, TextDraw.Justify.CENTER,
iWriteTop, iLetterWidth, iLetterHeight, iPictX, iPictY);
}
}
}