Subversion Repositories jumper

Rev

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

Rev 7 Rev 8
Line 12... Line 12...
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);
-
 
18
 
17
  TFieldState = (fsError, fsLocked, fsAvailable, fsStone);
19
  TFieldState = (fsError, fsLocked, fsAvailable, fsStone);
18
 
20
 
19
  TPlayGroundMatrix = array of array of TField;
21
  TPlayGroundMatrix = array of array of TField;
20
 
22
 
21
  TMainForm = class(TForm)
23
  TMainForm = class(TForm)
Line 97... Line 99...
97
    function FieldState(t: TFieldType): TFieldState; overload;
99
    function FieldState(t: TFieldType): TFieldState; overload;
98
    function FieldState(f: TField): TFieldState; overload;
100
    function FieldState(f: TField): TFieldState; overload;
99
    function FieldState(x, y: integer): TFieldState; overload;
101
    function FieldState(x, y: integer): TFieldState; overload;
100
    procedure ClearMatrix(Matrix: TPlayGroundMatrix; FreeVCL: boolean);
102
    procedure ClearMatrix(Matrix: TPlayGroundMatrix; FreeVCL: boolean);
101
    function CloneMatrix(Source: TPlayGroundMatrix): TPlayGroundMatrix;
103
    function CloneMatrix(Source: TPlayGroundMatrix): TPlayGroundMatrix;
-
 
104
    function MatrixHasGoal(Matrix: TPlayGroundMatrix): boolean;
102
    procedure LoadPictureForType(FieldType: TFieldType; Picture: TPicture);
105
    procedure LoadPictureForType(FieldType: TFieldType; Picture: TPicture);
103
    function MatrixWorth(Matrix: TPlayGroundMatrix): integer;
106
    function MatrixWorth(Matrix: TPlayGroundMatrix): integer;
-
 
107
    function GoalStatus: TGoalStatus;
104
    function FieldTypeWorth(t: TFieldType): integer;
108
    function GoalFieldType(Matrix: TPlayGroundMatrix): TFieldType;
105
  end;
109
  end;
106
 
110
 
107
var
111
var
108
  MainForm: TMainForm;
112
  MainForm: TMainForm;
109
 
113
 
Line 112... Line 116...
112
uses
116
uses
113
  About, Finish, Choice, Functions, History, HighScore, Help, Constants;
117
  About, Finish, Choice, Functions, History, HighScore, Help, Constants;
114
 
118
 
115
{$R *.dfm}
119
{$R *.dfm}
116
 
120
 
-
 
121
function TMainForm.MatrixHasGoal(Matrix: TPlayGroundMatrix): boolean;
-
 
122
var
-
 
123
  i, j: integer;
-
 
124
begin
-
 
125
  result := false;
-
 
126
  for i := Low(Matrix) to High(Matrix) do
-
 
127
  begin
-
 
128
    for j := Low(Matrix[i]) to High(Matrix[i]) do
-
 
129
    begin
-
 
130
      result := result or Matrix[i][j].Goal;
-
 
131
    end;
-
 
132
  end;
-
 
133
end;
-
 
134
 
-
 
135
function TMainForm.GoalFieldType(Matrix: TPlayGroundMatrix): TFieldType;
-
 
136
var
-
 
137
  i, j: integer;
-
 
138
begin
-
 
139
  for i := Low(Matrix) to High(Matrix) do
-
 
140
  begin
-
 
141
    for j := Low(Matrix[i]) to High(Matrix[i]) do
-
 
142
    begin
-
 
143
      if Matrix[i][j].Goal then result := Matrix[i][j].FieldType
-
 
144
    end;
-
 
145
  end;
-
 
146
end;
-
 
147
 
117
function TMainForm.MatrixWorth(Matrix: TPlayGroundMatrix): integer;
148
function TMainForm.MatrixWorth(Matrix: TPlayGroundMatrix): integer;
118
var
149
var
119
  i, j: integer;
150
  i, j: integer;
120
begin
151
begin
121
  result := 0;
152
  result := 0;
Line 305... Line 336...
305
procedure TMainForm.RefreshPoints;
336
procedure TMainForm.RefreshPoints;
306
begin
337
begin
307
  Statistics.Panels.Items[2].Text := Format(LNG_POINTS, [Points]);
