Subversion Repositories jumper

Compare Revisions

Regard whitespace Rev HEAD → Rev 1

/trunk/Finish.pas
4,7 → 4,7
 
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MMSystem, Math, ExtCtrls, Registry, LevelFunctions;
Dialogs, StdCtrls, MMSystem, Math, ExtCtrls, Registry;
 
type
TFinishForm = class(TForm)
29,12 → 29,12
FStonesRemoved: integer;
FSeconds: integer;
FHistory: TStringList;
FGoalStatus: TGoalStatus;
procedure Calculate;
procedure SaveToJournal(PlayerName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer);
procedure LoadSettings;
public
procedure SaveSettings;
function Execute(LevelName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer; GoalStatus: TGoalStatus; JumpHistory: TStringList): Integer;
function Execute(LevelName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer; JumpHistory: TStringList): Integer;
end;
 
var
52,61 → 52,26
Close;
end;
 
function TFinishForm.Execute(LevelName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer; GoalStatus: TGoalStatus; JumpHistory: TStringList): Integer;
resourcestring
LNG_SCORE = 'Score: %d';
LNG_REMAINING = 'Remaining stones: %d (%f%%)'; // Jumping stone not counted!
LNG_TIME_SECONDS = 'Time: %d seconds';
LNG_POINTS_PER_MINUTE = '%d points per minute';
LNG_GOAL_RED = 'Red stone in target field (%d points)';
LNG_GOAL_YELLOW = 'Yellow stone in target field (%d points)';
LNG_GOAL_GREEN = 'Green stone in target field (%d points)';
LNG_GOAL_MISSED = 'No stone in target field (%d points)';
var
ExtraPoints: Integer;
procedure TFinishForm.Calculate;
begin
PerformanceMemo.Lines.Clear;
PerformanceMemo.Lines.Add(Format(LNG_SCORE, [FScore]));
PerformanceMemo.Lines.Add(Format(LNG_REMAINING, [FStonesTotal - FStonesRemoved,
RoundTo(((FStonesTotal - FStonesRemoved) / FStonesTotal * 100), -2)]));
PerformanceMemo.Lines.Add(Format(LNG_TIME_SECONDS, [FSeconds]));
PerformanceMemo.Lines.Add(Format(LNG_POINTS_PER_MINUTE, [Round(FScore / FSeconds * 60)]));
end;
 
function TFinishForm.Execute(LevelName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer; JumpHistory: TStringList): Integer;
begin
FLevel := LevelName;
FScore := Score;
FStonesTotal := StonesTotal;
FStonesRemoved := StonesRemoved;
FSeconds := Seconds;
FGoalStatus := GoalStatus;
FHistory := JumpHistory;
 
PerformanceMemo.Lines.Clear;
PerformanceMemo.Lines.Add('');
PerformanceMemo.Lines.Add(Format(LNG_REMAINING, [FStonesTotal - 1 - FStonesRemoved,
RoundTo(((FStonesTotal - 1 - FStonesRemoved) / FStonesTotal * 100), -2)]));
PerformanceMemo.Lines.Add(Format(LNG_TIME_SECONDS, [FSeconds]));
PerformanceMemo.Lines.Add(Format(LNG_POINTS_PER_MINUTE, [Round(FScore / FSeconds * 60)]));
 
if FGoalStatus = gsLastStoneInGoalRed then
begin
ExtraPoints := FieldTypeWorth(ftRed) * 100;
PerformanceMemo.Lines.Add(Format(LNG_GOAL_RED, [ExtraPoints]));
Inc(FScore, ExtraPoints);
end
else if FGoalStatus = gsLastStoneInGoalYellow then
begin
ExtraPoints := FieldTypeWorth(ftYellow) * 100;
PerformanceMemo.Lines.Add(Format(LNG_GOAL_YELLOW, [ExtraPoints]));
Inc(FScore, ExtraPoints);
end
else if FGoalStatus = gsLastStoneInGoalGreen then
begin
ExtraPoints := FieldTypeWorth(ftGreen) * 100;
PerformanceMemo.Lines.Add(Format(LNG_GOAL_GREEN, [ExtraPoints]));
Inc(FScore, ExtraPoints);
end
else if FGoalStatus = gsLastStoneOutsideGoal then
begin
ExtraPoints := 0;
PerformanceMemo.Lines.Add(Format(LNG_GOAL_MISSED, [ExtraPoints]));
Inc(FScore, ExtraPoints);
end;
 
PerformanceMemo.Lines.Strings[0] := Format(LNG_SCORE, [FScore]);
 
Calculate;
result := ShowModal;
end;
 
122,10 → 87,7
Append(f)
else
ReWrite(f);
 
// TODO: Maybe we should do much more details, like, how many green stones were removed, how many yellows etc., and which stone was in the goal?
WriteLn(f, Format(JNL_ENTRY, [DateTimeToStr(now()), NameEdit.Text, FScore, FSeconds, FStonesRemoved, FStonesTotal-1]));
 
WriteLn(f, Format(JNL_ENTRY, [DateTimeToStr(now()), NameEdit.Text, FScore, FSeconds, FStonesRemoved, FStonesTotal]));
CloseFile(f);
end;
 
169,17 → 131,18
end;
 
procedure TFinishForm.SaveBtnClick(Sender: TObject);
resourcestring
LNG_ENTER_NAME = 'Please enter your name to get added to the high score lists.';
begin
if NameEdit.Text = '' then
begin
MessageDlg(LNG_ENTER_NAME, mtWarning, [mbOk], 0);
showmessage(LNG_ENTER_NAME);
NameEdit.SetFocus;
Exit;
end
else
begin
SaveToJournal(NameEdit.Text, FScore, FStonesTotal, FStonesRemoved, FSeconds);
Close;
end;
 
SaveToJournal(NameEdit.Text, FScore, FStonesTotal, FStonesRemoved, FSeconds);
ModalResult := mrOK;
end;
 
193,7 → 156,7
begin
if not ForceDirectories(ExtractFilePath(Application.ExeName) + JNL_PATH) then
begin
MessageDlg(Format(LNG_COULD_NOT_CREATE_DIR, [JNL_PATH]), mtError, [mbOk], 0);
ShowMessage(Format(LNG_COULD_NOT_CREATE_DIR, [JNL_PATH]));
end;
 
LoadSettings;