Subversion Repositories jumper

Rev

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

Rev 10 Rev 11
Line 66... Line 66...
66
    PlaygroundMatrix: TPlayGroundMatrix;
66
    PlaygroundMatrix: TPlayGroundMatrix;
67
    Points: Integer;
67
    Points: Integer;
68
    LevelTotalStones: Integer;
68
    LevelTotalStones: Integer;
69
    LevelRemovedStones: Integer;
69
    LevelRemovedStones: Integer;
70
    JumpHistory: TStringList;
70
    JumpHistory: TStringList;
-
 
71
    Level: TLevel;
71
    procedure LoadSettings;
72
    procedure LoadSettings;
72
    procedure SaveSettings;
73
    procedure SaveSettings;
73
    procedure RestartLevel;
74
    procedure RestartLevel;
74
    procedure SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix);
75
    procedure SetNewPlayGroundMatrix(Matrix: TPlayGroundMatrix);
75
    procedure RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix);
76
    procedure RedrawStonesFromMatrix(Matrix: TPlayGroundMatrix);
Line 222... Line 223...
222
    ClearMatrix(PrevPlaygroundMatrixes[i], false);
223
    ClearMatrix(PrevPlaygroundMatrixes[i], false);
223
  SetLength(PrevPlaygroundMatrixes, 0);
224
  SetLength(PrevPlaygroundMatrixes, 0);
224
  MUndo.Enabled := false;
225
  MUndo.Enabled := false;
225
 
226
 
226
  SetLength(LookupFieldCoordinateArray, 0);
227
  SetLength(LookupFieldCoordinateArray, 0);
-
 
228
 
-
 
229
  if Assigned(Level) then FreeAndNil(Level);
227
end;
230
end;
228
 
231
 
229
procedure TMainForm.LoadPictureForType(FieldType: TFieldType; Picture: TPicture);
232
procedure TMainForm.LoadPictureForType(FieldType: TFieldType; Picture: TPicture);
230
begin
233
begin
231
  case FieldType of
234
  case FieldType of
Line 296... Line 299...
296
 
299
 
297
function TMainForm.FieldState(t: TFieldType): TFieldState;
300
function TMainForm.FieldState(t: TFieldType): TFieldState;
298
begin
301
begin
299
  result := fsError;
302
  result := fsError;
300
  case t of
303
  case t of
301
    ftLocked:        result := fsLocked;
304
    ftFullSpace:        result := fsLocked;
302
    ftLockedWithTab: result := fsLocked;
305
    ftHalfSpace: result := fsLocked;
303
    ftEmpty:         result := fsAvailable;
306
    ftEmpty:         result := fsAvailable;
304
    ftGreen:         result := fsStone;
307
    ftGreen:         result := fsStone;
305
    ftYellow:        result := fsStone;
308
    ftYellow:        result := fsStone;
306
    ftRed:           result := fsStone;
309
    ftRed:           result := fsStone;
307
  end;
310
  end;
Line 368... Line 371...
368
  if MayJump(x, y, x+2, y) then exit;
371
  if MayJump(x, y, x+2, y) then exit;
369
  if MayJump(x, y, x-2, y) then exit;
372
  if MayJump(x, y, x-2, y) then exit;
370
  if MayJump(x, y, x, y+2) then exit;
373
  if MayJump(x, y, x, y+2) then exit;
371
  if MayJump(x, y, x, y-2) then exit;
374
  if MayJump(x, y, x, y-2) then exit;
372
 
375
 
373
  if AllowDiagonalMoves then
376
  if Level.GetGameMode = gmDiagonal then
374
  begin
377
  begin
375
    if MayJump(x, y, x-2, y-2) then exit;
378
    if MayJump(x, y, x-2, y-2) then exit;
376
    if MayJump(x, y, x+2, y-2) then exit;
379
    if MayJump(x, y, x+2, y-2) then exit;
377
    if MayJump(x, y, x-2, y+2) then exit;
380
    if MayJump(x, y, x-2, y+2) then exit;
378
    if MayJump(x, y, x+2, y+2) then exit;
381
    if MayJump(x, y, x+2, y+2) then exit;
Line 412... Line 415...
412
  s := LookupFieldCoordinateArray[SourceTag];
415
  s := LookupFieldCoordinateArray[SourceTag];
413
 
416
 
414
  JumpHistory.Add(Format(LNG_JUMP_LOG, [SourceTag+1, s.x+1, s.y+1, DestTag+1, d.x+1, d.y+1]));
417
  JumpHistory.Add(Format(LNG_JUMP_LOG, [SourceTag+1, s.x+1, s.y+1, DestTag+1, d.x+1, d.y+1]));
415
 
418
 
416
  {$REGION 'Stein entfernen und Punkte vergeben'}
419
  {$REGION 'Stein entfernen und Punkte vergeben'}
417
  if AllowDiagonalMoves then
420
  if Level.GetGameMode = gmDiagonal then
418
  begin
421
  begin
419
    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);
420
    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);
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);
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);
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);
425
    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);
