Subversion Repositories jumper

Rev

Rev 19 | Rev 22 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19 Rev 21
Line 5... Line 5...
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
-
 
11
    FieldType: TFieldType;
-
 
12
    Goal: Boolean;
-
 
13
    Panel: TPanel;
-
 
14
    Stone: TImage;
-
 
15
  end;
-
 
16
 
-
 
17
  TGoalStatus = (gsUndefined, gsNoGoal, gsMultipleStonesRemaining, gsLastStoneInGoalRed, gsLastStoneInGoalYellow, gsLastStoneInGoalGreen, gsLastStoneOutsideGoal);
-
 
18
 
-
 
19
  TFieldState = (fsUndefined, fsError, fsLocked, fsAvailable, fsStone);
-
 
20
 
-
 
21
  TPlayGroundMatrix = array of array of TField;
-
 
22
 
-
 
23
  TMainForm = class(TForm)
10
  TMainForm = class(TForm)
24
    Playground: TPanel;
11
    Playground: TPanel;
25
    MainMenu: TMainMenu;
12
    MainMenu: TMainMenu;
26
    Help1: TMenuItem;
13
    Help1: TMenuItem;
27
    MExit: TMenuItem;
14
    MExit: TMenuItem;
Line 52... Line 39...
52
    procedure FormCreate(Sender: TObject);
39
    procedure FormCreate(Sender: TObject);
53
    procedure FormDestroy(Sender: TObject);
40
    procedure FormDestroy(Sender: TObject);
54
    procedure MJumpHistoryClick(Sender: TObject);
41
    procedure MJumpHistoryClick(Sender: TObject);
55
    procedure MRestartGameClick(Sender: TObject);
42
    procedure MRestartGameClick(Sender: TObject);
56
    procedure MHighScoresClick(Sender: TObject);
43
    procedure MHighScoresClick(Sender: TObject);
57
    procedure MPauseTimeClick(Sender: TObject);
-
 
58
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
44
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
59
    procedure MHelpClick(Sender: TObject);
45
    procedure MHelpClick(Sender: TObject);
60
    procedure MEnableSoundClick(Sender: TObject);
-
 
61
    procedure MUndoClick(Sender: TObject);
46
    procedure MUndoClick(Sender: TObject);
62
    procedure Aboutthislevel1Click(Sender: TObject);
47
    procedure Aboutthislevel1Click(Sender: TObject);
63
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
48
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
64
  private
49
  private
65
    NoCloseQuery: boolean;
50
    NoCloseQuery: boolean;
Line 97... Line 82...
97
    procedure StoneDragDrop(Sender, Source: TObject; X, Y: Integer);
82
    procedure StoneDragDrop(Sender, Source: TObject; X, Y: Integer);
98
    function DrawField(x, y: integer; t: TFieldProperties; indent: integer): TField;
83
    function DrawField(x, y: integer; t: TFieldProperties; indent: integer): TField;
99
    function DrawStone(fieldtype: TFieldType; panel: TPanel): TImage;
84
    function DrawStone(fieldtype: TFieldType; panel: TPanel): TImage;
100
    function DrawStoneBox(x, y, tag, halftabs: integer; isGoal: boolean): TPanel;
85
    function DrawStoneBox(x, y, tag, halftabs: integer; isGoal: boolean): TPanel;
101
    procedure BuildPlayground(LevelArray: TLevelArray);
86
    procedure BuildPlayground(LevelArray: TLevelArray);
102
    function FieldState(t: TFieldType): TFieldState; overload;
-
 
103
    function FieldState(f: TField): TFieldState; overload;
-
 
104
    function FieldState(x, y: integer): TFieldState; overload;
-
 
105
    procedure ClearMatrix(Matrix: TPlayGroundMatrix; FreeVCL: boolean);
-
 
106
    function CloneMatrix(Source: TPlayGroundMatrix): TPlayGroundMatrix;
-
 
107
    function MatrixHasGoal(Matrix: TPlayGroundMatrix): boolean;
-
 
108
    procedure LoadPictureForType(FieldType: TFieldType; Picture: TPicture);
87
    procedure LoadPictureForType(FieldType: TFieldType; Picture: TPicture);
109
    function MatrixWorth(Matrix: TPlayGroundMatrix): integer;
-
 
110
    function GoalStatus: TGoalStatus;
88
    function GoalStatus: TGoalStatus;
111
    function GoalFieldType(Matrix: TPlayGroundMatrix): TFieldType;
-
 
112
  end;
89
  end;
113
 
90
 
114
var
91
var
115
  MainForm: TMainForm;
92
  MainForm: TMainForm;
116
 
93
 
Line 119... Line 96...
119
uses
96
uses
120
  About, Finish, Choice, Functions, History, HighScore, Help, Constants, Math;
97
  About, Finish, Choice, Functions, History, HighScore, Help, Constants, Math;
121
 
98
 
122
{$R *.dfm}
99
{$R *.dfm}
123
 
100
 
124
function TMainForm.MatrixHasGoal(Matrix: TPlayGroundMatrix): boolean;
-
 
125
var
-
 
126
  i, j: integer;
-
 
127
begin
-
 
128
  result := false;
-
 
