Rev 8 | Rev 10 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8 | Rev 9 | ||
---|---|---|---|
1 | unit Main; |
1 | unit Main; |
2 | 2 | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | uses |
5 | uses |
6 | Windows, SysUtils, Classes, Graphics, Dialogs, StdCtrls, Menus, Controls, |
6 | Windows, SysUtils, Classes, Graphics, Dialogs, StdCtrls, Menus, Controls, |
7 | ComCtrls, ExtCtrls, Forms, MMSystem, LevelFunctions, Registry; |
7 | ComCtrls, ExtCtrls, Forms, MMSystem, LevelFunctions, Registry; |
8 | 8 | ||
9 | type |
9 | type |
10 | TField = record |
10 | TField = record |
11 | FieldType: TFieldType; |
11 | FieldType: TFieldType; |
12 | Goal: Boolean; |
12 | Goal: Boolean; |
13 | Panel: TPanel; |
13 | Panel: TPanel; |
14 | Stone: TImage; |
14 | Stone: TImage; |
15 | end; |
15 | end; |
16 | 16 | ||
17 | TGoalStatus = (gsNoGoal, gsMultipleStonesRemaining, gsLastStoneInGoalRed, gsLastStoneInGoalYellow, gsLastStoneInGoalGreen, gsLastStoneOutsideGoal); |
17 | TGoalStatus = (gsNoGoal, gsMultipleStonesRemaining, gsLastStoneInGoalRed, gsLastStoneInGoalYellow, gsLastStoneInGoalGreen, gsLastStoneOutsideGoal); |
18 | 18 | ||
19 | TFieldState = (fsError, fsLocked, fsAvailable, fsStone); |
19 | TFieldState = (fsError, fsLocked, fsAvailable, fsStone); |
20 | 20 | ||
21 | TPlayGroundMatrix = array of array of TField; |
21 | TPlayGroundMatrix = array of array of TField; |
22 | 22 | ||
23 | TMainForm = class(TForm) |
23 | TMainForm = class(TForm) |
24 | Playground: TPanel; |
24 | Playground: TPanel; |
25 | MainMenu: TMainMenu; |
25 | MainMenu: TMainMenu; |
26 | Help1: TMenuItem; |
26 | Help1: TMenuItem; |
27 | MExit: TMenuItem; |
27 | MExit: TMenuItem; |
28 | Statistics: TStatusBar; |
28 | Statistics: TStatusBar; |
29 | Timer: TTimer; |
29 | Timer: TTimer; |
30 | MNewGame: TMenuItem; |
30 | MNewGame: TMenuItem; |
31 | Help2: TMenuItem; |
31 | Help2: TMenuItem; |
32 | MAbout: TMenuItem; |
32 | MAbout: TMenuItem; |
33 | MHelp: TMenuItem; |
33 | MHelp: TMenuItem; |
34 | N5: TMenuItem; |
34 | N5: TMenuItem; |
35 | MJumpHistory: TMenuItem; |
35 | MJumpHistory: TMenuItem; |
36 | N2: TMenuItem; |
36 | N2: TMenuItem; |
37 | N4: TMenuItem; |
37 | N4: TMenuItem; |
38 | MHighScores: TMenuItem; |
38 | MHighScores: TMenuItem; |
39 | MRestartGame: TMenuItem; |
39 | MRestartGame: TMenuItem; |
40 | MSettings: TMenuItem; |
40 | MSettings: TMenuItem; |
41 | MEnableSound: TMenuItem; |
41 | MEnableSound: TMenuItem; |
42 | MPauseTime: TMenuItem; |
42 | MPauseTime: TMenuItem; |
43 | N1: TMenuItem; |
43 | N1: TMenuItem; |
44 | MUndo: TMenuItem; |
44 | MUndo: TMenuItem; |
45 | N3: TMenuItem; |
45 | N3: TMenuItem; |
46 | procedure MExitClick(Sender: TObject); |
46 | procedure MExitClick(Sender: TObject); |
47 | procedure TimerTimer(Sender: TObject); |
47 | procedure TimerTimer(Sender: TObject); |
48 | procedure MNewGameClick(Sender: TObject); |
48 | procedure MNewGameClick(Sender: TObject); |
49 | procedure MAboutClick(Sender: TObject); |
49 | procedure MAboutClick(Sender: TObject); |
50 | procedure FormShow(Sender: TObject); |
50 | procedure FormShow(Sender: TObject); |
51 | procedure FormCreate(Sender: TObject); |
51 | procedure FormCreate(Sender: TObject); |
52 | procedure FormDestroy(Sender: TObject); |
52 | procedure FormDestroy(Sender: TObject); |
53 | procedure MJumpHistoryClick(Sender: TObject); |
53 | procedure MJumpHistoryClick(Sender: TObject); |
54 | procedure MRestartGameClick(Sender: TObject); |
54 | procedure MRestartGameClick(Sender: TObject); |
55 | procedure MHighScoresClick(Sender: TObject); |
55 | procedure MHighScoresClick(Sender: TObject); |
56 | procedure MPauseTimeClick(Sender: TObject); |
56 | procedure MPauseTimeClick(Sender: TObject); |
57 | procedure FormClose(Sender: TObject; var Action: TCloseAction); |
57 | procedure FormClose(Sender: TObject; var Action: TCloseAction); |
58 | procedure MHelpClick(Sender: TObject); |
58 | procedure MHelpClick(Sender: TObject); |
59 | procedure MEnableSoundClick(Sender: TObject); |
59 | procedure MEnableSoundClick(Sender: TObject); |
60 | procedure MUndoClick(Sender: TObject); |
60 | procedure MUndoClick(Sender: TObject); |
61 | private |
61 | private |
62 | CountedSeconds: Integer; |
62 | CountedSeconds: Integer; |
63 | LevelFile: String; |
63 | LevelFile: String; |
64 | LookupFieldCoordinateArray: array of TPoint; |
64 | LookupFieldCoordinateArray: array of TPoint; |
65 | OriginalPlayGroundMatrix: TPlayGroundMatrix; |
65 | OriginalPlayGroundMatrix: TPlayGroundMatrix; |
66 | PrevPlaygroundMatrixes: array of TPlayGroundMatrix; |
66 | PrevPlaygroundMatrixes: array of TPlayGroundMatrix; |
67 | PlaygroundMatrix: TPlayGroundMatrix; |
67 | PlaygroundMatrix: TPlayGroundMatrix; |
68 | Points: Integer; |
68 | Points: Integer; |
69 | LevelTotalStones: Integer; |
69 | LevelTotalStones: Integer; |
70 | LevelRemovedStones: Integer; |
70 | LevelRemovedStones: Integer; |
71 | JumpHistory: TStringList; |
71 | JumpHistory: TStringList; |
72 | procedure LoadSettings; |
72 | procedure LoadSettings; |
73 | procedure SaveSettings; |
73 | procedure SaveSettings; |
74 | procedure RestartLevel; |
74 | procedure RestartLevel; |
75 | procedure SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix); |
75 | procedure SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix); |
76 | procedure RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix); |
76 | procedure RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix); |
77 | function AskForLevel: String; |
77 | function AskForLevel: String; |
78 | function AreJumpsPossible: boolean; |
78 | function AreJumpsPossible: boolean; |
79 | procedure StoneDraggingAllow(Stone: TImage; Allow: boolean); |
79 | procedure StoneDraggingAllow(Stone: TImage; Allow: boolean); |
80 | procedure NewGame(Filename: string); |
80 | procedure NewGame(Filename: string); |
81 | function LevelTime: String; |
81 | function LevelTime: String; |
82 | procedure DestroyLevel; |
82 | procedure DestroyLevel; |
83 | procedure RefreshTime; |
83 | procedure RefreshTime; |
84 | procedure RefreshPoints; |
84 | procedure RefreshPoints; |
85 | procedure RefreshStonesRemoved; |
85 | procedure RefreshStonesRemoved; |
86 | procedure CountPoints(t: TFieldType); |
86 | procedure CountPoints(t: TFieldType); |
87 | procedure RemoveStone(x, y: integer; count_points: boolean); |
87 | procedure RemoveStone(x, y: integer; count_points: boolean); |
88 | procedure DoJump(SourceTag, DestTag: integer); |
88 | procedure DoJump(SourceTag, DestTag: integer); |
89 | function CanJump(x, y: integer): boolean; |
89 | function CanJump(x, y: integer): boolean; |
90 | function MayJump(SourceX, SourceY, DestX, DestY: integer): boolean; overload; |
90 | function MayJump(SourceX, SourceY, DestX, DestY: integer): boolean; overload; |
91 | function MayJump(SourceTag, DestTag: integer): boolean; overload; |
91 | function MayJump(SourceTag, DestTag: integer): boolean; overload; |
92 | procedure StoneDragOver(Sender, Source: TObject; X, |
92 | procedure StoneDragOver(Sender, Source: TObject; X, |
93 | Y: Integer; State: TDragState; var Accept: Boolean); |
93 | Y: Integer; State: TDragState; var Accept: Boolean); |
94 | procedure StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
94 | procedure StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
95 | procedure DrawField(x, y: integer; t: TFieldProperties; halftabs: integer); |
95 | procedure DrawField(x, y: integer; t: TFieldProperties; halftabs: integer); |
96 | function DrawStone(fieldtype: TFieldType; panel: TPanel): TImage; |
96 | function DrawStone(fieldtype: TFieldType; panel: TPanel): TImage; |
97 | function DrawStoneBox(x, y, tag, halftabs: integer; isGoal: boolean): TPanel; |
97 | function DrawStoneBox(x, y, tag, halftabs: integer; isGoal: boolean): TPanel; |
98 | procedure BuildPlayground(LevelArray: TLevelArray); |
98 | procedure BuildPlayground(LevelArray: TLevelArray); |
99 | function FieldState(t: TFieldType): TFieldState; overload; |
99 | function FieldState(t: TFieldType): TFieldState; overload; |
100 | function FieldState(f: TField): TFieldState; overload; |
100 | function FieldState(f: TField): TFieldState; overload; |
101 | function FieldState(x, y: integer): TFieldState; overload; |
101 | function FieldState(x, y: integer): TFieldState; overload; |
102 | procedure ClearMatrix(Matrix: TPlayGroundMatrix; FreeVCL: boolean); |
102 | procedure ClearMatrix(Matrix: TPlayGroundMatrix; FreeVCL: boolean); |
103 | function CloneMatrix(Source: TPlayGroundMatrix): TPlayGroundMatrix; |
103 | function CloneMatrix(Source: TPlayGroundMatrix): TPlayGroundMatrix; |
104 | function MatrixHasGoal(Matrix: TPlayGroundMatrix): boolean; |
104 | function MatrixHasGoal(Matrix: TPlayGroundMatrix): boolean; |
105 | procedure LoadPictureForType(FieldType: TFieldType; Picture: TPicture); |
105 | procedure LoadPictureForType(FieldType: TFieldType; Picture: TPicture); |
106 | function MatrixWorth(Matrix: TPlayGroundMatrix): integer; |
106 | function MatrixWorth(Matrix: TPlayGroundMatrix): integer; |
107 | function GoalStatus: TGoalStatus; |
107 | function GoalStatus: TGoalStatus; |
108 | function GoalFieldType(Matrix: TPlayGroundMatrix): TFieldType; |
108 | function GoalFieldType(Matrix: TPlayGroundMatrix): TFieldType; |
109 | end; |
109 | end; |
110 | 110 | ||
111 | var |
111 | var |
112 | MainForm: TMainForm; |
112 | MainForm: TMainForm; |
113 | 113 | ||
114 | implementation |
114 | implementation |
115 | 115 | ||
116 | uses |
116 | uses |
117 | About, Finish, Choice, Functions, History, HighScore, Help, Constants; |
117 | About, Finish, Choice, Functions, History, HighScore, Help, Constants; |
118 | 118 | ||
119 | {$R *.dfm} |
119 | {$R *.dfm} |
120 | 120 | ||
121 | function TMainForm.MatrixHasGoal(Matrix: TPlayGroundMatrix): boolean; |
121 | function TMainForm.MatrixHasGoal(Matrix: TPlayGroundMatrix): boolean; |
122 | var |
122 | var |
123 | i, j: integer; |
123 | i, j: integer; |
124 | begin |
124 | begin |
125 | result := false; |
125 | result := false; |
126 | for i := Low(Matrix) to High(Matrix) do |
126 | for i := Low(Matrix) to High(Matrix) do |
127 | begin |
127 | begin |
128 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
128 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
129 | begin |
129 | begin |
130 | result := result or Matrix[i][j].Goal; |
130 | result := result or Matrix[i][j].Goal; |
131 | end; |
131 | end; |
132 | end; |
132 | end; |
133 | end; |
133 | end; |
134 | 134 | ||
135 | function TMainForm.GoalFieldType(Matrix: TPlayGroundMatrix): TFieldType; |
135 | function TMainForm.GoalFieldType(Matrix: TPlayGroundMatrix): TFieldType; |
136 | var |
136 | var |
137 | i, j: integer; |
137 | i, j: integer; |
138 | begin |
138 | begin |
139 | for i := Low(Matrix) to High(Matrix) do |
139 | for i := Low(Matrix) to High(Matrix) do |
140 | begin |
140 | begin |
141 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
141 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
142 | begin |
142 | begin |
143 | if Matrix[i][j].Goal then result := Matrix[i][j].FieldType |
143 | if Matrix[i][j].Goal then result := Matrix[i][j].FieldType |
144 | end; |
144 | end; |
145 | end; |
145 | end; |
146 | end; |
146 | end; |
147 | 147 | ||
148 | function TMainForm.MatrixWorth(Matrix: TPlayGroundMatrix): integer; |
148 | function TMainForm.MatrixWorth(Matrix: TPlayGroundMatrix): integer; |
149 | var |
149 | var |
150 | i, j: integer; |
150 | i, j: integer; |
151 | begin |
151 | begin |
152 | result := 0; |
152 | result := 0; |
153 | for i := Low(Matrix) to High(Matrix) do |
153 | for i := Low(Matrix) to High(Matrix) do |
154 | begin |
154 | begin |
155 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
155 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
156 | begin |
156 | begin |
157 | Inc(result, FieldTypeWorth(Matrix[i][j].FieldType)); |
157 | Inc(result, FieldTypeWorth(Matrix[i][j].FieldType)); |
158 | end; |
158 | end; |
159 | end; |
159 | end; |
160 | end; |
160 | end; |
161 | 161 | ||
162 | procedure TMainForm.ClearMatrix(Matrix: TPlayGroundMatrix; FreeVCL: boolean); |
162 | procedure TMainForm.ClearMatrix(Matrix: TPlayGroundMatrix; FreeVCL: boolean); |
163 | var |
163 | var |
164 | i, j: integer; |
164 | i, j: integer; |
165 | begin |
165 | begin |
166 | for i := Low(Matrix) to High(Matrix) do |
166 | for i := Low(Matrix) to High(Matrix) do |
167 | begin |
167 | begin |
168 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
168 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
169 | begin |
169 | begin |
170 | if FreeVCL then |
170 | if FreeVCL then |
171 | begin |
171 | begin |
172 | if Assigned(Matrix[i][j].Stone) then Matrix[i][j].Stone.Free; |
172 | if Assigned(Matrix[i][j].Stone) then Matrix[i][j].Stone.Free; |
173 | if Assigned(Matrix[i][j].Panel) then Matrix[i][j].Panel.Free; |
173 | if Assigned(Matrix[i][j].Panel) then Matrix[i][j].Panel.Free; |
174 | end; |
174 | end; |
175 | end; |
175 | end; |
176 | SetLength(Matrix[i], 0); |
176 | SetLength(Matrix[i], 0); |
177 | end; |
177 | end; |
178 | SetLength(Matrix, 0); |
178 | SetLength(Matrix, 0); |
179 | end; |
179 | end; |
180 | 180 | ||
181 | procedure TMainForm.RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix); |
181 | procedure TMainForm.RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix); |
182 | var |
182 | var |
183 | i, j: integer; |
183 | i, j: integer; |
184 | begin |
184 | begin |
185 | for i := Low(Matrix) to High(Matrix) do |
185 | for i := Low(Matrix) to High(Matrix) do |
186 | begin |
186 | begin |
187 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
187 | for j := Low(Matrix[i]) to High(Matrix[i]) do |
188 | begin |
188 | begin |
189 | if Assigned(Matrix[i][j].Stone) then |
189 | if Assigned(Matrix[i][j].Stone) then |
190 | begin |
190 | begin |
191 | LoadPictureForType(Matrix[i][j].FieldType, Matrix[i][j].Stone.Picture); |
191 | LoadPictureForType(Matrix[i][j].FieldType, Matrix[i][j].Stone.Picture); |
192 | StoneDraggingAllow(Matrix[i][j].Stone, FieldState(Matrix[i][j].FieldType) <> fsAvailable); |
192 | StoneDraggingAllow(Matrix[i][j].Stone, FieldState(Matrix[i][j].FieldType) <> fsAvailable); |
193 | end; |
193 | end; |
194 | end; |
194 | end; |
195 | end; |
195 | end; |
196 | end; |
196 | end; |
197 | 197 | ||
198 | procedure TMainForm.DestroyLevel; |
198 | procedure TMainForm.DestroyLevel; |
199 | var |
199 | var |
200 | i: Integer; |
200 | i: Integer; |
201 | begin |
201 | begin |
202 | MPauseTime.Enabled := false; |
202 | MPauseTime.Enabled := false; |
203 | Timer.Enabled := false; |
203 | Timer.Enabled := false; |
204 | 204 | ||
205 | MRestartGame.Enabled := false; |
205 | MRestartGame.Enabled := false; |
206 | 206 | ||
207 | LevelFile := ''; |
207 | LevelFile := ''; |
208 | 208 | ||
209 | CountedSeconds := 0; |
209 | CountedSeconds := 0; |
210 | RefreshTime; |
210 | RefreshTime; |
211 | 211 | ||
212 | Points := 0; |
212 | Points := 0; |
213 | RefreshPoints; |
213 | RefreshPoints; |
214 | 214 | ||
215 | LevelRemovedStones := 0; |
215 | LevelRemovedStones := 0; |
216 | LevelTotalStones := 0; |
216 | LevelTotalStones := 0; |
217 | RefreshStonesRemoved; |
217 | RefreshStonesRemoved; |
218 | 218 | ||
219 | JumpHistory.Clear; |
219 | JumpHistory.Clear; |
220 | 220 | ||
221 | ClearMatrix(PlayGroundMatrix, true); |
221 | ClearMatrix(PlayGroundMatrix, true); |
222 | ClearMatrix(OriginalPlayGroundMatrix, false); |
222 | ClearMatrix(OriginalPlayGroundMatrix, false); |
223 | for i := 0 to Length(PrevPlaygroundMatrixes)-1 do |
223 | for i := 0 to Length(PrevPlaygroundMatrixes)-1 do |
224 | ClearMatrix(PrevPlaygroundMatrixes[i], false); |
224 | ClearMatrix(PrevPlaygroundMatrixes[i], false); |
225 | SetLength(PrevPlaygroundMatrixes, 0); |
225 | SetLength(PrevPlaygroundMatrixes, 0); |
226 | MUndo.Enabled := false; |
226 | MUndo.Enabled := false; |
227 | 227 | ||
228 | SetLength(LookupFieldCoordinateArray, 0); |
228 | SetLength(LookupFieldCoordinateArray, 0); |
229 | end; |
229 | end; |
230 | 230 | ||
231 | procedure TMainForm.LoadPictureForType(FieldType: TFieldType; Picture: TPicture); |
231 | procedure TMainForm.LoadPictureForType(FieldType: TFieldType; Picture: TPicture); |
232 | begin |
232 | begin |
233 | case FieldType of |
233 | case FieldType of |
234 | ftEmpty: Picture.Bitmap.LoadFromResourceName(HInstance, RES_EMPTY); |
234 | ftEmpty: Picture.Bitmap.LoadFromResourceName(HInstance, RES_EMPTY); |
235 | ftGreen: Picture.Bitmap.LoadFromResourceName(HInstance, RES_GREEN); |
235 | ftGreen: Picture.Bitmap.LoadFromResourceName(HInstance, RES_GREEN); |
236 | ftYellow: Picture.Bitmap.LoadFromResourceName(HInstance, RES_YELLOW); |
236 | ftYellow: Picture.Bitmap.LoadFromResourceName(HInstance, RES_YELLOW); |
237 | ftRed: Picture.Bitmap.LoadFromResourceName(HInstance, RES_RED); |
237 | ftRed: Picture.Bitmap.LoadFromResourceName(HInstance, RES_RED); |
238 | end; |
238 | end; |
239 | end; |
239 | end; |
240 | 240 | ||
241 | function TMainForm.DrawStone(fieldtype: TFieldType; panel: TPanel): TImage; |
241 | function TMainForm.DrawStone(fieldtype: TFieldType; panel: TPanel): TImage; |
242 | begin |
242 | begin |
243 | result := TImage.Create(panel); |
243 | result := TImage.Create(panel); |
244 | result.Parent := panel; |
244 | result.Parent := panel; |
245 | LoadPictureForType(fieldtype, result.Picture); |
245 | LoadPictureForType(fieldtype, result.Picture); |
246 | result.Width := panel.Width - 2*MET_SHAPE_MARGIN; |
246 | result.Width := panel.Width - 2*MET_SHAPE_MARGIN; |
247 | result.Height := panel.Height - 2*MET_SHAPE_MARGIN; |
247 | result.Height := panel.Height - 2*MET_SHAPE_MARGIN; |
248 | result.Left := MET_SHAPE_MARGIN; |
248 | result.Left := MET_SHAPE_MARGIN; |
249 | result.Top := MET_SHAPE_MARGIN; |
249 | result.Top := MET_SHAPE_MARGIN; |
250 | result.Center := true; |
250 | result.Center := true; |
251 | result.Transparent := true; |
251 | result.Transparent := true; |
252 | 252 | ||
253 | result.Tag := panel.Tag; |
253 | result.Tag := panel.Tag; |
254 | result.OnDragOver := panel.OnDragOver; |
254 | result.OnDragOver := panel.OnDragOver; |
255 | result.OnDragDrop := panel.OnDragDrop; |
255 | result.OnDragDrop := panel.OnDragDrop; |
256 | 256 | ||
257 | StoneDraggingAllow(result, FieldState(fieldtype) <> fsAvailable); |
257 | StoneDraggingAllow(result, FieldState(fieldtype) <> fsAvailable); |
258 | end; |
258 | end; |
259 | 259 | ||
260 | procedure TMainForm.StoneDraggingAllow(Stone: TImage; Allow: boolean); |
260 | procedure TMainForm.StoneDraggingAllow(Stone: TImage; Allow: boolean); |
261 | begin |
261 | begin |
262 | if Allow then |
262 | if Allow then |
263 | begin |
263 | begin |
264 | Stone.DragMode := dmAutomatic; |
264 | Stone.DragMode := dmAutomatic; |
265 | (Stone.Parent as TPanel).DragMode := dmAutomatic; |
265 | (Stone.Parent as TPanel).DragMode := dmAutomatic; |
266 | end |
266 | end |
267 | else |
267 | else |
268 | begin |
268 | begin |
269 | Stone.DragMode := dmManual; |
269 | Stone.DragMode := dmManual; |
270 | (Stone.Parent as TPanel).DragMode := dmManual; |
270 | (Stone.Parent as TPanel).DragMode := dmManual; |
271 | end; |
271 | end; |
272 | end; |
272 | end; |
273 | 273 | ||
274 | function TMainForm.DrawStoneBox(x, y, tag, halftabs: integer; isGoal: boolean): TPanel; |
274 | function TMainForm.DrawStoneBox(x, y, tag, halftabs: integer; isGoal: boolean): TPanel; |
275 | begin |
275 | begin |
276 | result := TPanel.Create(Playground); |
276 | result := TPanel.Create(Playground); |
277 | result.Parent := Playground; |
277 | result.Parent := Playground; |
278 | if isGoal then |
278 | if isGoal then |
279 | begin |
279 | begin |
280 | result.BevelInner := bvLowered; |
280 | result.BevelInner := bvLowered; |
281 | end; |
281 | end; |
282 | result.Color := Playground.Color; |
282 | result.Color := Playground.Color; |
283 | result.BevelOuter := bvLowered; |
283 | result.BevelOuter := bvLowered; |
284 | result.Width := MET_FIELD_SIZE; |
284 | result.Width := MET_FIELD_SIZE; |
285 | result.Height := MET_FIELD_SIZE; |
285 | result.Height := MET_FIELD_SIZE; |
286 | result.Left := x * (MET_FIELD_SIZE+MET_FIELD_SPACE) + MET_FIELD_SPACE - (halftabs*MET_HALFTAB_SIZE); |
286 | result.Left := x * (MET_FIELD_SIZE+MET_FIELD_SPACE) + MET_FIELD_SPACE - (halftabs*MET_HALFTAB_SIZE); |
287 | result.Top := y * (MET_FIELD_SIZE+MET_FIELD_SPACE) + MET_FIELD_SPACE; |
287 | result.Top := y * (MET_FIELD_SIZE+MET_FIELD_SPACE) + MET_FIELD_SPACE; |
288 | 288 | ||
289 | result.Tag := tag; |
289 | result.Tag := tag; |
290 | result.OnDragOver := StoneDragOver; |
290 | result.OnDragOver := StoneDragOver; |
291 | result.OnDragDrop := StoneDragDrop; |
291 | result.OnDragDrop := StoneDragDrop; |
292 | end; |
292 | end; |
293 | 293 | ||
294 | procedure TMainForm.MExitClick(Sender: TObject); |
294 | procedure TMainForm.MExitClick(Sender: TObject); |
295 | begin |
295 | begin |
296 | Close; |
296 | Close; |
297 | end; |
297 | end; |
298 | 298 | ||
299 | function TMainForm.FieldState(t: TFieldType): TFieldState; |
299 | function TMainForm.FieldState(t: TFieldType): TFieldState; |
300 | begin |
300 | begin |
301 | result := fsError; |
301 | result := fsError; |
302 | case t of |
302 | case t of |
303 | ftLocked: result := fsLocked; |
303 | ftLocked: result := fsLocked; |
304 | ftLockedWithTab: result := fsLocked; |
304 | ftLockedWithTab: result := fsLocked; |
305 | ftEmpty: result := fsAvailable; |
305 | ftEmpty: result := fsAvailable; |
306 | ftGreen: result := fsStone; |
306 | ftGreen: result := fsStone; |
307 | ftYellow: result := fsStone; |
307 | ftYellow: result := fsStone; |
308 | ftRed: result := fsStone; |
308 | ftRed: result := fsStone; |
309 | end; |
309 | end; |
310 | end; |
310 | end; |
311 | 311 | ||
312 | function TMainForm.FieldState(f: TField): TFieldState; |
312 | function TMainForm.FieldState(f: TField): TFieldState; |
313 | begin |
313 | begin |
314 | result := FieldState(f.FieldType); |
314 | result := FieldState(f.FieldType); |
315 | end; |
315 | end; |
316 | 316 | ||
317 | function TMainForm.FieldState(x, y: integer): TFieldState; |
317 | function TMainForm.FieldState(x, y: integer): TFieldState; |
318 | begin |
318 | begin |
319 | result := fsError; |
319 | result := fsError; |
320 | if (x < Low(PlayGroundMatrix)) or (x > High(PlayGroundMatrix)) then exit; |
320 | if (x < Low(PlayGroundMatrix)) or (x > High(PlayGroundMatrix)) then exit; |
321 | if (y < Low(PlayGroundMatrix[x])) or (y > High(PlayGroundMatrix[x])) then exit; |
321 | if (y < Low(PlayGroundMatrix[x])) or (y > High(PlayGroundMatrix[x])) then exit; |
322 | 322 | ||
323 | result := FieldState(PlayGroundMatrix[x][y]); |
323 | result := FieldState(PlayGroundMatrix[x][y]); |
324 | end; |
324 | end; |
325 | 325 | ||
326 | procedure TMainForm.RefreshTime; |
326 | procedure TMainForm.RefreshTime; |
327 | begin |
327 | begin |
328 | Statistics.Panels.Items[0].Text := Format(LNG_TIME, [LevelTime]); |
328 | Statistics.Panels.Items[0].Text := Format(LNG_TIME, [LevelTime]); |
329 | end; |
329 | end; |
330 | 330 | ||
331 | procedure TMainForm.RefreshStonesRemoved; |
331 | procedure TMainForm.RefreshStonesRemoved; |
332 | begin |
332 | begin |
333 | Statistics.Panels.Items[1].Text := Format(LNG_STONES_REMOVED, [LevelRemovedStones, LevelTotalStones]); |
333 | Statistics.Panels.Items[1].Text := Format(LNG_STONES_REMOVED, [LevelRemovedStones, LevelTotalStones]); |
334 | end; |
334 | end; |
335 | 335 | ||
336 | procedure TMainForm.RefreshPoints; |
336 | procedure TMainForm.RefreshPoints; |
337 | begin |
337 | begin |
338 | Statistics.Panels.Items[2].Text := Format(LNG_POINTS, [Points]); |
338 | Statistics.Panels.Items[2].Text := Format(LNG_POINTS, [Points]); |
339 | end; |
339 | end; |
340 | 340 | ||
341 | procedure TMainForm.CountPoints(t: TFieldType); |
341 | procedure TMainForm.CountPoints(t: TFieldType); |
342 | begin |
342 | begin |
343 | inc(Points, FieldTypeWorth(t)); |
343 | inc(Points, FieldTypeWorth(t)); |
344 | RefreshPoints; |
344 | RefreshPoints; |
345 | end; |
345 | end; |
346 | 346 | ||
347 | procedure TMainForm.RemoveStone(x, y: integer; count_points: boolean); |
347 | procedure TMainForm.RemoveStone(x, y: integer; count_points: boolean); |
348 | begin |
348 | begin |
349 | if count_points then |
349 | if count_points then |
350 | begin |
350 | begin |
351 | CountPoints(PlayGroundMatrix[x, y].FieldType); |
351 | CountPoints(PlayGroundMatrix[x, y].FieldType); |
352 | Inc(LevelRemovedStones); |
352 | Inc(LevelRemovedStones); |
353 | RefreshStonesRemoved; |
353 | RefreshStonesRemoved; |
354 | end; |
354 | end; |
355 | PlayGroundMatrix[x, y].FieldType := ftEmpty; |
355 | PlayGroundMatrix[x, y].FieldType := ftEmpty; |
356 | LoadPictureForType(PlayGroundMatrix[x, y].FieldType, PlayGroundMatrix[x, y].Stone.Picture); |
356 | LoadPictureForType(PlayGroundMatrix[x, y].FieldType, PlayGroundMatrix[x, y].Stone.Picture); |
357 | StoneDraggingAllow(PlayGroundMatrix[x, y].Stone, false); |
357 | StoneDraggingAllow(PlayGroundMatrix[x, y].Stone, false); |
358 | end; |
358 | end; |
359 | 359 | ||
360 | function TMainForm.CanJump(x, y: integer): boolean; |
360 | function TMainForm.CanJump(x, y: integer): boolean; |
361 | begin |
361 | begin |
362 | if FieldState(x, y) <> fsStone then |
362 | if FieldState(x, y) <> fsStone then |
363 | begin |
363 | begin |
364 | result := false; |
364 | result := false; |
365 | exit; |
365 | exit; |
366 | end; |
366 | end; |
367 | 367 | ||
368 | result := true; |
368 | result := true; |
369 | 369 | ||
370 | if MayJump(x, y, x+2, y) then exit; |
370 | if MayJump(x, y, x+2, y) then exit; |
371 | if MayJump(x, y, x-2, y) then exit; |
371 | if MayJump(x, y, x-2, y) then exit; |
372 | if MayJump(x, y, x, y+2) then exit; |
372 | if MayJump(x, y, x, y+2) then exit; |
373 | if MayJump(x, y, x, y-2) then exit; |
373 | if MayJump(x, y, x, y-2) then exit; |
374 | 374 | ||
375 | if AllowDiagonalMoves then |
375 | if AllowDiagonalMoves then |
376 | begin |
376 | begin |
377 | if MayJump(x, y, x-2, y-2) then exit; |
377 | if MayJump(x, y, x-2, y-2) then exit; |
378 | if MayJump(x, y, x+2, y-2) then exit; |
378 | if MayJump(x, y, x+2, y-2) then exit; |
379 | if MayJump(x, y, x-2, y+2) then exit; |
379 | if MayJump(x, y, x-2, y+2) then exit; |
380 | if MayJump(x, y, x+2, y+2) then exit; |
380 | if MayJump(x, y, x+2, y+2) then exit; |
381 | end; |
381 | end; |
382 | 382 | ||
383 | result := false; |
383 | result := false; |
384 | end; |
384 | end; |
385 | 385 | ||
386 | function TMainForm.AreJumpsPossible: boolean; |
386 | function TMainForm.AreJumpsPossible: boolean; |
387 | var |
387 | var |
388 | i, j: integer; |
388 | i, j: integer; |
389 | begin |
389 | begin |
390 | result := false; |
390 | result := false; |
391 | for i := Low(PlayGroundMatrix) to High(PlayGroundMatrix) do |
391 | for i := Low(PlayGroundMatrix) to High(PlayGroundMatrix) do |
392 | begin |
392 | begin |
393 | for j := Low(PlayGroundMatrix[i]) to High(PlayGroundMatrix[i]) do |
393 | for j := Low(PlayGroundMatrix[i]) to High(PlayGroundMatrix[i]) do |
394 | begin |
394 | begin |
395 | if CanJump(i, j) then |
395 | if CanJump(i, j) then |
396 | begin |
396 | begin |
397 | result := true; |
397 | result := true; |
398 | break; |
398 | break; |
399 | end; |
399 | end; |
400 | if result then break; |
400 | if result then break; |
401 | end; |
401 | end; |
402 | end; |
402 | end; |
403 | end; |
403 | end; |
404 | 404 | ||
405 | procedure TMainForm.DoJump(SourceTag, DestTag: integer); |
405 | procedure TMainForm.DoJump(SourceTag, DestTag: integer); |
406 | var |
406 | var |
407 | d, s: TPoint; |
407 | d, s: TPoint; |
408 | old_fieldtype: TFieldType; |
408 | old_fieldtype: TFieldType; |
409 | res: Integer; |
409 | res: Integer; |
410 | begin |
410 | begin |
411 | if not MayJump(SourceTag, DestTag) then exit; |
411 | if not MayJump(SourceTag, DestTag) then exit; |
412 | 412 | ||
413 | d := LookupFieldCoordinateArray[DestTag]; |
413 | d := LookupFieldCoordinateArray[DestTag]; |
414 | s := LookupFieldCoordinateArray[SourceTag]; |
414 | s := LookupFieldCoordinateArray[SourceTag]; |
415 | 415 | ||
416 | JumpHistory.Add(Format(LNG_JUMP_LOG, [SourceTag+1, s.x+1, s.y+1, DestTag+1, d.x+1, d.y+1])); |
416 | JumpHistory.Add(Format(LNG_JUMP_LOG, [SourceTag+1, s.x+1, s.y+1, DestTag+1, d.x+1, d.y+1])); |
417 | 417 | ||
418 | {$REGION 'Stein entfernen und Punkte vergeben'} |
418 | {$REGION 'Stein entfernen und Punkte vergeben'} |
419 | if AllowDiagonalMoves then |
419 | if AllowDiagonalMoves then |
420 | begin |
420 | begin |
421 | if (s.X-2 = d.X) and (s.Y-2 = d.Y) and (FieldState(s.X-1, s.Y-1) = fsStone) then RemoveStone(s.X-1, s.Y-1, true); |
421 | if (s.X-2 = d.X) and (s.Y-2 = d.Y) and (FieldState(s.X-1, s.Y-1) = fsStone) then RemoveStone(s.X-1, s.Y-1, true); |
422 | if (s.X-2 = d.X) and (s.Y+2 = d.Y) and (FieldState(s.X-1, s.Y+1) = fsStone) then RemoveStone(s.X-1, s.Y+1, true); |
422 | if (s.X-2 = d.X) and (s.Y+2 = d.Y) and (FieldState(s.X-1, s.Y+1) = fsStone) then RemoveStone(s.X-1, s.Y+1, true); |
423 | if (s.X+2 = d.X) and (s.Y-2 = d.Y) and (FieldState(s.X+1, s.Y-1) = fsStone) then RemoveStone(s.X+1, s.Y-1, true); |
423 | if (s.X+2 = d.X) and (s.Y-2 = d.Y) and (FieldState(s.X+1, s.Y-1) = fsStone) then RemoveStone(s.X+1, s.Y-1, true); |
424 | if (s.X+2 = d.X) and (s.Y+2 = d.Y) and (FieldState(s.X+1, s.Y+1) = fsStone) then RemoveStone(s.X+1, s.Y+1, true); |
424 | if (s.X+2 = d.X) and (s.Y+2 = d.Y) and (FieldState(s.X+1, s.Y+1) = fsStone) then RemoveStone(s.X+1, s.Y+1, true); |
425 | end; |
425 | end; |
426 | 426 | ||
427 | if (s.X+2 = d.X) and (s.Y = d.Y) and (FieldState(s.X+1, s.Y ) = fsStone) then RemoveStone(s.X+1, s.Y, true); |
427 | if (s.X+2 = d.X) and (s.Y = d.Y) and (FieldState(s.X+1, s.Y ) = fsStone) then RemoveStone(s.X+1, s.Y, true); |
428 | if (s.X-2 = d.X) and (s.Y = d.Y) and (FieldState(s.X-1, s.Y ) = fsStone) then RemoveStone(s.X-1, s.Y, true); |
428 | if (s.X-2 = d.X) and (s.Y = d.Y) and (FieldState(s.X-1, s.Y ) = fsStone) then RemoveStone(s.X-1, s.Y, true); |
429 | if (s.X = d.X) and (s.Y+2 = d.Y) and (FieldState(s.X , s.Y+1) = fsStone) then RemoveStone(s.X, s.Y+1, true); |
429 | if (s.X = d.X) and (s.Y+2 = d.Y) and (FieldState(s.X , s.Y+1) = fsStone) then RemoveStone(s.X, s.Y+1, true); |
430 | if (s.X = d.X) and (s.Y-2 = d.Y) and (FieldState(s.X , s.Y-1) = fsStone) then RemoveStone(s.X, s.Y-1, true); |
430 | if (s.X = d.X) and (s.Y-2 = d.Y) and (FieldState(s.X , s.Y-1) = fsStone) then RemoveStone(s.X, s.Y-1, true); |
431 | {$ENDREGION} |
431 | {$ENDREGION} |
432 | 432 | ||
433 | // Den Timer erst nach dem ersten Zug starten |
433 | // Den Timer erst nach dem ersten Zug starten |
434 | // oder nach einer Pause neustarten |
434 | // oder nach einer Pause neustarten |
435 | if not Timer.Enabled then |
435 | if not Timer.Enabled then |
436 | begin |
436 | begin |
437 | MPauseTime.Enabled := true; |
437 | MPauseTime.Enabled := true; |
438 | Timer.Enabled := true; |
438 | Timer.Enabled := true; |
439 | end; |
439 | end; |
440 | 440 | ||
441 | MRestartGame.Enabled := true; |
441 | MRestartGame.Enabled := true; |
442 | 442 | ||
443 | // Sound abspielen |
443 | // Sound abspielen |
444 | if MEnableSound.Checked then PlaySound(RES_JUMP, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE); |
444 | if MEnableSound.Checked then PlaySound(RES_JUMP, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE); |
445 | 445 | ||
446 | {$REGION 'Nun den Stein springen lassen'} |
446 | {$REGION 'Nun den Stein springen lassen'} |
447 | old_fieldtype := PlayGroundMatrix[s.X, s.Y].FieldType; // Steinfarbe merken |
447 | old_fieldtype := PlayGroundMatrix[s.X, s.Y].FieldType; // Steinfarbe merken |
448 | RemoveStone(s.X, s.Y, false); // Eigenen Stein entfernen. Keine Punkte zählen, da das unser eigener Stein ist, der springt |
448 | RemoveStone(s.X, s.Y, false); // Eigenen Stein entfernen. Keine Punkte zählen, da das unser eigener Stein ist, der springt |
449 | PlayGroundMatrix[d.X, d.Y].FieldType := old_fieldtype; // Farbe wiederherstellen |
449 | PlayGroundMatrix[d.X, d.Y].FieldType := old_fieldtype; // Farbe wiederherstellen |
450 | LoadPictureForType(PlayGroundMatrix[d.X, d.Y].FieldType, PlayGroundMatrix[d.X, d.Y].Stone.Picture); // Stein an neue Position malen |
450 | LoadPictureForType(PlayGroundMatrix[d.X, d.Y].FieldType, PlayGroundMatrix[d.X, d.Y].Stone.Picture); // Stein an neue Position malen |
451 | StoneDraggingAllow(PlayGroundMatrix[d.X, d.Y].Stone, true); // Und die Drag-Eigenschaft erneuern |
451 | StoneDraggingAllow(PlayGroundMatrix[d.X, d.Y].Stone, true); // Und die Drag-Eigenschaft erneuern |
452 | {$ENDREGION} |
452 | {$ENDREGION} |
453 | 453 | ||
454 | {$REGION 'Sind weitere Sprünge möglich oder ist das Spiel vorbei?'} |
454 | {$REGION 'Sind weitere Sprünge möglich oder ist das Spiel vorbei?'} |
455 | if not AreJumpsPossible then |
455 | if not AreJumpsPossible then |
456 | begin |
456 | begin |
457 | MPauseTime.Enabled := false; |
457 | MPauseTime.Enabled := false; |
458 | Timer.Enabled := false; |
458 | Timer.Enabled := false; |
459 | RefreshTime; |
459 | RefreshTime; |
460 | if MEnableSound.Checked then |
460 | if MEnableSound.Checked then |
461 | begin |
461 | begin |
462 | if LevelRemovedStones = LevelTotalStones-1 then |
462 | if LevelRemovedStones = LevelTotalStones-1 then |
463 | begin |
463 | begin |
464 | if GoalStatus in [gsLastStoneInGoalRed, gsLastStoneInGoalYellow, gsLastStoneInGoalGreen] then |
464 | if GoalStatus in [gsLastStoneInGoalRed, gsLastStoneInGoalYellow, gsLastStoneInGoalGreen] then |
465 | PlaySound(RES_WIN2, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE) |
465 | PlaySound(RES_WIN2, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE) |
466 | else |
466 | else |
467 | PlaySound(RES_WIN1, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE) |
467 | PlaySound(RES_WIN1, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE) |
468 | end |
468 | end |
469 | else |
469 | else |
470 | PlaySound(RES_LOSE, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE); |
470 | PlaySound(RES_LOSE, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE); |
471 | end; |
471 | end; |
472 | res := FinishForm.Execute(ExtractFileNameWithoutExt(LevelFile), Points, LevelTotalStones, LevelRemovedStones, CountedSeconds, GoalStatus, JumpHistory); |
472 | res := FinishForm.Execute(ExtractFileNameWithoutExt(LevelFile), Points, LevelTotalStones, LevelRemovedStones, CountedSeconds, GoalStatus, JumpHistory); |
473 | if (res = mrOK) and FinishForm.ReplayCheckbox.Checked then RestartLevel; |
473 | if (res = mrOK) and FinishForm.ReplayCheckbox.Checked then RestartLevel; |
474 | end; |
474 | end; |
475 | {$ENDREGION} |
475 | {$ENDREGION} |
476 | 476 | ||
477 | SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)+1); |
477 | SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)+1); |
478 | PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1] := CloneMatrix(PlaygroundMatrix); |
478 | PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1] := CloneMatrix(PlaygroundMatrix); |
479 | MUndo.Enabled := true; |
479 | MUndo.Enabled := true; |
480 | end; |
480 | end; |
481 | 481 | ||
482 | function TMainForm.MayJump(SourceX, SourceY, DestX, DestY: integer): boolean; |
482 | function TMainForm.MayJump(SourceX, SourceY, DestX, DestY: integer): boolean; |
483 | begin |
483 | begin |
484 | result := false; |
484 | result := false; |
485 | 485 | ||
486 | // Check 1: Ist das Zielfeld überhaupt leer? |
486 | // Check 1: Ist das Zielfeld überhaupt leer? |
487 | if FieldState(DestX, DestY) <> fsAvailable then exit; |
487 | if FieldState(DestX, DestY) <> fsAvailable then exit; |
488 | 488 | ||
489 | // Check 2: Befindet sich ein Stein zwischen Source und Destination und ist der Abstand 2? |
489 | // Check 2: Befindet sich ein Stein zwischen Source und Destination und ist der Abstand 2? |
490 | if AllowDiagonalMoves then |
490 | if AllowDiagonalMoves then |
491 | begin |
491 | begin |
492 | if (SourceX-2 = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX-1, SourceY-1) = fsStone) then result := true; |
492 | if (SourceX-2 = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX-1, SourceY-1) = fsStone) then result := true; |
493 | if (SourceX-2 = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX-1, SourceY+1) = fsStone) then result := true; |
493 | if (SourceX-2 = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX-1, SourceY+1) = fsStone) then result := true; |
494 | if (SourceX+2 = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX+1, SourceY-1) = fsStone) then result := true; |
494 | if (SourceX+2 = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX+1, SourceY-1) = fsStone) then result := true; |
495 | if (SourceX+2 = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX+1, SourceY+1) = fsStone) then result := true; |
495 | if (SourceX+2 = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX+1, SourceY+1) = fsStone) then result := true; |
496 | end; |
496 | end; |
497 | 497 | ||
498 | if (SourceX+2 = DestX) and (SourceY = DestY) and (FieldState(SourceX+1, SourceY ) = fsStone) then result := true; |
498 | if (SourceX+2 = DestX) and (SourceY = DestY) and (FieldState(SourceX+1, SourceY ) = fsStone) then result := true; |
499 | if (SourceX-2 = DestX) and (SourceY = DestY) and (FieldState(SourceX-1, SourceY ) = fsStone) then result := true; |
499 | if (SourceX-2 = DestX) and (SourceY = DestY) and (FieldState(SourceX-1, SourceY ) = fsStone) then result := true; |
500 | if (SourceX = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX , SourceY+1) = fsStone) then result := true; |
500 | if (SourceX = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX , SourceY+1) = fsStone) then result := true; |
501 | if (SourceX = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX , SourceY-1) = fsStone) then result := true; |
501 | if (SourceX = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX , SourceY-1) = fsStone) then result := true; |
502 | end; |
502 | end; |
503 | 503 | ||
504 | function TMainForm.MayJump(SourceTag, DestTag: integer): boolean; |
504 | function TMainForm.MayJump(SourceTag, DestTag: integer): boolean; |
505 | var |
505 | var |
506 | s, d: TPoint; |
506 | s, d: TPoint; |
507 | begin |
507 | begin |
508 | d := LookupFieldCoordinateArray[DestTag]; |
508 | d := LookupFieldCoordinateArray[DestTag]; |
509 | s := LookupFieldCoordinateArray[SourceTag]; |
509 | s := LookupFieldCoordinateArray[SourceTag]; |
510 | 510 | ||
511 | result := MayJump(s.X, s.Y, d.X, d.Y); |
511 | result := MayJump(s.X, s.Y, d.X, d.Y); |
512 | end; |
512 | end; |
513 | 513 | ||
514 | procedure TMainForm.StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
514 | procedure TMainForm.StoneDragDrop(Sender, Source: TObject; X, Y: Integer); |
515 | begin |
515 | begin |
516 | DoJump(TComponent(Source).Tag, TComponent(Sender).Tag); |
516 | DoJump(TComponent(Source).Tag, TComponent(Sender).Tag); |
517 | end; |
517 | end; |
518 | 518 | ||
519 | procedure TMainForm.StoneDragOver(Sender, Source: TObject; X, |
519 | procedure TMainForm.StoneDragOver(Sender, Source: TObject; X, |
520 | Y: Integer; State: TDragState; var Accept: Boolean); |
520 | Y: Integer; State: TDragState; var Accept: Boolean); |
521 | begin |
521 | begin |
522 | Accept := MayJump(TComponent(Source).Tag, TComponent(Sender).Tag); |
522 | Accept := MayJump(TComponent(Source).Tag, TComponent(Sender).Tag); |
523 | end; |
523 | end; |
524 | 524 | ||
525 | procedure TMainForm.DrawField(x, y: integer; t: TFieldProperties; halftabs: integer); |
525 | procedure TMainForm.DrawField(x, y: integer; t: TFieldProperties; halftabs: integer); |
526 | var |
526 | var |
527 | newField: TField; |
527 | newField: TField; |
528 | index: integer; |
528 | index: integer; |
529 | begin |
529 | begin |
530 | if (t.Typ = ftLocked) or (t.Typ = ftLockedWithTab) then exit; |
530 | if (t.Typ = ftLocked) or (t.Typ = ftLockedWithTab) then exit; |
531 | 531 | ||
532 | index := Length(LookupFieldCoordinateArray); |
532 | index := Length(LookupFieldCoordinateArray); |
533 | 533 | ||
534 | newField.FieldType := t.Typ; |
534 | newField.FieldType := t.Typ; |
535 | newField.Goal := t.Goal; |
535 | newField.Goal := t.Goal; |
536 | newField.Panel := DrawStoneBox(x, y, index, halftabs, t.Goal); |
536 | newField.Panel := DrawStoneBox(x, y, index, halftabs, t.Goal); |
537 | newField.Stone := DrawStone(t.Typ, newField.Panel); |
537 | newField.Stone := DrawStone(t.Typ, newField.Panel); |
538 | if FieldState(t.Typ) = fsStone then Inc(LevelTotalStones); |
538 | if FieldState(t.Typ) = fsStone then Inc(LevelTotalStones); |
539 | 539 | ||
540 | SetLength(LookupFieldCoordinateArray, index + 1); |
540 | SetLength(LookupFieldCoordinateArray, index + 1); |
541 | LookupFieldCoordinateArray[index].X := x; |
541 | LookupFieldCoordinateArray[index].X := x; |
542 | LookupFieldCoordinateArray[index].Y := y; |
542 | LookupFieldCoordinateArray[index].Y := y; |
543 | 543 | ||
544 | if Length(PlayGroundMatrix) < x+1 then SetLength(PlayGroundMatrix, x+1); |
544 | if Length(PlayGroundMatrix) < x+1 then SetLength(PlayGroundMatrix, x+1); |
545 | if Length(PlayGroundMatrix[x]) < y+1 then SetLength(PlayGroundMatrix[x], y+1); |
545 | if Length(PlayGroundMatrix[x]) < y+1 then SetLength(PlayGroundMatrix[x], y+1); |
546 | PlaygroundMatrix[x, y] := newField; |
546 | PlaygroundMatrix[x, y] := newField; |
547 | end; |
547 | end; |
548 | 548 | ||
549 | function TMainForm.CloneMatrix(Source: TPlayGroundMatrix): TPlayGroundMatrix; |
549 | function TMainForm.CloneMatrix(Source: TPlayGroundMatrix): TPlayGroundMatrix; |
550 | var |
550 | var |
551 | i, j: integer; |
551 | i, j: integer; |
552 | begin |
552 | begin |
553 | SetLength(result, Length(Source)); |
553 | SetLength(result, Length(Source)); |
554 | for i := Low(Source) to High(Source) do |
554 | for i := Low(Source) to High(Source) do |
555 | begin |
555 | begin |
556 | SetLength(result[i], Length(Source[i])); |
556 | SetLength(result[i], Length(Source[i])); |
557 | for j := Low(Source[i]) to High(Source[i]) do |
557 | for j := Low(Source[i]) to High(Source[i]) do |
558 | begin |
558 | begin |
559 | result[i][j].FieldType := Source[i][j].FieldType; |
559 | result[i][j].FieldType := Source[i][j].FieldType; |
560 | result[i][j].Goal := Source[i][j].Goal; |
560 | result[i][j].Goal := Source[i][j].Goal; |
561 | result[i][j].Panel := Source[i][j].Panel; |
561 | result[i][j].Panel := Source[i][j].Panel; |
562 | result[i][j].Stone := Source[i][j].Stone; |
562 | result[i][j].Stone := Source[i][j].Stone; |
563 | end; |
563 | end; |
564 | end; |
564 | end; |
565 | end; |
565 | end; |
566 | 566 | ||
567 | procedure TMainForm.BuildPlayground(LevelArray: TLevelArray); |
567 | procedure TMainForm.BuildPlayground(LevelArray: TLevelArray); |
568 | var |
568 | var |
569 | i, j, halftabs, cur_x: integer; |
569 | i, j, halftabs, cur_x: integer; |
570 | max_x, max_y, old_cw, old_ch: integer; |
570 | max_x, max_y, old_cw, old_ch: integer; |
571 | begin |
571 | begin |
572 | PlayGround.Visible := false; |
572 | PlayGround.Visible := false; |
573 | 573 | ||
574 | // Die Dimensionen ermitteln |
574 | // Die Dimensionen ermitteln |
575 | max_x := 0; |
575 | max_x := 0; |
576 | for i := Low(LevelArray) to High(LevelArray) do |
576 | for i := Low(LevelArray) to High(LevelArray) do |
577 | begin |
577 | begin |
578 | halftabs := 0; |
578 | halftabs := 0; |
579 | for j := Low(LevelArray[i]) to High(LevelArray[i]) do |
579 | for j := Low(LevelArray[i]) to High(LevelArray[i]) do |
580 | begin |
580 | begin |
581 | if LevelArray[i][j].Typ = ftLockedWithTab then inc(halftabs); |
581 | if LevelArray[i][j].Typ = ftLockedWithTab then inc(halftabs); |
582 | DrawField(j, i, LevelArray[i][j], halftabs); |
582 | DrawField(j, i, LevelArray[i][j], halftabs); |
583 | end; |
583 | end; |
584 | cur_x := High(LevelArray[i]) + 1; |
584 | cur_x := High(LevelArray[i]) + 1; |
585 | if cur_x > max_x then max_x := cur_x; |
585 | if cur_x > max_x then max_x := cur_x; |
586 | end; |
586 | end; |
587 | max_y := High(LevelArray) + 1; |
587 | max_y := High(LevelArray) + 1; |
588 | 588 | ||
589 | PlayGround.Visible := true; |
589 | PlayGround.Visible := true; |
590 | 590 | ||
591 | // Die aktuellen Dimensionen merken |
591 | // Die aktuellen Dimensionen merken |
592 | old_cw := ClientWidth; |
592 | old_cw := ClientWidth; |
593 | old_ch := ClientHeight; |
593 | old_ch := ClientHeight; |
594 | 594 | ||
595 | // Das Form an das Level anpassen |
595 | // Das Form an das Level anpassen |
596 | PlayGround.Width := MET_FIELD_SPACE + max_x * (MET_FIELD_SPACE + MET_FIELD_SIZE); |
596 | PlayGround.Width := MET_FIELD_SPACE + max_x * (MET_FIELD_SPACE + MET_FIELD_SIZE); |
597 | PlayGround.Height := MET_FIELD_SPACE + max_y * (MET_FIELD_SPACE + MET_FIELD_SIZE); |
597 | PlayGround.Height := MET_FIELD_SPACE + max_y * (MET_FIELD_SPACE + MET_FIELD_SIZE); |
598 | ClientWidth := 2 * MET_OUTER_MARGIN + PlayGround.Width; |
598 | ClientWidth := 2 * MET_OUTER_MARGIN + PlayGround.Width; |
599 | ClientHeight := 2 * MET_OUTER_MARGIN + PlayGround.Height + Statistics.Height; |
599 | ClientHeight := 2 * MET_OUTER_MARGIN + PlayGround.Height + Statistics.Height; |
600 | 600 | ||
601 | Statistics.Panels.Items[0].Width := Round(ClientWidth*MET_PERCENT_PNL_TIME); |
601 | Statistics.Panels.Items[0].Width := Round(ClientWidth*MET_PERCENT_PNL_TIME); |
602 | Statistics.Panels.Items[1].Width := Round(ClientWidth*MET_PERCENT_PNL_STONES); |
602 | Statistics.Panels.Items[1].Width := Round(ClientWidth*MET_PERCENT_PNL_STONES); |
603 | 603 | ||
604 | // Wenn sich das Form vergrößert oder verkleinert hat, neu justieren |
604 | // Wenn sich das Form vergrößert oder verkleinert hat, neu justieren |
605 | if (old_cw <> ClientWidth) or (old_ch <> ClientHeight) then |
605 | if (old_cw <> ClientWidth) or (old_ch <> ClientHeight) then |
606 | begin |
606 | begin |
607 | Left := Screen.Width div 2 - Width div 2; |
607 | Left := Screen.Width div 2 - Width div 2; |
608 | Top := Screen.Height div 2 - Height div 2; |
608 | Top := Screen.Height div 2 - Height div 2; |
609 | 609 | ||
610 | // Playground mittig setzen, falls die Mindestgröße für die |
610 | // Playground mittig setzen, falls die Mindestgröße für die |
611 | // Punkteanzeige unterschritten wurde, |
611 | // Punkteanzeige unterschritten wurde, |
612 | PlayGround.Left := ClientWidth div 2 - PlayGround.Width div 2; |
612 | PlayGround.Left := ClientWidth div 2 - PlayGround.Width div 2; |
613 | PlayGround.Top := ClientHeight div 2 - PlayGround.Height div 2; |
613 | PlayGround.Top := ClientHeight div 2 - PlayGround.Height div 2; |
614 | end; |
614 | end; |
615 | 615 | ||
616 | OriginalPlayGroundMatrix := CloneMatrix(PlayGroundMatrix); |
616 | OriginalPlayGroundMatrix := CloneMatrix(PlayGroundMatrix); |
617 | SetLength(PrevPlaygroundMatrixes,1); |
617 | SetLength(PrevPlaygroundMatrixes,1); |
618 | PrevPlaygroundMatrixes[0] := CloneMatrix(PlayGroundMatrix); |
618 | PrevPlaygroundMatrixes[0] := CloneMatrix(PlayGroundMatrix); |
619 | MUndo.Enabled := false; |
619 | MUndo.Enabled := false; |
620 | end; |
620 | end; |
621 | 621 | ||
622 | procedure TMainForm.TimerTimer(Sender: TObject); |
622 | procedure TMainForm.TimerTimer(Sender: TObject); |
623 | begin |
623 | begin |
624 | if mainform.Focused then Inc(CountedSeconds); |
624 | if mainform.Focused then Inc(CountedSeconds); |
625 | RefreshTime; |
625 | RefreshTime; |
626 | end; |
626 | end; |
627 | 627 | ||
628 | function TMainForm.LevelTime: String; |
628 | function TMainForm.LevelTime: String; |
629 | begin |
629 | begin |
630 | result := SecondsToTimeString(CountedSeconds); |
630 | result := SecondsToTimeString(CountedSeconds); |
631 | end; |
631 | end; |
632 | 632 | ||
633 | procedure TMainForm.NewGame(Filename: string); |
633 | procedure TMainForm.NewGame(Filename: string); |
634 | var |
634 | var |
635 | LevelString: String; |
635 | LevelString: String; |
636 | LevelArray: TLevelArray; |
636 | LevelArray: TLevelArray; |
637 | begin |
637 | begin |
638 | DestroyLevel; |
638 | DestroyLevel; |
639 | LevelFile := Filename; |
639 | LevelFile := Filename; |
640 | LevelString := ReadFile(LevelFile); |
640 | LevelString := ReadFile(LevelFile); |
641 | LevelArray := LevelStringToLevelArray(LevelString, true); |
641 | LevelArray := LevelStringToLevelArray(LevelString, true); |
642 | if Length(LevelArray) = 0 then Exit; |
642 | if Length(LevelArray) = 0 then Exit; |
643 | BuildPlayground(LevelArray); |
643 | BuildPlayground(LevelArray); |
644 | if not AreJumpsPossible then |
644 | if not AreJumpsPossible then |
645 | begin |
645 | begin |
646 | ShowMessage(LNG_LVL_INVALID_NO_JUMP); |
646 | MessageDlg(LNG_LVL_INVALID_NO_JUMP, mtError, [mbOk], 0); |
647 | end; |
647 | end; |
648 | RefreshTime; |
648 | RefreshTime; |
649 | RefreshStonesRemoved; |
649 | RefreshStonesRemoved; |
650 | RefreshPoints; |
650 | RefreshPoints; |
651 | end; |
651 | end; |
652 | 652 | ||
653 | procedure TMainForm.MNewGameClick(Sender: TObject); |
653 | procedure TMainForm.MNewGameClick(Sender: TObject); |
654 | begin |
654 | begin |
655 | LevelFile := AskForLevel; |
655 | LevelFile := AskForLevel; |
656 | if LevelFile <> '' then |
656 | if LevelFile <> '' then |
657 | begin |
657 | begin |
658 | NewGame(LevelFile); |
658 | NewGame(LevelFile); |
659 | end; |
659 | end; |
660 | end; |
660 | end; |
661 | 661 | ||
662 | procedure TMainForm.MAboutClick(Sender: TObject); |
662 | procedure TMainForm.MAboutClick(Sender: TObject); |
663 | begin |
663 | begin |
664 | AboutBox.ShowModal; |
664 | AboutBox.ShowModal; |
665 | end; |
665 | end; |
666 | 666 | ||
667 | function TMainForm.AskForLevel: String; |
667 | function TMainForm.AskForLevel: String; |
668 | begin |
668 | begin |
669 | LevelChoice.ShowModal; |
669 | LevelChoice.ShowModal; |
670 | 670 | ||
671 | if LevelChoice.ModalResult <> mrOK then |
671 | if LevelChoice.ModalResult <> mrOK then |
672 | begin |
672 | begin |
673 | result := ''; |
673 | result := ''; |
674 | exit; |
674 | exit; |
675 | end; |
675 | end; |
676 | 676 | ||
677 | result := LevelChoice.SelectedLevel; |
677 | result := LevelChoice.SelectedLevel; |
678 | end; |
678 | end; |
679 | 679 | ||
680 | procedure TMainForm.FormShow(Sender: TObject); |
680 | procedure TMainForm.FormShow(Sender: TObject); |
681 | begin |
681 | begin |
682 | LevelFile := AskForLevel; |
682 | LevelFile := AskForLevel; |
683 | if LevelFile <> '' then |
683 | if LevelFile <> '' then |
684 | begin |
684 | begin |
685 | NewGame(LevelFile); |
685 | NewGame(LevelFile); |
686 | end |
686 | end |
687 | else Close(); |
687 | else Close(); |
688 | end; |
688 | end; |
689 | 689 | ||
690 | function TMainForm.GoalStatus: TGoalStatus; |
690 | function TMainForm.GoalStatus: TGoalStatus; |
691 | var |
691 | var |
692 | ft: TFieldType; |
692 | ft: TFieldType; |
693 | begin |
693 | begin |
694 | if not MatrixHasGoal(PlaygroundMatrix) then |
694 | if not MatrixHasGoal(PlaygroundMatrix) then |
695 | result := gsNoGoal |
695 | result := gsNoGoal |
696 | else if LevelRemovedStones < LevelTotalStones-1 then |
696 | else if LevelRemovedStones < LevelTotalStones-1 then |
697 | Result := gsMultipleStonesRemaining |
697 | Result := gsMultipleStonesRemaining |
698 | else |
698 | else |
699 | begin |
699 | begin |
700 | ft := GoalFieldType(PlaygroundMatrix); |
700 | ft := GoalFieldType(PlaygroundMatrix); |
701 | if ft = ftRed then |
701 | if ft = ftRed then |
702 | result := gsLastStoneInGoalRed |
702 | result := gsLastStoneInGoalRed |
703 | else if ft = ftYellow then |
703 | else if ft = ftYellow then |
704 | result := gsLastStoneInGoalYellow |
704 | result := gsLastStoneInGoalYellow |
705 | else if ft = ftGreen then |
705 | else if ft = ftGreen then |
706 | result := gsLastStoneInGoalGreen; |
706 | result := gsLastStoneInGoalGreen; |
707 | end; |
707 | end; |
708 | end; |
708 | end; |
709 | 709 | ||
710 | procedure TMainForm.FormCreate(Sender: TObject); |
710 | procedure TMainForm.FormCreate(Sender: TObject); |
711 | begin |
711 | begin |
712 | JumpHistory := TStringList.Create; |
712 | JumpHistory := TStringList.Create; |
713 | LoadSettings; |
713 | LoadSettings; |
714 | end; |
714 | end; |
715 | 715 | ||
716 | procedure TMainForm.FormDestroy(Sender: TObject); |
716 | procedure TMainForm.FormDestroy(Sender: TObject); |
717 | begin |
717 | begin |
718 | JumpHistory.Free; |
718 | JumpHistory.Free; |
719 | end; |
719 | end; |
720 | 720 | ||
721 | procedure TMainForm.MJumpHistoryClick(Sender: TObject); |
721 | procedure TMainForm.MJumpHistoryClick(Sender: TObject); |
722 | begin |
722 | begin |
723 | HistoryForm.JumpMemo.Lines.Assign(JumpHistory); |
723 | HistoryForm.JumpMemo.Lines.Assign(JumpHistory); |
724 | HistoryForm.ShowModal; |
724 | HistoryForm.ShowModal; |
725 | end; |
725 | end; |
726 | 726 | ||
727 | procedure TMainForm.RestartLevel; |
727 | procedure TMainForm.RestartLevel; |
728 | begin |
728 | begin |
729 | MPauseTime.Enabled := false; |
729 | MPauseTime.Enabled := false; |
730 | Timer.Enabled := false; |
730 | Timer.Enabled := false; |
731 | 731 | ||
732 | MRestartGame.Enabled := false; |
732 | MRestartGame.Enabled := false; |
733 | 733 | ||
734 | CountedSeconds := 0; |
734 | CountedSeconds := 0; |
735 | RefreshTime; |
735 | RefreshTime; |
736 | 736 | ||
737 | Points := 0; |
737 | Points := 0; |
738 | RefreshPoints; |
738 | RefreshPoints; |
739 | 739 | ||
740 | LevelRemovedStones := 0; |
740 | LevelRemovedStones := 0; |
741 | RefreshStonesRemoved; |
741 | RefreshStonesRemoved; |
742 | 742 | ||
743 | JumpHistory.Clear; |
743 | JumpHistory.Clear; |
744 | 744 | ||
745 | RedrawStonesFromMatrix(OriginalPlayGroundMatrix); |
745 | RedrawStonesFromMatrix(OriginalPlayGroundMatrix); |
746 | SetNewPlayGroundMatrix(OriginalPlayGroundMatrix); |
746 | SetNewPlayGroundMatrix(OriginalPlayGroundMatrix); |
747 | SetLength(PrevPlaygroundMatrixes,1); |
747 | SetLength(PrevPlaygroundMatrixes,1); |
748 | PrevPlaygroundMatrixes[0] := CloneMatrix(OriginalPlayGroundMatrix); |
748 | PrevPlaygroundMatrixes[0] := CloneMatrix(OriginalPlayGroundMatrix); |
749 | MUndo.Enabled := false; |
749 | MUndo.Enabled := false; |
750 | end; |
750 | end; |
751 | 751 | ||
752 | procedure TMainForm.SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix); |
752 | procedure TMainForm.SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix); |
753 | begin |
753 | begin |
754 | ClearMatrix(PlayGroundMatrix, false); // Memory Leak verhindern |
754 | ClearMatrix(PlayGroundMatrix, false); // Memory Leak verhindern |
755 | PlayGroundMatrix := CloneMatrix(Matrix); |
755 | PlayGroundMatrix := CloneMatrix(Matrix); |
756 | end; |
756 | end; |
757 | 757 | ||
758 | procedure TMainForm.MRestartGameClick(Sender: TObject); |
758 | procedure TMainForm.MRestartGameClick(Sender: TObject); |
759 | begin |
759 | begin |
760 | RestartLevel; |
760 | RestartLevel; |
761 | end; |
761 | end; |
762 | 762 | ||
763 | procedure TMainForm.MUndoClick(Sender: TObject); |
763 | procedure TMainForm.MUndoClick(Sender: TObject); |
764 | var |
764 | var |
765 | PrevWorth: integer; |
765 | PrevWorth: integer; |
766 | NewWorth: integer; |
766 | NewWorth: integer; |
767 | begin |
767 | begin |
768 | if Length(PrevPlaygroundMatrixes) > 1 then |
768 | if Length(PrevPlaygroundMatrixes) > 1 then |
769 | begin |
769 | begin |
770 | PrevWorth := MatrixWorth(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]); |
770 | PrevWorth := MatrixWorth(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]); |
771 | 771 | ||
772 | ClearMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1], false); |
772 | ClearMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1], false); |
773 | SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)-1); |
773 | SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)-1); |
774 | 774 | ||
775 | NewWorth := MatrixWorth(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]); |
775 | NewWorth := MatrixWorth(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]); |
776 | RedrawStonesFromMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]); |
776 | RedrawStonesFromMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]); |
777 | SetNewPlayGroundMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]); |
777 | SetNewPlayGroundMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]); |
778 | 778 | ||
779 | JumpHistory.Delete(JumpHistory.Count-1); |
779 | JumpHistory.Delete(JumpHistory.Count-1); |
780 | 780 | ||
781 | Dec(LevelRemovedStones); |
781 | Dec(LevelRemovedStones); |
782 | RefreshStonesRemoved; |
782 | RefreshStonesRemoved; |
783 | 783 | ||
784 | Dec(Points, NewWorth-PrevWorth); |
784 | Dec(Points, NewWorth-PrevWorth); |
785 | RefreshPoints; |
785 | RefreshPoints; |
786 | 786 | ||
787 | // Sound abspielen |
787 | // Sound abspielen |
788 | if MEnableSound.Checked then PlaySound(RES_UNDO, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE); |
788 | if MEnableSound.Checked then PlaySound(RES_UNDO, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE); |
789 | end; |
789 | end; |
790 | 790 | ||
791 | MUndo.Enabled := Length(PrevPlaygroundMatrixes) > 1; |
791 | MUndo.Enabled := Length(PrevPlaygroundMatrixes) > 1; |
792 | end; |
792 | end; |
793 | 793 | ||
794 | procedure TMainForm.MHighScoresClick(Sender: TObject); |
794 | procedure TMainForm.MHighScoresClick(Sender: TObject); |
795 | begin |
795 | begin |
796 | HighScoreForm.Execute(ExtractFileNameWithoutExt(LevelFile)); |
796 | HighScoreForm.Execute(ExtractFileNameWithoutExt(LevelFile)); |
797 | end; |
797 | end; |
798 | 798 | ||
799 | procedure TMainForm.MPauseTimeClick(Sender: TObject); |
799 | procedure TMainForm.MPauseTimeClick(Sender: TObject); |
800 | begin |
800 | begin |
801 | MPauseTime.Enabled := false; |
801 | MPauseTime.Enabled := false; |
802 | Timer.Enabled := false; |
802 | Timer.Enabled := false; |
803 | end; |
803 | end; |
804 | 804 | ||
805 | procedure TMainForm.LoadSettings; |
805 | procedure TMainForm.LoadSettings; |
806 | var |
806 | var |
807 | reg: TRegistry; |
807 | reg: TRegistry; |
808 | begin |
808 | begin |
809 | reg := TRegistry.Create; |
809 | reg := TRegistry.Create; |
810 | try |
810 | try |
811 | reg.RootKey := HKEY_CURRENT_USER; |
811 | reg.RootKey := HKEY_CURRENT_USER; |
812 | if reg.OpenKeyReadOnly(REG_KEY) then |
812 | if reg.OpenKeyReadOnly(REG_KEY) then |
813 | begin |
813 | begin |
814 | if reg.ValueExists(REG_SOUND) then |
814 | if reg.ValueExists(REG_SOUND) then |
815 | MEnableSound.Checked := reg.ReadBool(REG_SOUND); |
815 | MEnableSound.Checked := reg.ReadBool(REG_SOUND); |
816 | reg.CloseKey; |
816 | reg.CloseKey; |
817 | end; |
817 | end; |
818 | finally |
818 | finally |
819 | reg.Free; |
819 | reg.Free; |
820 | end; |
820 | end; |
821 | end; |
821 | end; |
822 | 822 | ||
823 | procedure TMainForm.SaveSettings; |
823 | procedure TMainForm.SaveSettings; |
824 | var |
824 | var |
825 | reg: TRegistry; |
825 | reg: TRegistry; |
826 | begin |
826 | begin |
827 | reg := TRegistry.Create; |
827 | reg := TRegistry.Create; |
828 | try |
828 | try |
829 | reg.RootKey := HKEY_CURRENT_USER; |
829 | reg.RootKey := HKEY_CURRENT_USER; |
830 | if reg.OpenKey(REG_KEY, true) then |
830 | if reg.OpenKey(REG_KEY, true) then |
831 | begin |
831 | begin |
832 | reg.WriteBool(REG_SOUND, MEnableSound.Checked); |
832 | reg.WriteBool(REG_SOUND, MEnableSound.Checked); |
833 | reg.CloseKey; |
833 | reg.CloseKey; |
834 | end; |
834 | end; |
835 | finally |
835 | finally |
836 | reg.Free; |
836 | reg.Free; |
837 | end; |
837 | end; |
838 | end; |
838 | end; |
839 | 839 | ||
840 | 840 | ||
841 | procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction); |
841 | procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction); |
842 | begin |
842 | begin |
843 | SaveSettings; |
843 | SaveSettings; |
844 | if FinishForm.NameEdit.Text <> '' then |
844 | if FinishForm.NameEdit.Text <> '' then |
845 | begin |
845 | begin |
846 | FinishForm.SaveSettings; |
846 | FinishForm.SaveSettings; |
847 | end; |
847 | end; |
848 | end; |
848 | end; |
849 | 849 | ||
850 | procedure TMainForm.MHelpClick(Sender: TObject); |
850 | procedure TMainForm.MHelpClick(Sender: TObject); |
851 | begin |
851 | begin |
852 | HelpForm.ShowModal; |
852 | HelpForm.ShowModal; |
853 | end; |
853 | end; |
854 | 854 | ||
855 | procedure TMainForm.MEnableSoundClick(Sender: TObject); |
855 | procedure TMainForm.MEnableSoundClick(Sender: TObject); |
856 | begin |
856 | begin |
857 | MEnableSound.Checked := not MEnableSound.Checked; |
857 | MEnableSound.Checked := not MEnableSound.Checked; |
858 | end; |
858 | end; |
859 | 859 | ||
860 | end. |
860 | end. |
861 | 861 |