338
  Statistics.Panels.Items[2].Text := Format(LNG_POINTS, [Points]);
308
end;
339
end;
309
 
340
 
310
function TMainForm.FieldTypeWorth(t: TFieldType): integer;
-
 
311
begin
-
 
312
  if t = ftGreen then result := 10
-
 
313
  else if t = ftYellow then result := 20
-
 
314
  else if t = ftRed then result := 30
-
 
315
  else result := 0;
-
 
316
end;
-
 
317
 
-
 
318
procedure TMainForm.CountPoints(t: TFieldType);
341
procedure TMainForm.CountPoints(t: TFieldType);
319
begin
342
begin
320
  inc(Points, FieldTypeWorth(t));
343
  inc(Points, FieldTypeWorth(t));
321
  RefreshPoints;
344
  RefreshPoints;
322
end;
345
end;
Line 434... Line 457...
434
    MPauseTime.Enabled := false;
457
    MPauseTime.Enabled := false;
435
    Timer.Enabled := false;
458
    Timer.Enabled := false;
436
    RefreshTime;
459
    RefreshTime;
437
    if MEnableSound.Checked then
460
    if MEnableSound.Checked then
438
    begin
461
    begin
439
      if LevelRemovedStones = LevelTotalStones then
462
      if LevelRemovedStones = LevelTotalStones-1 then
-
 
463
      begin
-
 
464
        if GoalStatus in [gsLastStoneInGoalRed, gsLastStoneInGoalYellow, gsLastStoneInGoalGreen] then
-
 
465
          PlaySound(RES_WIN2, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE)
-
 
466
        else
440
        PlaySound(RES_FINISH, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE)
467
          PlaySound(RES_WIN1, HInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE)
-
 
468
      end
441
      else
469
      else
442
        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);
443
    end;
471
    end;
444
    res := FinishForm.Execute(ExtractFileNameWithoutExt(LevelFile), Points, LevelTotalStones, LevelRemovedStones, CountedSeconds, JumpHistory);
472
    res := FinishForm.Execute(ExtractFileNameWithoutExt(LevelFile), Points, LevelTotalStones, LevelRemovedStones, CountedSeconds, GoalStatus, JumpHistory);
445
    if (res = mrOK) and FinishForm.ReplayCheckbox.Checked then RestartLevel;
473
    if (res = mrOK) and FinishForm.ReplayCheckbox.Checked then RestartLevel;
446
  end;
474
  end;
447
  {$ENDREGION}
475
  {$ENDREGION}
448
 
476
 
449
  SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)+1);
477
  SetLength(PrevPlaygroundMatrixes, Length(PrevPlaygroundMatrixes)+1);
Line 657... Line 685...
657
    NewGame(LevelFile);
685
    NewGame(LevelFile);
658
  end
686
  end
659
  else Close();
687
  else Close();
660
end;
688
end;
661
 
689
 
-
 
690
function TMainForm.GoalStatus: TGoalStatus;
-
 
691
var
-
 
692
  ft: TFieldType;
-
 
693
begin
-
 
694
  if not MatrixHasGoal(PlaygroundMatrix) then
-
 
695
    result := gsNoGoal
-
 
696
  else if LevelRemovedStones < LevelTotalStones-1 then
-
 
697
    Result := gsMultipleStonesRemaining
-
 
698
  else
-
 
699
  begin
-
 
700
    ft := GoalFieldType(PlaygroundMatrix);
-
 
701
    if ft = ftRed then
-
 
702
      result := gsLastStoneInGoalRed
-
 
703
    else if ft = ftYellow then
-
 
704
      result := gsLastStoneInGoalYellow
-
 
705
    else if ft = ftGreen then
-
 
706
      result := gsLastStoneInGoalGreen;
-
 
707
  end;
-
 
708
end;
-
 
709
 
662
procedure TMainForm.FormCreate(Sender: TObject);
710
procedure TMainForm.FormCreate(Sender: TObject);
663
begin
711
begin
664
  JumpHistory := TStringList.Create;
712
  JumpHistory := TStringList.Create;
665
  LoadSettings;
713
  LoadSettings;
666
end;
714
end;