129
  for i := Low(Matrix) to High(Matrix) do
-
 
130
  begin
-
 
131
    for j := Low(Matrix[i]) to High(Matrix[i]) do
-
 
132
    begin
-
 
133
      result := result or Matrix[i][j].Goal;
-
 
134
    end;
-
 
135
  end;
-
 
136
end;
-
 
137
 
-
 
138
function TMainForm.GoalFieldType(Matrix: TPlayGroundMatrix): TFieldType;
-
 
139
var
-
 
140
  i, j: integer;
-
 
141
begin
-
 
142
  result := ftEmpty; // Damit der Compiler nicht meckert
-
 
143
  for i := Low(Matrix) to High(Matrix) do
-
 
144
  begin
-
 
145
    for j := Low(Matrix[i]) to High(Matrix[i]) do
-
 
146
    begin
-
 
147
      if Matrix[i][j].Goal then result := Matrix[i][j].FieldType
-
 
148
    end;
-
 
149
  end;
-
 
150
end;
-
 
151
 
-
 
152
function TMainForm.MatrixWorth(Matrix: TPlayGroundMatrix): integer;
-
 
153
var
-
 
154
  i, j: integer;
-
 
155
begin
-
 
156
  result := 0;
101
{ TMainForm }
157
  for i := Low(Matrix) to High(Matrix) do
-
 
158
  begin
-
 
159
    for j := Low(Matrix[i]) to High(Matrix[i]) do
-
 
160
    begin
-
 
161
      Inc(result, FieldTypeWorth(Matrix[i][j].FieldType));
-
 
162
    end;
-
 
163
  end;
-
 
164
end;
-
 
165
 
-
 
166
procedure TMainForm.ClearMatrix(Matrix: TPlayGroundMatrix; FreeVCL: boolean);
-
 
167
var
-
 
168
  i, j: integer;
-
 
169
begin
-
 
170
  for i := Low(Matrix) to High(Matrix) do
-
 
171
  begin
-
 
172
    for j := Low(Matrix[i]) to High(Matrix[i]) do
-
 
173
    begin
-
 
174
      if FreeVCL then
-
 
175
      begin
-
 
176
        if Assigned(Matrix[i][j].Stone) then Matrix[i][j].Stone.Free;
-
 
177
        if Assigned(Matrix[i][j].Panel) then Matrix[i][j].Panel.Free;
-
 
178
      end;
-
 
179
    end;
-
 
180
    SetLength(Matrix[i], 0);
-
 
181
  end;
-
 
182
  SetLength(Matrix, 0);
-
 
183
end;
-
 
184
 
102
 
185
procedure TMainForm.RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix);
103
procedure TMainForm.RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix);
186
var
104
var
187
  i, j: integer;
105
  i, j: integer;
188
begin
106
begin
189
  for i := Low(Matrix) to High(Matrix) do
107
  for i := Low(Matrix.Fields) to High(Matrix.Fields) do
190
  begin
108
  begin
191
    for j := Low(Matrix[i]) to High(Matrix[i]) do
109
    for j := Low(Matrix.Fields[i]) to High(Matrix.Fields[i]) do
192
    begin
110
    begin
193
      if Assigned(Matrix[i][j].Stone) then
111
      if Assigned(Matrix.Fields[i][j].Stone) then
194
      begin
112
      begin
195
        LoadPictureForType(Matrix[i][j].FieldType, Matrix[i][j].Stone.Picture);
113
        LoadPictureForType(Matrix.Fields[i][j].FieldType, Matrix.Fields[i][j].Stone.Picture);
196
        StoneDraggingAllow(Matrix[i][j].Stone, FieldState(Matrix[i][j].FieldType) <> fsAvailable);
114
        StoneDraggingAllow(Matrix.Fields[i][j].Stone, Matrix.FieldState(Matrix.Fields[i][j].FieldType) <> fsAvailable);
197
      end;
115
      end;
198
    end;
116
    end;
199
  end;
117
  end;
200
end;
118
end;
201
 
119
 
202
procedure TMainForm.DestroyLevel;
120
procedure TMainForm.DestroyLevel;
203
var
121
var
204
  i: Integer;
122
  i: Integer;
205
begin
123
begin
-
 
124
  MPauseTime.Checked := false;
206
  MPauseTime.Enabled := false;
125
  MPauseTime.Enabled := false;
207
  Timer.Enabled := false;
126
  Timer.Enabled := false;
208
 
127
 
209
  MRestartGame.Enabled := false;
128
  MRestartGame.Enabled := false;
210
 
129
 
Line 220... Line 139...
220
  LevelTotalStones := 0;
139
  LevelTotalStones := 0;
221
  RefreshStonesRemoved;
140
  RefreshStonesRemoved;
222
 
141
 
223
  JumpHistory.Clear;
142
  JumpHistory.Clear;
224
 
143
 
225
  ClearMatrix(PlayGroundMatrix, true);
144
  PlayGroundMatrix.ClearMatrix(true);
226
  for i := 0 to Length(PrevPlaygroundMatrixes)-1 do
145
  for i := 0 to Length(PrevPlaygroundMatrixes)-1 do
227
    ClearMatrix(PrevPlaygroundMatrixes[i], false);
