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