-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuGameScore.pas
More file actions
151 lines (131 loc) · 3.25 KB
/
uGameScore.pas
File metadata and controls
151 lines (131 loc) · 3.25 KB
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
unit uGameScore;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Objects;
type
TScore = class(TFrame)
Rectangle1: TRectangle;
ImgTime: TImage;
TxtTime: TImage;
ImageFlag: TImage;
ImgFlagCount: TImage;
ImgMinesCount: TImage;
ImgMines: TImage;
private
FTimeStr : String;
FTime : TTime;
FTimer : TTimer;
Procedure UpdateTime(Sender : TObject);
public
Constructor Create(aOwner : TComponent); Override;
Procedure ShowIn(aControl : TControl);
Procedure HideScore;
Procedure ShowTime(aTime : string);
Procedure ShowFlags(aFlags : Integer);
procedure ShowMines(aMines : Integer);
Procedure StartTime;
Procedure StopTime;
Procedure ResumeTime;
Procedure IncTime(aSec : Integer);
Property Time : TTime Read FTime;
end;
Var
Score : TScore;
implementation
Uses
FMX.Ani,
uImages;
{$R *.fmx}
{ TFrame1 }
constructor TScore.Create(aOwner: TComponent);
begin
inherited;
FTime := 0;
FTimer := TTimer.Create(Self);
FTimer.Enabled := False;
FTimer.Interval := 100;
FTimer.OnTimer := UpdateTime;
ShowFlags(0);
end;
procedure TScore.ShowIn(aControl: TControl);
begin
Parent := aControl;
Position.x := (aControl.Width-Width)/2;
Position.Y := -Height-2;
TAnimator.AnimateFloat(Self, 'Position.Y', 20, 1, TAnimationType.Out, TInterpolationType.Back);
ShowTime ('00:00:00');
ShowFlags(0);
end;
procedure TScore.HideScore;
begin
TAnimator.AnimateFloat(Self, 'Position.Y', -Height-2, 1, TAnimationType.Out, TInterpolationType.Back);
TThread.CreateAnonymousThread(
Procedure
Begin
Sleep(420);
TThread.Synchronize(Nil,
Procedure
Begin
Parent := Nil;
End);
End).Start;
end;
procedure TScore.IncTime(aSec: Integer);
begin
If aSec <= 60 Then
FTime := FTime + StrToTime('00:00:'+FormatFloat('00', aSec));
end;
procedure TScore.ShowMines(aMines: Integer);
Var
LBitmap : TBitmap;
begin
LBitmap := Images.GetText(aMines.ToString);
ImgMinesCount.Bitmap.Assign(LBitmap);
LBitmap.Free;
end;
procedure TScore.ShowFlags(aFlags: Integer);
Var
LBitmap : TBitmap;
begin
LBitmap := Images.GetText(aFlags.ToString);
ImgFlagCount.Bitmap.Assign(LBitmap);
LBitmap.Free;
end;
procedure TScore.ShowTime(aTime : string);
Var
LBitmap : TBitmap;
begin
LBitmap := Images.GetText(aTime);
ImgTime.Bitmap.Assign(LBitmap);
LBitmap.Free;
end;
procedure TScore.StartTime;
begin
FTime := StrToTime('00:00:00');
FTimeStr := FormatDateTime('hh:nn:ss', Time);
FTimer.Enabled := True;
end;
procedure TScore.StopTime;
begin
FTimer.Enabled := False;
end;
procedure TScore.ResumeTime;
begin
FTimer.Enabled := True;
end;
procedure TScore.UpdateTime(Sender: TObject);
Var
LTime : String;
begin
LTime := FormatDateTime('hh:nn:ss', Now);
If FTimeStr <> LTime Then
Begin
FTimer.Enabled := False;
FTime := FTime + StrToTime('00:00:01');
ShowTime(FormatDateTime('hh:nn:ss', FTime));
FTimer.Enabled := True;
FTimeStr := LTime;
End;
end;
end.