146
    PrevPlaygroundMatrixes[i].ClearMatrix(false);
228
  SetLength(PrevPlaygroundMatrixes, 0);
147
  SetLength(PrevPlaygroundMatrixes, 0);
229
  MUndo.Enabled := false;
148
  MUndo.Enabled := false;
230
 
149
 
231
  SetLength(LookupFieldCoordinateArray, 0);
150
  SetLength(LookupFieldCoordinateArray, 0);
232
 
151
 
Line 257... Line 176...
257
 
176
 
258
  result.Tag := panel.Tag;
177
  result.Tag := panel.Tag;
259
  result.OnDragOver := panel.OnDragOver;
178
  result.OnDragOver := panel.OnDragOver;
260
  result.OnDragDrop := panel.OnDragDrop;
179
  result.OnDragDrop := panel.OnDragDrop;
261
 
180
 
262
  StoneDraggingAllow(result, FieldState(fieldtype) <> fsAvailable);
181
  StoneDraggingAllow(result, PlayGroundMatrix.FieldState(fieldtype) <> fsAvailable);
263
end;
182
end;
264
 
183
 
265
procedure TMainForm.StoneDraggingAllow(Stone: TImage; Allow: boolean);
184
procedure TMainForm.StoneDraggingAllow(Stone: TImage; Allow: boolean);
266
begin
185
begin
267
  if Allow then
186
  if Allow then
Line 299... Line 218...
299
procedure TMainForm.MExitClick(Sender: TObject);
218
procedure TMainForm.MExitClick(Sender: TObject);
300
begin
219
begin
301
  Close;
220
  Close;
302
end;
221
end;
303
 
222
 
304
function TMainForm.FieldState(t: TFieldType): TFieldState;
-
 
305
begin
-
 
306
  result := fsError;
-
 
307
  case t of
-
 
308
    ftFullSpace:     result := fsLocked;
-
 
309
    ftEmpty:         result := fsAvailable;
-
 
310
    ftGreen:         result := fsStone;
-
 
311
    ftYellow:        result := fsStone;
-
 
312
    ftRed:           result := fsStone;
-
 
313
  end;
-
 
314
end;
-
 
315
 
-
 
316
function TMainForm.FieldState(f: TField): TFieldState;
-
 
317
begin
-
 
318
  result := FieldState(f.FieldType);
-
 
319
end;
-
 
320
 
-
 
321
function TMainForm.FieldState(x, y: integer): TFieldState;
-
 
322
begin
-
 
323
  result := fsError;
-
 
324
  if (x < Low(PlayGroundMatrix)) or (x > High(PlayGroundMatrix)) then exit;
-
 
325
  if (y < Low(PlayGroundMatrix[x])) or (y > High(PlayGroundMatrix[x])) then exit;
-
 
326
 
-
 
327
  result := FieldState(PlayGroundMatrix[x][y]);
-
 
328
end;
-
 
329
 
-
 
330
procedure TMainForm.RefreshTime;
223
procedure TMainForm.RefreshTime;
331
begin
224
begin
332
  Statistics.Panels.Items[0].Text := Format(LNG_TIME, [LevelTime]);
225
  Statistics.Panels.Items[0].Text := Format(LNG_TIME, [LevelTime]);
333
end;
226
end;
334
 
227
 
335
procedure TMainForm.RefreshStonesRemoved;
228
procedure TMainForm.RefreshStonesRemoved;
-
 
229
resourcestring
-
 
230
  LNG_STONES_REMOVED = '%d of %d stones removed';
336
begin
231
begin
337
  Statistics.Panels.Items[1].Text := Format(LNG_STONES_REMOVED, [LevelRemovedStones, LevelTotalStones-1]);
232
  Statistics.Panels.Items[1].Text := Format(LNG_STONES_REMOVED, [LevelRemovedStones, LevelTotalStones-1]);
338
end;
233
end;
339
 
234
 
340
procedure TMainForm.RefreshPoints;
235
procedure TMainForm.RefreshPoints;
Line 350... Line 245...
350
 
245
 
351
procedure TMainForm.RemoveStone(x, y: integer; count_points: boolean);
246
procedure TMainForm.RemoveStone(x, y: integer; count_points: boolean);
352
begin
247
begin
353
  if count_points then
248
  if count_points then
354
  begin
249
  begin
355
    CountPoints(PlayGroundMatrix[x, y].FieldType);
250
    CountPoints(PlayGroundMatrix.Fields[x, y].FieldType);
356
    Inc(LevelRemovedStones);
251
    Inc(LevelRemovedStones);
357
    RefreshStonesRemoved;
252
    RefreshStonesRemoved;
358
  end;
253
  end;
359
  PlayGroundMatrix[x, y].FieldType := ftEmpty;
254
  PlayGroundMatrix.Fields[x, y].FieldType := ftEmpty;
360
  LoadPictureForType(PlayGroundMatrix[x, y].FieldType, PlayGroundMatrix[x, y].Stone.Picture);
255
  LoadPictureForType(PlayGroundMatrix.Fields[x, y].FieldType, PlayGroundMatrix.Fields[x, y].Stone.Picture);
361
  StoneDraggingAllow(PlayGroundMatrix[x, y].Stone, false);
