Rev 1 | Rev 9 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 8 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | 2 | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | uses |
5 | uses |
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, |
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, |
7 | Dialogs, StdCtrls, MMSystem, Math, ExtCtrls, Registry; |
7 | Dialogs, StdCtrls, MMSystem, Math, ExtCtrls, Registry, Main; |
8 | 8 | ||
9 | type |
9 | type |
10 | TFinishForm = class(TForm) |
10 | TFinishForm = class(TForm) |
11 | Label1: TLabel; |
11 | Label1: TLabel; |
12 | Label2: TLabel; |
12 | Label2: TLabel; |
Line 27... | Line 27... | ||
27 | FScore: integer; |
27 | FScore: integer; |
28 | FStonesTotal: integer; |
28 | FStonesTotal: integer; |
29 | FStonesRemoved: integer; |
29 | FStonesRemoved: integer; |
30 | FSeconds: integer; |
30 | FSeconds: integer; |
31 | FHistory: TStringList; |
31 | FHistory: TStringList; |
32 | procedure Calculate; |
32 | FGoalStatus: TGoalStatus; |
33 | procedure SaveToJournal(PlayerName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer); |
33 | procedure SaveToJournal(PlayerName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer); |
34 | procedure LoadSettings; |
34 | procedure LoadSettings; |
35 | public |
35 | public |
36 | procedure SaveSettings; |
36 | procedure SaveSettings; |
37 | function Execute(LevelName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer; JumpHistory: TStringList): Integer; |
37 | function Execute(LevelName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer; GoalStatus: TGoalStatus; JumpHistory: TStringList): Integer; |
38 | end; |
38 | end; |
39 | 39 | ||
40 | var |
40 | var |
41 | FinishForm: TFinishForm; |
41 | FinishForm: TFinishForm; |
42 | 42 | ||
43 | implementation |
43 | implementation |
44 | 44 | ||
45 | uses |
45 | uses |
46 | History, Constants; |
46 | History, Constants, LevelFunctions; |
47 | 47 | ||
48 | {$R *.dfm} |
48 | {$R *.dfm} |
49 | 49 | ||
50 | procedure TFinishForm.CancelBtnClick(Sender: TObject); |
50 | procedure TFinishForm.CancelBtnClick(Sender: TObject); |
51 | begin |
51 | begin |
52 | Close; |
52 | Close; |
53 | end; |
53 | end; |
54 | 54 | ||
55 | procedure TFinishForm.Calculate; |
55 | function TFinishForm.Execute(LevelName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer; GoalStatus: TGoalStatus; JumpHistory: TStringList): Integer; |
56 | begin |
56 | var |
57 | PerformanceMemo.Lines.Clear; |
57 | ExtraPoints: Integer; |
58 | PerformanceMemo.Lines.Add(Format(LNG_SCORE, [FScore])); |
- | |
59 | PerformanceMemo.Lines.Add(Format(LNG_REMAINING, [FStonesTotal - FStonesRemoved, |
- | |
60 | RoundTo(((FStonesTotal - FStonesRemoved) / FStonesTotal * 100), -2)])); |
- | |
61 | PerformanceMemo.Lines.Add(Format(LNG_TIME_SECONDS, [FSeconds])); |
- | |
62 | PerformanceMemo.Lines.Add(Format(LNG_POINTS_PER_MINUTE, [Round(FScore / FSeconds * 60)])); |
- | |
63 | end; |
- | |
64 | - | ||
65 | function TFinishForm.Execute(LevelName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer; JumpHistory: TStringList): Integer; |
- | |
66 | begin |
58 | begin |
67 | FLevel := LevelName; |
59 | FLevel := LevelName; |
68 | FScore := Score; |
60 | FScore := Score; |
69 | FStonesTotal := StonesTotal; |
61 | FStonesTotal := StonesTotal; |
70 | FStonesRemoved := StonesRemoved; |
62 | FStonesRemoved := StonesRemoved; |
71 | FSeconds := Seconds; |
63 | FSeconds := Seconds; |
- | 64 | FGoalStatus := GoalStatus; |
|
72 | FHistory := JumpHistory; |
65 | FHistory := JumpHistory; |
73 | 66 | ||
- | 67 | PerformanceMemo.Lines.Clear; |
|
- | 68 | PerformanceMemo.Lines.Add(''); |
|
- | 69 | PerformanceMemo.Lines.Add(Format(LNG_REMAINING, [FStonesTotal - 1 - FStonesRemoved, |
|
- | 70 | RoundTo(((FStonesTotal - 1 - FStonesRemoved) / FStonesTotal * 100), -2)])); |
|
- | 71 | PerformanceMemo.Lines.Add(Format(LNG_TIME_SECONDS, [FSeconds])); |
|
- | 72 | PerformanceMemo.Lines.Add(Format(LNG_POINTS_PER_MINUTE, [Round(FScore / FSeconds * 60)])); |
|
- | 73 | ||
- | 74 | if FGoalStatus = gsLastStoneInGoalRed then |
|
- | 75 | begin |
|
- | 76 | ExtraPoints := FieldTypeWorth(ftRed) * 100; |
|
- | 77 | PerformanceMemo.Lines.Add(Format(LNG_GOAL_RED, [ExtraPoints])) |
|
- | 78 | end |
|
- | 79 | else if FGoalStatus = gsLastStoneInGoalYellow then |
|
- | 80 | begin |
|
- | 81 | ExtraPoints := FieldTypeWorth(ftYellow) * 100; |
|
- | 82 | PerformanceMemo.Lines.Add(Format(LNG_GOAL_YELLOW, [ExtraPoints])) |
|
- | 83 | end |
|
- | 84 | else if FGoalStatus = gsLastStoneInGoalGreen then |
|
- | 85 | begin |
|
- | 86 | ExtraPoints := FieldTypeWorth(ftGreen) * 100; |
|
- | 87 | PerformanceMemo.Lines.Add(Format(LNG_GOAL_GREEN, [ExtraPoints])) |
|
- | 88 | end |
|
- | 89 | else if FGoalStatus = gsLastStoneOutsideGoal then |
|
- | 90 | begin |
|
- | 91 | ExtraPoints := 0; |
|
- | 92 | PerformanceMemo.Lines.Add(Format(LNG_GOAL_MISSED, [ExtraPoints])) |
|
74 | Calculate; |
93 | end; |
- | 94 | ||
- | 95 | Inc(FScore, ExtraPoints); |
|
- | 96 | PerformanceMemo.Lines.Strings[0] := Format(LNG_SCORE, [FScore]); |
|
- | 97 | ||
75 | result := ShowModal; |
98 | result := ShowModal; |
76 | end; |
99 | end; |
77 | 100 | ||
78 | procedure TFinishForm.SaveToJournal(PlayerName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer); |
101 | procedure TFinishForm.SaveToJournal(PlayerName: String; Score, StonesTotal, StonesRemoved, Seconds: Integer); |
79 | var |
102 | var |
Line 85... | Line 108... | ||
85 | AssignFile(f, tmp); |
108 | AssignFile(f, tmp); |
86 | if FileExists(tmp) then |
109 | if FileExists(tmp) then |
87 | Append(f) |
110 | Append(f) |
88 | else |
111 | else |
89 | ReWrite(f); |
112 | ReWrite(f); |
- | 113 | ||
- | 114 | // 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? |
|
90 | WriteLn(f, Format(JNL_ENTRY, [DateTimeToStr(now()), NameEdit.Text, FScore, FSeconds, FStonesRemoved, FStonesTotal])); |
115 | WriteLn(f, Format(JNL_ENTRY, [DateTimeToStr(now()), NameEdit.Text, FScore, FSeconds, FStonesRemoved, FStonesTotal-1])); |
- | 116 | ||
91 | CloseFile(f); |
117 | CloseFile(f); |
92 | end; |
118 | end; |
93 | 119 | ||
94 | procedure TFinishForm.SaveSettings; |
120 | procedure TFinishForm.SaveSettings; |
95 | var |
121 | var |
Line 134... | Line 160... | ||
134 | begin |
160 | begin |
135 | if NameEdit.Text = '' then |
161 | if NameEdit.Text = '' then |
136 | begin |
162 | begin |
137 | showmessage(LNG_ENTER_NAME); |
163 | showmessage(LNG_ENTER_NAME); |
138 | NameEdit.SetFocus; |
164 | NameEdit.SetFocus; |
139 | end |
- | |
140 | else |
- | |
141 | begin |
- | |
142 | SaveToJournal(NameEdit.Text, FScore, FStonesTotal, FStonesRemoved, FSeconds); |
- | |
143 | Close; |
165 | Exit; |
144 | end; |
166 | end; |
145 | 167 | ||
- | 168 | SaveToJournal(NameEdit.Text, FScore, FStonesTotal, FStonesRemoved, FSeconds); |
|
146 | ModalResult := mrOK; |
169 | ModalResult := mrOK; |
147 | end; |
170 | end; |
148 | 171 | ||
149 | procedure TFinishForm.JumpHistoryLinkClick(Sender: TObject); |
172 | procedure TFinishForm.JumpHistoryLinkClick(Sender: TObject); |
150 | begin |
173 | begin |