Line 483... Line 486...
483
 
486
 
484
  // Check 1: Ist das Zielfeld überhaupt leer?
487
  // Check 1: Ist das Zielfeld überhaupt leer?
485
  if FieldState(DestX, DestY) <> fsAvailable then exit;
488
  if FieldState(DestX, DestY) <> fsAvailable then exit;
486
 
489
 
487
  // Check 2: Befindet sich ein Stein zwischen Source und Destination und ist der Abstand 2?
490
  // Check 2: Befindet sich ein Stein zwischen Source und Destination und ist der Abstand 2?
488
  if AllowDiagonalMoves then
491
  if Level.GetGameMode = gmDiagonal then
489
  begin
492
  begin
490
    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;
491
    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;
492
    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;
493
    if (SourceX+2 = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX+1, SourceY+1) = fsStone) then result := true;
496
    if (SourceX+2 = DestX) and (SourceY+2 = DestY) and (FieldState(SourceX+1, SourceY+1) = fsStone) then result := true;
Line 523... Line 526...
523
procedure TMainForm.DrawField(x, y: integer; t: TFieldProperties; halftabs: integer);
526
procedure TMainForm.DrawField(x, y: integer; t: TFieldProperties; halftabs: integer);
524
var
527
var
525
  newField: TField;
528
  newField: TField;
526
  index: integer;
529
  index: integer;
527
begin
530
begin
528
  if (t.Typ = ftLocked) or (t.Typ = ftLockedWithTab) then exit;
531
  if (t.Typ = ftFullSpace) or (t.Typ = ftHalfSpace) then exit;
529
 
532
 
530
  index := Length(LookupFieldCoordinateArray);
533
  index := Length(LookupFieldCoordinateArray);
531
 
534
 
532
  newField.FieldType := t.Typ;
535
  newField.FieldType := t.Typ;
533
  newField.Goal := t.Goal;
536
  newField.Goal := t.Goal;
Line 574... Line 577...
574
  for i := Low(LevelArray) to High(LevelArray) do
577
  for i := Low(LevelArray) to High(LevelArray) do
575
  begin
578
  begin
576
    halftabs := 0;
579
    halftabs := 0;
577
    for j := Low(LevelArray[i]) to High(LevelArray[i]) do
580
    for j := Low(LevelArray[i]) to High(LevelArray[i]) do
578
    begin
581
    begin
579
      if LevelArray[i][j].Typ = ftLockedWithTab then inc(halftabs);
582
      if LevelArray[i][j].Typ = ftHalfSpace then inc(halftabs);
580
      DrawField(j, i, LevelArray[i][j], halftabs);
583
      DrawField(j, i, LevelArray[i][j], halftabs);
581
    end;
584
    end;
582
    cur_x := High(LevelArray[i]) + 1;
585
    cur_x := High(LevelArray[i]) + 1;
583
    if cur_x > max_x then max_x := cur_x;
586
    if cur_x > max_x then max_x := cur_x;
584
  end;
587
  end;
Line 627... Line 630...
627
  result := SecondsToTimeString(CountedSeconds);
630
  result := SecondsToTimeString(CountedSeconds);
628
end;
631
end;
629
 
632
 
630
procedure TMainForm.NewGame(Filename: string);
633
procedure TMainForm.NewGame(Filename: string);
631
var
634
var
632
  LevelString: String;
-
 
633
  LevelArray: TLevelArray;
635
  LevelArray: TLevelArray;
634
begin                          
636
begin
635
  DestroyLevel;
637
  DestroyLevel;
636
  LevelFile := Filename;
638
  LevelFile := Filename;
637
  LevelString := ReadFile(LevelFile);
639
  Level := TLevel.Create(LevelFile);
638
  LevelArray := LevelStringToLevelArray(LevelString, true);
640
  LevelArray := Level.LevelStringToLevelArray(true);
639
  if Length(LevelArray) = 0 then Exit;
641
  if Length(LevelArray) = 0 then Exit;
640
  BuildPlayground(LevelArray);
642
  BuildPlayground(LevelArray);
641
  if not AreJumpsPossible then
643
  if not AreJumpsPossible then
642
  begin
644
  begin
643
    MessageDlg(LNG_LVL_INVALID_NO_JUMP, mtError, [mbOk], 0);
645
    MessageDlg(LNG_LVL_INVALID_NO_JUMP, mtError, [mbOk], 0);
Line 710... Line 712...
710
  LoadSettings;
712
  LoadSettings;
711
end;
713
end;
712
 
714
 
713
procedure TMainForm.FormDestroy(Sender: TObject);
715
procedure TMainForm.FormDestroy(Sender: TObject);
714
begin
716
begin
-
 
717
  DestroyLevel;
715
  JumpHistory.Free;
718
  JumpHistory.Free;
716
end;
719
end;
717
 
720
 
718
procedure TMainForm.MJumpHistoryClick(Sender: TObject);
721
procedure TMainForm.MJumpHistoryClick(Sender: TObject);
719
begin
722
begin