256
  StoneDraggingAllow(PlayGroundMatrix.Fields[x, y].Stone, false);
362
end;
257
end;
363
 
258
 
364
function TMainForm.CanJump(x, y: integer): boolean;
259
function TMainForm.CanJump(x, y: integer): boolean;
365
begin
260
begin
366
  if FieldState(x, y) <> fsStone then
261
  if PlayGroundMatrix.FieldState(x, y) <> fsStone then
367
  begin
262
  begin
368
    result := false;
263
    result := false;
369
    exit;
264
    exit;
370
  end;
265
  end;
371
 
266
 
Line 420... Line 315...
420
function TMainForm.AreJumpsPossible: boolean;
315
function TMainForm.AreJumpsPossible: boolean;
421
var
316
var
422
  i, j: integer;
317
  i, j: integer;
423
begin
318
begin
424
  result := false;
319
  result := false;
425
  for i := Low(PlayGroundMatrix) to High(PlayGroundMatrix) do
320
  for i := Low(PlayGroundMatrix.Fields) to High(PlayGroundMatrix.Fields) do
426
  begin
321
  begin
427
    for j := Low(PlayGroundMatrix[i]) to High(PlayGroundMatrix[i]) do
322
    for j := Low(PlayGroundMatrix.Fields[i]) to High(PlayGroundMatrix.Fields[i]) do
428
    begin
323
    begin
429
      if CanJump(i, j) then
324
      if CanJump(i, j) then
430
      begin
325
      begin
431
        result := true;
326
        result := true;
432
        break;
327
        break;
Line 435... Line 330...
435
    end;
330
    end;
436
  end;
331
  end;
437
end;
332
end;
438
 
333
 
439
procedure TMainForm.DoJump(SourceTag, DestTag: integer);
334
procedure TMainForm.DoJump(SourceTag, DestTag: integer);
-
 
335
resourcestring
-
 
336
  LNG_JUMP_LOG = '%d [%d, %d] -> %d [%d, %d];';
440
var
337
var
441
  d, s: TPoint;
338
  d, s: TPoint;
442
  old_fieldtype: TFieldType;
339
  old_fieldtype: TFieldType;
443
  res: Integer;
340
  res: Integer;
444
begin
341
begin
Line 450... Line 347...
450
  JumpHistory.Add(Format(LNG_JUMP_LOG, [SourceTag+1, s.x+1, s.y+1, DestTag+1, d.x+1, d.y+1]));
347
  JumpHistory.Add(Format(LNG_JUMP_LOG, [SourceTag+1, s.x+1, s.y+1, DestTag+1, d.x+1, d.y+1]));
451
 
348
 
452
  {$REGION 'Stein entfernen und Punkte vergeben'}
349
  {$REGION 'Stein entfernen und Punkte vergeben'}
453
  if Level.GetGameMode = gmDiagonal then
350
  if Level.GetGameMode = gmDiagonal then
454
  begin
351
  begin
455
    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);
352
    if (s.X-2 = d.X) and (s.Y-2 = d.Y) and (PlayGroundMatrix.FieldState(s.X-1, s.Y-1) = fsStone) then RemoveStone(s.X-1, s.Y-1, true);
456
    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);
353
    if (s.X-2 = d.X) and (s.Y+2 = d.Y) and (PlayGroundMatrix.FieldState(s.X-1, s.Y+1) = fsStone) then RemoveStone(s.X-1, s.Y+1, true);
457
    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);
354
    if (s.X+2 = d.X) and (s.Y-2 = d.Y) and (PlayGroundMatrix.FieldState(s.X+1, s.Y-1) = fsStone) then RemoveStone(s.X+1, s.Y-1, true);
458
    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);
355
    if (s.X+2 = d.X) and (s.Y+2 = d.Y) and (PlayGroundMatrix.FieldState(s.X+1, s.Y+1) = fsStone) then RemoveStone(s.X+1, s.Y+1, true);
459
  end;
356
  end;
460
 
357
 
461
  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);
358
  if (s.X+2 = d.X) and (s.Y = d.Y) and (PlayGroundMatrix.FieldState(s.X+1, s.Y  ) = fsStone) then RemoveStone(s.X+1, s.Y, true);
462
  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);
359
  if (s.X-2 = d.X) and (s.Y = d.Y) and (PlayGroundMatrix.FieldState(s.X-1, s.Y  ) = fsStone) then RemoveStone(s.X-1, s.Y, true);
463
  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);
360
  if (s.X = d.X) and (s.Y+2 = d.Y) and (PlayGroundMatrix.FieldState(s.X  , s.Y+1) = fsStone) then RemoveStone(s.X, s.Y+1, true);
464
  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);
361
  if (s.X = d.X) and (s.Y-2 = d.Y) and (PlayGroundMatrix.FieldState(s.X  , s.Y-1) = fsStone) then RemoveStone(s.X, s.Y-1, true);
465
  {$ENDREGION}
362
  {$ENDREGION}
466
 
363
 
467
  // Den Timer erst nach dem ersten Zug starten
364
  // Den Timer erst nach dem ersten Zug starten
468
  // oder nach einer Pause neustarten
