-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspiderstats.pas
More file actions
116 lines (93 loc) · 3.3 KB
/
Copy pathspiderstats.pas
File metadata and controls
116 lines (93 loc) · 3.3 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
unit SpiderStats;
{$mode objfpc}{$H+}
interface
uses
SysUtils, SpiderTypes;
procedure InitStats(var S: TSpiderStats);
procedure RecordGameStart(var U: TUserList; Difficulty: TSpiderDifficulty);
procedure RecordGameEnd(var G: TSpiderGame; U: TUserList; Difficulty: TSpiderDifficulty; Won: Boolean);
procedure ShowStats(const U: TUserList);
procedure ResetStats(var Stats: TSpiderStats);
implementation
procedure InitStats(var S: TSpiderStats);
begin
FillChar(S, SizeOf(S), 0); { #todo : What the eff is this doing?!?! }
end;
procedure RecordGameStart(var U: TUserList; Difficulty: TSpiderDifficulty);
begin
Inc(U.Players[ActiveUserIndex].Stats.GamesPlayed);
case Difficulty of
sdOneSuit: Inc(U.Players[ActiveUserIndex].Stats.OneSuitPlayed);
sdTwoSuit: Inc(U.Players[ActiveUserIndex].Stats.TwoSuitPlayed);
sdFourSuit: Inc(U.Players[ActiveUserIndex].Stats.FourSuitPlayed);
end;
U.Players[ActiveUserIndex].Stats.LastDifficulty := intDiff;
//S.HasSavedGame := False; //???
end;
procedure RecordGameEnd(var G: TSpiderGame; U: TUserList; Difficulty: TSpiderDifficulty; Won: Boolean);
begin
if Won then
begin
Inc(U.Players[ActiveUserIndex].Stats.GamesWon);
case Difficulty of
sdOneSuit: Inc(U.Players[ActiveUserIndex].Stats.OneSuitWon);
sdTwoSuit: Inc(U.Players[ActiveUserIndex].Stats.TwoSuitWon);
sdFourSuit: Inc(U.Players[ActiveUserIndex].Stats.FourSuitWon);
end;
end
else
Inc(U.Players[ActiveUserIndex].Stats.GamesLost);
// Final stats
Inc(U.Players[ActiveUserIndex].Stats.TotalStacks, G.CompletedRuns);
end;
procedure ShowStats(const U: TUserList);
var
winPct: Double;
begin
if U.Players[ActiveUserIndex].Stats.GamesPlayed > 0 then
winPct := (U.Players[ActiveUserIndex].Stats.GamesWon / U.Players[ActiveUserIndex].Stats.GamesPlayed) * 100
else
winPct := 0;
WriteLn('=== Spider Solitaire Statistics ===');
WriteLn('Games Played: ', U.Players[ActiveUserIndex].Stats.GamesPlayed);
WriteLn('Games Won: ', U.Players[ActiveUserIndex].Stats.GamesWon);
WriteLn('Games Lost: ', U.Players[ActiveUserIndex].Stats.GamesLost);
WriteLn('Win %: ', FormatFloat('0.0', winPct));
WriteLn('Total Moves: ', U.Players[ActiveUserIndex].Stats.TotalMoves);
WriteLn;
WriteLn('--- Difficulty Breakdown ---');
WriteLn('1-Suit: ', U.Players[ActiveUserIndex].Stats.OneSuitWon, ' wins / ', U.Players[ActiveUserIndex].Stats.OneSuitPlayed, ' played');
WriteLn('2-Suit: ', U.Players[ActiveUserIndex].Stats.TwoSuitWon, ' wins / ', U.Players[ActiveUserIndex].Stats.TwoSuitPlayed, ' played');
WriteLn('4-Suit: ', U.Players[ActiveUserIndex].Stats.FourSuitWon, ' wins / ', U.Players[ActiveUserIndex].Stats.FourSuitPlayed, ' played');
WriteLn;
WriteLn('Press any key to continue.');
WriteLn;
ReadLn;
end;
procedure ResetStats(var Stats: TSpiderStats);
begin
with Stats do
begin
GamesPlayed := 0;
GamesWon := 0;
GamesLost := 0;
GamesDrawn := 0;
WinPercentage := 0;
HighScore := 0;
AverageScorePerGame := 0;
BestTime := 0;
AverageTimePerGame := 0;
TotalMoves := 0;
TotalStacks := 0;
AverageStacksPerGame := 0;
OneSuitPlayed := 0;
OneSuitWon := 0;
TwoSuitPlayed := 0;
TwoSuitWon := 0;
FourSuitPlayed := 0;
FourSuitWon := 0;
LastDifficulty := 0;
HasSavedGame := False;
end;
end;
end.