Rev 1 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | unit HighScore; |
2 | |||
3 | interface |
||
4 | |||
5 | uses |
||
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, |
||
7 | Dialogs, ComCtrls, StdCtrls; |
||
8 | |||
9 | type |
||
10 | THighScoreForm = class(TForm) |
||
11 | PageControl: TPageControl; |
||
12 | RemainingTab: TTabSheet; |
||
13 | TimeTab: TTabSheet; |
||
14 | RemainingList: TListView; |
||
15 | ScoreTab: TTabSheet; |
||
16 | PPMTab: TTabSheet; |
||
17 | TimeList: TListView; |
||
18 | ScoreList: TListView; |
||
19 | PPMList: TListView; |
||
20 | CloseBtn: TButton; |
||
21 | ClearBtn: TButton; |
||
22 | procedure CompareDesc(Sender: TObject; Item1, Item2: TListItem; |
||
23 | Data: Integer; var Compare: Integer); |
||
24 | procedure CompareAsc(Sender: TObject; Item1, Item2: TListItem; |
||
25 | Data: Integer; var Compare: Integer); |
||
26 | procedure CloseBtnClick(Sender: TObject); |
||
27 | procedure ClearBtnClick(Sender: TObject); |
||
28 | private |
||
29 | FLevelName: String; |
||
30 | procedure Parse(JournalEntry: String); |
||
31 | procedure ReadOutJournal; |
||
32 | procedure ClearLists; |
||
33 | public |
||
34 | procedure Execute(LevelName: String); |
||
35 | end; |
||
36 | |||
37 | var |
||
38 | HighScoreForm: THighScoreForm; |
||
39 | |||
40 | implementation |
||
41 | |||
42 | {$R *.dfm} |
||
43 | |||
44 | uses |
||
45 | Functions, Constants; |
||
46 | |||
47 | procedure THighScoreForm.CompareDesc(Sender: TObject; Item1, |
||
48 | Item2: TListItem; Data: Integer; var Compare: Integer); |
||
49 | var |
||
50 | n1, n2: integer; |
||
51 | begin |
||
52 | if item1.SubItems.Count < 1 then exit; |
||
53 | if item2.SubItems.Count < 1 then exit; |
||
54 | |||
55 | n1 := StrToIntDef(Item1.SubItems[1], 0); |
||
56 | n2 := StrToIntDef(Item2.SubItems[1], 0); |
||
57 | |||
58 | if (n1 = n2) |
||
59 | then Compare := 0 else |
||
60 | if (n1 > n2) |
||
61 | then Compare := 1 |
||
62 | else Compare := -1; |
||
63 | end; |
||
64 | |||
65 | procedure THighScoreForm.Parse(JournalEntry: String); |
||
66 | var |
||
67 | res: TStringList; |
||
68 | Date, Name: String; |
||
69 | Score, Seconds, Removed, Total: Integer; |
||
70 | Remaining, PPM: integer; |
||
71 | begin |
||
72 | res := Explode(JNL_SEP, JournalEntry); |
||
73 | |||
74 | // VARIABLES |
||
75 | |||
76 | Date := res.Strings[0]; |
||
77 | Name := res.Strings[1]; |
||
78 | Score := StrToIntDef(res.Strings[2], 0); |
||
79 | Seconds := StrToIntDef(res.Strings[3], 0); |
||
80 | Removed := StrToIntDef(res.Strings[4], 0); |
||
81 | Total := StrToIntDef(res.Strings[5], 0); |
||
82 | |||
83 | Remaining := Total - Removed; |
||
84 | PPM := Round(Score / Seconds * 60); |
||
85 | |||
86 | // CATEGORY A - LOWEST REMAINING STONES |
||
87 | |||
88 | RemainingList.SortType := stNone; |
||
89 | |||
90 | with RemainingList.Items.Add do |
||
91 | begin |
||
92 | Caption := Name; |
||
93 | SubItems.Add(Date); |
||
94 | SubItems.Add(IntToStr(Remaining)); |
||
95 | end; |
||
96 | |||
97 | RemainingList.SortType := stText; |
||
98 | |||
99 | // CATEGORY B - HIGHEST SCORE |
||
100 | |||
101 | ScoreList.SortType := stNone; |
||
102 | |||
103 | with ScoreList.Items.Add do |
||
104 | begin |
||
105 | Caption := Name; |
||
106 | SubItems.Add(Date); |
||
107 | SubItems.Add(IntToStr(Score)); |
||
108 | end; |
||
109 | |||
110 | ScoreList.SortType := stText; |
||
111 | |||
112 | // CATEGORY C - LOWEST TIME |
||
113 | |||
114 | TimeList.SortType := stNone; |
||
115 | |||
116 | with TimeList.Items.Add do |
||
117 | begin |
||
118 | Caption := Name; |
||
119 | SubItems.Add(Date); |
||
120 | SubItems.Add(IntToStr(Seconds)); |
||
121 | end; |
||
122 | |||
123 | TimeList.SortType := stText; |
||
124 | |||
125 | // CATEGORY D - HIGHEST POINTS PER MINUTE |
||
126 | |||
127 | PPMList.SortType := stNone; |
||
128 | |||
129 | with PPMList.Items.Add do |
||
130 | begin |
||
131 | Caption := Name; |
||
132 | SubItems.Add(Date); |
||
133 | SubItems.Add(IntToStr(PPM)); |
||
134 | end; |
||
135 | |||
136 | PPMList.SortType := stText; |
||
137 | end; |
||
138 | |||
139 | procedure THighScoreForm.ReadOutJournal; |
||
140 | var |
||
141 | f: textfile; |
||
142 | tmp: string; |
||
143 | begin |
||
144 | ClearLists; |
||
145 | |||
146 | tmp := Format(JNL_FILE, [FLevelName]); |
||
147 | if FileExists(tmp) then |
||
148 | begin |
||
149 | AssignFile(f, tmp); |
||
150 | Reset(f); |
||
151 | while not eof(f) do |
||
152 | begin |
||
153 | ReadLn(f, tmp); |
||
154 | Parse(tmp); |
||
155 | end; |
||
156 | CloseFile(f); |
||
157 | end; |
||
158 | end; |
||
159 | |||
160 | procedure THighScoreForm.Execute(LevelName: String); |
||
161 | begin |
||
162 | FLevelName := LevelName; |
||
163 | |||
164 | ReadOutJournal; |
||
165 | ShowModal; |
||
166 | end; |
||
167 | |||
168 | procedure THighScoreForm.CompareAsc(Sender: TObject; Item1, |
||
169 | Item2: TListItem; Data: Integer; var Compare: Integer); |
||
170 | var |
||
171 | n1, n2: integer; |
||
172 | begin |
||
173 | if item1.SubItems.Count < 1 then exit; |
||
174 | if item2.SubItems.Count < 1 then exit; |
||
175 | |||
176 | n1 := StrToIntDef(Item1.SubItems[1], 0); |
||
177 | n2 := StrToIntDef(Item2.SubItems[1], 0); |
||
178 | |||
179 | if (n1 = n2) |
||
180 | then Compare := 0 else |
||
181 | if (n1 > n2) |
||
182 | then Compare := -1 |
||
183 | else Compare := 1; |
||
184 | end; |
||
185 | |||
186 | procedure THighScoreForm.CloseBtnClick(Sender: TObject); |
||
187 | begin |
||
188 | Close(); |
||
189 | end; |
||
190 | |||
191 | procedure THighScoreForm.ClearBtnClick(Sender: TObject); |
||
8 | daniel-mar | 192 | resourcestring |
193 | LNG_ARE_YOU_SURE = 'Are you really sure you want to clear the high score list?'; |
||
1 | daniel-mar | 194 | begin |
8 | daniel-mar | 195 | if MessageDlg(LNG_ARE_YOU_SURE, mtConfirmation, mbYesNoCancel) = mrYes then |
196 | begin |
||
197 | DeleteFile(Format(JNL_FILE, [FLevelName])); |
||
198 | ClearLists; |
||
199 | end; |
||
1 | daniel-mar | 200 | end; |
201 | |||
202 | procedure THighScoreForm.ClearLists; |
||
203 | begin |
||
204 | RemainingList.Clear; |
||
205 | ScoreList.Clear; |
||
206 | TimeList.Clear; |
||
207 | PPMList.Clear; |
||
208 | end; |
||
209 | |||
210 | end. |