365
  // oder nach einer Pause neustarten
469
  if not Timer.Enabled then
366
  MPauseTime.Checked := false;
470
  begin
-
 
471
    MPauseTime.Enabled := true;
367
  MPauseTime.Enabled := true;
472
    Timer.Enabled := true;
368
  Timer.Enabled := true;
473
  end;
-
 
474
 
-
 
475
  MRestartGame.Enabled := true;
-
 
476
 
369
 
477
  // Sound abspielen
370
  // Sound abspielen
478
  if MEnableSound.Checked then PlaySound(RES_JUMP, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE);
371
  if MEnableSound.Checked then PlaySound(RES_JUMP, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE);
479
 
372
 
480
  {$REGION 'Nun den Stein springen lassen'}
373
  {$REGION 'Nun den Stein springen lassen'}
481
  old_fieldtype := PlayGroundMatrix[s.X, s.Y].FieldType; // Steinfarbe merken
374
  old_fieldtype := PlayGroundMatrix.Fields[s.X, s.Y].FieldType; // Steinfarbe merken
482
  RemoveStone(s.X, s.Y, false); // Eigenen Stein entfernen. Keine Punkte zählen, da das unser eigener Stein ist, der springt
375
  RemoveStone(s.X, s.Y, false); // Eigenen Stein entfernen. Keine Punkte zählen, da das unser eigener Stein ist, der springt
483
  PlayGroundMatrix[d.X, d.Y].FieldType := old_fieldtype; // Farbe wiederherstellen
376
  PlayGroundMatrix.Fields[d.X, d.Y].FieldType := old_fieldtype; // Farbe wiederherstellen
484
  LoadPictureForType(PlayGroundMatrix[d.X, d.Y].FieldType, PlayGroundMatrix[d.X, d.Y].Stone.Picture); // Stein an neue Position malen
377
  LoadPictureForType(PlayGroundMatrix.Fields[d.X, d.Y].FieldType, PlayGroundMatrix.Fields[d.X, d.Y].Stone.Picture); // Stein an neue Position malen
485
  StoneDraggingAllow(PlayGroundMatrix[d.X, d.Y].Stone, true); // Und die Drag-Eigenschaft erneuern
378
  StoneDraggingAllow(PlayGroundMatrix.Fields[d.X, d.Y].Stone, true); // Und die Drag-Eigenschaft erneuern
486
  {$ENDREGION}
379
  {$ENDREGION}
487
 
380
 
488
  {$REGION 'Sind weitere Sprünge möglich oder ist das Spiel vorbei?'}
381
  {$REGION 'Sind weitere Sprünge möglich oder ist das Spiel vorbei?'}
489
  if not AreJumpsPossible then
382
  if not AreJumpsPossible then
490
  begin
383
  begin
-
 
384
    MPauseTime.Checked := false;
491
    MPauseTime.Enabled := false;
385
    MPauseTime.Enabled := false;
492
    Timer.Enabled := false;
386
    Timer.Enabled := false;
493
    RefreshTime;
387
    RefreshTime;
494
    if MEnableSound.Checked then
388
    if MEnableSound.Checked then
495
    begin
389
    begin
Line 507... Line 401...
507
    if (res = mrOK) and FinishForm.ReplayCheckbox.Checked then RestartLevel;
401
    if (res = mrOK) and FinishForm.ReplayCheckbox.Checked then RestartLevel;
508
  end;
402
  end;
509
  {$ENDREGION}
403
  {$ENDREGION}
510
 
404
 
511
  SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)+1);
405
  SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)+1);
512
  PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1] := CloneMatrix(PlaygroundMatrix);
406
  PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1] := PlaygroundMatrix.CloneMatrix;
513
  MUndo.Enabled := true;
407
  MUndo.Enabled := true;
514
end;
408
end;
515
 
409
 
516
function TMainForm.MayJump(SourceX, SourceY, DestX, DestY: integer): boolean;
410
function TMainForm.MayJump(SourceX, SourceY, DestX, DestY: integer): boolean;
517
begin
411
begin
518
  result := false;
412
  result := false;
519
 
413
 
520
  // Check 1: Ist das Zielfeld überhaupt leer?
414
  // Check 1: Ist das Zielfeld überhaupt leer?
521
  if FieldState(DestX, DestY) <> fsAvailable then exit;
415
  if PlayGroundMatrix.FieldState(DestX, DestY) <> fsAvailable then exit;
522
 
416
 
523
  // Check 2: Befindet sich ein Stein zwischen Source und Destination und ist der Abstand 2?
417
  // Check 2: Befindet sich ein Stein zwischen Source und Destination und ist der Abstand 2?
524
  if Level.GetGameMode = gmDiagonal then
418
  if Level.GetGameMode = gmDiagonal then
525
  begin
419
  begin
526
    if (SourceX-2 = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX-1, SourceY-1) = fsStone) then result := true;
420
    if (SourceX-2 = DestX) and (SourceY-2 = DestY) and (PlayGroundMatrix.FieldState(SourceX-1, SourceY-1) = fsStone) then result := true;
527
    if (SourceX-2 = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX-1, SourceY+1) = fsStone) then result := true;
