forked from ericlangedijk/Lemmix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameScreen.Postview.pas
248 lines (213 loc) · 6.29 KB
/
GameScreen.Postview.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
unit GameScreen.Postview;
{$include lem_directives.inc}
interface
uses
LCLIntf, LCLType,
Classes, SysUtils,
Controls, ClipBrd,
Gr32, Gr32_Image, Gr32_Layers,
Base.Utils,
Dos.Consts,
Prog.Base, Prog.Types, Prog.App, Prog.Data, Prog.Strings,
Game,
Styles.Base,
Form.Message,
GameScreen.Base;
type
// The dos postview screen, which shows you how you've played the game etc.
TGamePostviewScreen = class(TGameBaseScreen)
private
fPlayedLevelInfo: TLevelLoadingInformation;
fNextCode: string;
function GetScreenText: string;
procedure Form_KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Form_KeyPress(Sender: TObject; var Key: Char);
procedure Form_MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure Img_MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
procedure HandleMouseClick(Button: TMouseButton);
protected
procedure PrepareGameParams; override;
procedure BuildScreen; override;
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
uses
Forms;
{ TDosGamePreview }
procedure TGamePostviewScreen.PrepareGameParams;
begin
inherited;
end;
procedure TGamePostviewScreen.BuildScreen;
var
Temp: TBitmap32;
begin
ScreenImg.BeginUpdate;
Temp := TBitmap32.Create;
try
InitializeImageSizeAndPosition(640, 350);
ExtractBackGround;
ExtractPurpleFont;
Temp.SetSize(640, 350);
Temp.Clear(0);
TileBackgroundBitmap(0, 0, Temp);
DrawPurpleTextCentered(Temp, GetScreenText, 16);
ScreenImg.Bitmap.Assign(Temp);
finally
ScreenImg.EndUpdate;
Temp.Free;
end;
end;
constructor TGamePostviewScreen.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
Stretched := True;
OnKeyDown := Form_KeyDown;
OnKeyPress := Form_KeyPress;
OnMouseDown := Form_MouseDown;
ScreenImg.OnMouseDown := Img_MouseDown;
end;
destructor TGamePostviewScreen.Destroy;
begin
inherited Destroy;
end;
function TGamePostviewScreen.GetScreenText: string;
var
STarget: string;
SDone: string;
H: string;
procedure AddLine(const S: string);
begin
Result := Result + S + #13;
end;
procedure AddLineFeed(aCount: Integer);
begin
if aCount <= 0 then
Exit;
Result := Result + StringOfChar(#13, aCount);
end;
function GetResultText: string;
var
ix: Integer;
r: TGameResultsRec;
begin
if App.GameResult.Cheated then
Exit(SYouCheater);
ix := -1;
r := App.GameResult; // shorten code
// result text
if r.Done = 100 then ix := 8 else
if r.Done = 0 then ix := 0 else
if r.Done < r.Target div 2 then ix := 1 else
if r.Done < r.Target - 5 then ix := 2 else
if r.Done < r.Target - 1 then ix := 3 else
if r.Done = r.Target - 1 then ix := 4 else
if r.Done = r.Target then ix := 5 else
if r.Done < r.Target + 20 then ix := 6 else
if r.Done >= r.Target + 20 then ix := 7;
if (ix >= 0) and (ix < Length(ResultStrings[Consts.StyleDef]))
then Result := ResultStrings[Consts.StyleDef][ix]
else Result := SUnknownGameResultString;
end;
var
NextInfo: TLevelLoadingInformation;
NextAvail, Congrats: Boolean;
r: TGameResultsRec;
//Sys: TLevelSystem;
begin
Assert(App.CurrentLevelInfo <> nil);
fPlayedLevelInfo := App.CurrentLevelInfo;
Result := '';
r := App.GameResult;
NextInfo := App.CurrentLevelInfo.Next;
NextAvail := NextInfo <> nil;
Congrats := not NextAvail and r.Success;
// next level earned
if r.Success then
App.CurrentLevelInfo := NextInfo;
// all levels finished
if Congrats then
AddLine(SCongrats[Consts.StyleDef])
// default
else begin
// init some local strings
STarget := (r.Target.ToString + '%').PadLeft(4);
SDone := (r.Done.ToString + '%').PadLeft(4);
// top text
if r.TimeIsUp
then AddLine(SYourTimeIsUp)
else AddLine(SAllLemmingsAccountedFor);
AddLineFeed(1);
AddLine(Format(SYouRescuedYouNeeded_ss, [SDone, STarget]));
AddLineFeed(1);
AddLine(GetResultText);
AddLineFeed(6);
if r.Success then begin
H := NextInfo.GetLevelCode;
fNextCode := H;
AddLine(Format(SYourAccessCode_ds, [NextInfo.LevelIndex + 1, H]));
AddLineFeed(3);
end
else
AddLineFeed(5);
end;
// force bottomtext to a fixed position
AddLineFeed(18 - Result.CountChar(#13));
// check final screen
if Congrats then
AddLine(SPressMouseToContinue)
// default bottom text
else begin
if r.Success
then AddLine(SPressLeftMouseForNextLevel)
else AddLine(SPressLeftMouseToRetryLevel);
AddLine(SPressRightMouseForMenu);
end;
end;
procedure TGamePostviewScreen.Form_KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
case Key of
VK_ESCAPE: CloseScreen(TGameScreenType.Menu);
VK_RETURN: CloseScreen(TGameScreenType.Preview);
end;
end;
procedure TGamePostviewScreen.Form_MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
HandleMouseClick(Button);
end;
procedure TGamePostviewScreen.Img_MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
begin
HandleMouseClick(Button);
end;
procedure TGamePostviewScreen.HandleMouseClick(Button: TMouseButton);
begin
if Button = mbLeft then
CloseScreen(TGameScreenType.Preview)
else if Button = mbRight then
CloseScreen(TGameScreenType.Menu);
end;
procedure TGamePostviewScreen.Form_KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
^C :
begin
if App.GlobalGame.GameResultRec.Success then
ClipBoard.AsText := fNextCode;
end;
'u':
begin
App.GlobalGame.Save(True);
DlgInfo('Game saved (including game result in .txt file)');
end;
'r':
begin
App.CurrentLevelInfo := fPlayedLevelInfo;
App.ReplayCurrent := True;
CloseScreen(TGameScreenType.Play);
end;
end;
end;
end.