421
    if (SourceX-2 = DestX) and (SourceY+2 = DestY) and (PlayGroundMatrix.FieldState(SourceX-1, SourceY+1) = fsStone) then result := true;
528
    if (SourceX+2 = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX+1, SourceY-1) = fsStone) then result := true;
422
    if (SourceX+2 = DestX) and (SourceY-2 = DestY) and (PlayGroundMatrix.FieldState(SourceX+1, SourceY-1) = fsStone) then result := true;
529
    if (SourceX+2 = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX+1, SourceY+1) = fsStone) then result := true;
423
    if (SourceX+2 = DestX) and (SourceY+2 = DestY) and (PlayGroundMatrix.FieldState(SourceX+1, SourceY+1) = fsStone) then result := true;
530
  end;
424
  end;
531
 
425
 
532
  if (SourceX+2 = DestX) and (SourceY   = DestY) and (FieldState(SourceX+1, SourceY  ) = fsStone) then result := true;
426
  if (SourceX+2 = DestX) and (SourceY   = DestY) and (PlayGroundMatrix.FieldState(SourceX+1, SourceY  ) = fsStone) then result := true;
533
  if (SourceX-2 = DestX) and (SourceY   = DestY) and (FieldState(SourceX-1, SourceY  ) = fsStone) then result := true;
427
  if (SourceX-2 = DestX) and (SourceY   = DestY) and (PlayGroundMatrix.FieldState(SourceX-1, SourceY  ) = fsStone) then result := true;
534
  if (SourceX   = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX  , SourceY+1) = fsStone) then result := true;
428
  if (SourceX   = DestX) and (SourceY+2 = DestY) and (PlayGroundMatrix.FieldState(SourceX  , SourceY+1) = fsStone) then result := true;
535
  if (SourceX   = DestX) and (SourceY-2 = DestY) and (FieldState(SourceX  , SourceY-1) = fsStone) then result := true;
429
  if (SourceX   = DestX) and (SourceY-2 = DestY) and (PlayGroundMatrix.FieldState(SourceX  , SourceY-1) = fsStone) then result := true;
536
end;
430
end;
537
 
431
 
538
function TMainForm.MayJump(SourceTag, DestTag: integer): boolean;
432
function TMainForm.MayJump(SourceTag, DestTag: integer): boolean;
539
var
433
var
540
  s, d: TPoint;
434
  s, d: TPoint;
Line 568... Line 462...
568
 
462
 
569
  newField.FieldType := t.Typ;
463
  newField.FieldType := t.Typ;
570
  newField.Goal := t.Goal;
464
  newField.Goal := t.Goal;
571
  newField.Panel := DrawStoneBox(x, y, index, indent, t.Goal);
465
  newField.Panel := DrawStoneBox(x, y, index, indent, t.Goal);
572
  newField.Stone := DrawStone(t.Typ, newField.Panel);
466
  newField.Stone := DrawStone(t.Typ, newField.Panel);
573
  if FieldState(t.Typ) = fsStone then Inc(LevelTotalStones);
467
  if PlayGroundMatrix.FieldState(t.Typ) = fsStone then Inc(LevelTotalStones);
574
 
468
 
575
  SetLength(LookupFieldCoordinateArray, index + 1);
469
  SetLength(LookupFieldCoordinateArray, index + 1);
576
  LookupFieldCoordinateArray[index].X := x;
470
  LookupFieldCoordinateArray[index].X := x;
577
  LookupFieldCoordinateArray[index].Y := y;
471
  LookupFieldCoordinateArray[index].Y := y;
578
 
472
 
579
  if Length(PlayGroundMatrix) < x+1 then SetLength(PlayGroundMatrix, x+1);
473
  if Length(PlayGroundMatrix.Fields) < x+1 then SetLength(PlayGroundMatrix.Fields, x+1);
580
  if Length(PlayGroundMatrix[x]) < y+1 then SetLength(PlayGroundMatrix[x], y+1);
474
  if Length(PlayGroundMatrix.Fields[x]) < y+1 then SetLength(PlayGroundMatrix.Fields[x], y+1);
581
  PlaygroundMatrix[x, y] := newField;
475
  PlaygroundMatrix.Fields[x, y] := newField;
582
 
476
 
583
  result := newField;
477
  result := newField;
584
end;
478
end;
585
 
479
 
586
function TMainForm.CloneMatrix(Source: TPlayGroundMatrix): TPlayGroundMatrix;
-
 
587
var
-
 
588
  i, j: integer;
-
 
589
begin
-
 
590
  SetLength(result, Length(Source));
-
 
591
  for i := Low(Source) to High(Source) do
-
 
592
  begin
-
 
593
    SetLength(result[i], Length(Source[i]));
-
 
594
    for j := Low(Source[i]) to High(Source[i]) do
-
 
595
    begin
-
 
596
      result[i][j].FieldType := Source[i][j].FieldType;
-
 
597
      result[i][j].Goal      := Source[i][j].Goal;
-
 
598
      result[i][j].Panel     := Source[i][j].Panel;
-
 
599
      result[i][j].Stone     := Source[i][j].Stone;
-
 
600
    end;
-
 
601
  end;
-
 
602
end;
-
 
603
 
-
 
604
procedure TMainForm.BuildPlayground(LevelArray: TLevelArray);
480
procedure TMainForm.BuildPlayground(LevelArray: TLevelArray);
605
var
481
var
606
  y, x: integer;
482
  y, x: integer;
607
  max_x, max_y: integer;
483
  max_x, max_y: integer;
608
  p: TPanel;
484
  p: TPanel;
Line 642... Line 518...
642
 
518
 
643
  Statistics.Panels.Items[0].Width := Round(ClientWidth*MET_PERCENT_PNL_TIME);
519
  Statistics.Panels.Items[0].Width := Round(ClientWidth*MET_PERCENT_PNL_TIME);
644
  Statistics.Panels.Items[1].Width := Round(ClientWidth*MET_PERCENT_PNL_STONES);
520
  Statistics.Panels.Items[1].Width := Round(ClientWidth*MET_PERCENT_PNL_STONES);
645
 
521
 
646
  SetLength(PrevPlaygroundMatrixes,1);
522
  SetLength(PrevPlaygroundMatrixes,1);
647
  PrevPlaygroundMatrixes[0] := CloneMatrix(PlayGroundMatrix);
523
  PrevPlaygroundMatrixes[0] := PlayGroundMatrix.CloneMatrix;
648
  MUndo.Enabled := false;
524
  MUndo.Enabled := false;
649
end;
525
end;
650
 
526
 
651
procedure TMainForm.TimerTimer(Sender: TObject);
527
procedure TMainForm.TimerTimer(Sender: TObject);
652
begin
528
begin
-
 
529
  if MPauseTime.Checked then exit;
653
  if mainform.Focused then Inc(CountedSeconds);
530
  if mainform.Focused then Inc(CountedSeconds);
654
  RefreshTime;
531
  RefreshTime;
655
end;
532
end;
656
 
533
 
657
function TMainForm.LevelTime: String;
534
function TMainForm.LevelTime: String;
658
begin
535
begin
659
  result := SecondsToTimeString(CountedSeconds);
536
  result := FormatDateTime('hh:nn:ss', CountedSeconds / SecsPerDay)
660
end;
537
end;
661
 
538
 
662
procedure TMainForm.NewGame(Filename: string);
539
procedure TMainForm.NewGame(Filename: string);
-
 
540
resourcestring
-
 
541
  LNG_LVL_INVALID_NO_JUMP = 'Warning! The level is not playable. There are no jumps possible.';
663
var
542
var
664
  LevelArray: TLevelArray;
543
  LevelArray: TLevelArray;
665
begin
544
begin
666
  DestroyLevel;
545
  DestroyLevel;
-
 
546
 
-
 
547
  MPauseTime.Checked := true;
-
 
548
  MPauseTime.Enabled := true;
-
 
549
  Timer.Enabled := true;
-
 
550
  MRestartGame.Enabled := true;
-
 
551
 
667
  LevelFile := Filename;
552
  LevelFile := Filename;
668
  Level := TLevel.Create(LevelFile);
553
  Level := TLevel.Create(LevelFile);
669
  LevelArray := Level.LevelStringToLevelArray(true);
554
  LevelArray := Level.LevelStringToLevelArray(true);
670
  if Length(LevelArray) = 0 then Exit;
555
  if Length(LevelArray) = 0 then Exit;
671
  BuildPlayground(LevelArray);
556
  BuildPlayground(LevelArray);
Line 721... Line 606...
721
 
606
 
722
function TMainForm.GoalStatus: TGoalStatus;
607
function TMainForm.GoalStatus: TGoalStatus;
723
var
608
var
724
  ft: TFieldType;
609
  ft: TFieldType;
725
begin
610
begin
726
  if not MatrixHasGoal(PlaygroundMatrix) then
611
  if not PlaygroundMatrix.MatrixHasGoal then
727
    result := gsNoGoal
612
    result := gsNoGoal
728
  else if LevelRemovedStones < LevelTotalStones-1 then
613
  else if LevelRemovedStones < LevelTotalStones-1 then
729
    Result := gsMultipleStonesRemaining
614
    Result := gsMultipleStonesRemaining
730
  else
615
  else
731
  begin
616
  begin
732
    ft := GoalFieldType(PlaygroundMatrix);
617
    ft := PlaygroundMatrix.GoalFieldType;
733
    if ft = ftRed then
618
    if ft = ftRed then
734
      result := gsLastStoneInGoalRed
619
      result := gsLastStoneInGoalRed
735
    else if ft = ftYellow then
620
    else if ft = ftYellow then
736
      result := gsLastStoneInGoalYellow
621
      result := gsLastStoneInGoalYellow
737
    else if ft = ftGreen then
622
    else if ft = ftGreen then
Line 761... Line 646...
761
 
646
 
762
procedure TMainForm.RestartLevel;
647
procedure TMainForm.RestartLevel;
763
var
648
var
764
  i: Integer;
649
  i: Integer;
765
begin
650
begin
766
  MPauseTime.Enabled := false;
651
  MPauseTime.Checked := true;
767
  Timer.Enabled := false;
652
  MPauseTime.Enabled := true;
768
 
-
 
769
  MRestartGame.Enabled := false;
653
  Timer.Enabled := true;
770
 
654
 
771
  CountedSeconds := 0;
655
  CountedSeconds := 0;
772
  RefreshTime;
656
  RefreshTime;
773
 
657
 
774
  Points := 0;
658
  Points := 0;
Line 780... Line 664...
780
  JumpHistory.Clear;
664
  JumpHistory.Clear;
781
 
665
 
782
  RedrawStonesFromMatrix(PrevPlaygroundMatrixes[0]);
666
  RedrawStonesFromMatrix(PrevPlaygroundMatrixes[0]);
783
  SetNewPlayGroundMatrix(PrevPlaygroundMatrixes[0]);
667
  SetNewPlayGroundMatrix(PrevPlaygroundMatrixes[0]);
784
  for i := 1 to Length(PrevPlaygroundMatrixes)-1 do
668
  for i := 1 to Length(PrevPlaygroundMatrixes)-1 do
785
    ClearMatrix(PrevPlaygroundMatrixes[i], false);
669
    PrevPlaygroundMatrixes[i].ClearMatrix(false);
786
  SetLength(PrevPlaygroundMatrixes, 1);
670
  SetLength(PrevPlaygroundMatrixes, 1);
787
 
671
 
788
  MUndo.Enabled := false;
672
  MUndo.Enabled := false;
789
end;
673
end;
790
 
674
 
791
procedure TMainForm.SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix);
675
procedure TMainForm.SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix);
792
begin
676
begin
793
  ClearMatrix(PlayGroundMatrix, false); // Memory Leak verhindern
677
  PlayGroundMatrix.ClearMatrix(false); // Memory Leak verhindern
794
  PlayGroundMatrix := CloneMatrix(Matrix);
678
  PlayGroundMatrix := Matrix.CloneMatrix;
795
end;
679
end;
796
 
680
 
797
procedure TMainForm.MRestartGameClick(Sender: TObject);
681
procedure TMainForm.MRestartGameClick(Sender: TObject);
798
begin
682
begin
799
  RestartLevel;
683
  RestartLevel;
Line 804... Line 688...
804
  PrevWorth: integer;
688
  PrevWorth: integer;
805
  NewWorth: integer;
689
  NewWorth: integer;
806
begin
690
begin
807
  if Length(PrevPlaygroundMatrixes) > 1 then
691
  if Length(PrevPlaygroundMatrixes) > 1 then
808
  begin
692
  begin
809
    PrevWorth := MatrixWorth(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]);
693
    PrevWorth := PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1].MatrixWorth;
810
 
694
 
811
    ClearMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1], false);
695
    PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1].ClearMatrix(false);
812
    SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)-1);
696
    SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)-1);
813
 
697
 
814
    NewWorth := MatrixWorth(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]);
698
    NewWorth := PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1].MatrixWorth;
815
    RedrawStonesFromMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]);
699
    RedrawStonesFromMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]);
816
    SetNewPlayGroundMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]);
700
    SetNewPlayGroundMatrix(PrevPlaygroundMatrixes[Length(PrevPlaygroundMatrixes)-1]);
817
 
701
 
818
    JumpHistory.Delete(JumpHistory.Count-1);
702
    JumpHistory.Delete(JumpHistory.Count-1);
819
 
703
 
Line 833... Line 717...
833
procedure TMainForm.MHighScoresClick(Sender: TObject);
717
procedure TMainForm.MHighScoresClick(Sender: TObject);
834
begin
718
begin
835
  HighScoreForm.Execute(ExtractFileNameWithoutExt(LevelFile));
719
  HighScoreForm.Execute(ExtractFileNameWithoutExt(LevelFile));
836
end;
720
end;
837
 
721
 
838
procedure TMainForm.MPauseTimeClick(Sender: TObject);
-
 
839
begin
-
 
840
  MPauseTime.Enabled := false;
-
 
841
  Timer.Enabled := false;
-
 
842
end;
-
 
843
 
-
 
844
procedure TMainForm.LoadSettings;
722
procedure TMainForm.LoadSettings;
845
var
723
var
846
  reg: TRegistry;
724
  reg: TRegistry;
847
begin
725
begin
848
  reg := TRegistry.Create;
726
  reg := TRegistry.Create;
Line 874... Line 752...
874
  finally
752
  finally
875
    reg.Free;
753
    reg.Free;
876
  end;
754
  end;
877
end;
755
end;
878
 
756
 
879
 
-
 
880
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
757
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
881
begin
758
begin
882
  SaveSettings;
759
  SaveSettings;
883
  if FinishForm.NameEdit.Text <> '' then
760
  if FinishForm.NameEdit.Text <> '' then
884
  begin
761
  begin
Line 896... Line 773...
896
procedure TMainForm.MHelpClick(Sender: TObject);
773
procedure TMainForm.MHelpClick(Sender: TObject);
897
begin
774
begin
898
  HelpForm.ShowModal;
775
  HelpForm.ShowModal;
899
end;
776
end;
900
 
777
 
901
procedure TMainForm.MEnableSoundClick(Sender: TObject);
-
 
902
begin
-
 
903
  MEnableSound.Checked := not MEnableSound.Checked;
-
 
904
end;
-
 
905
 
-
 
906
end.
778
end.