-
Notifications
You must be signed in to change notification settings - Fork 3
/
Attack.pas
236 lines (215 loc) · 5.74 KB
/
Attack.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
unit Attack;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, LMessages, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;
type
{ TfAttack }
TfAttack = class(TForm)
panFromTerr: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
panFromArmies: TPanel;
panFromPlayer: TPanel;
panFromColor: TPanel;
panToTerr: TPanel;
panToArmies: TPanel;
panToPlayer: TPanel;
panToColor: TPanel;
cmdAttack: TBitBtn;
cmdRetreat: TBitBtn;
cmdDoOrDie: TBitBtn;
chkAutoMoveAll: TCheckBox;
cmdAttackUntil1: TBitBtn;
cboUntil1: TComboBox;
lblUntil1: TLabel;
cmdAttackUntil2: TBitBtn;
lblUntil2: TLabel;
cboUntil2: TComboBox;
procedure FormShow(Sender: TObject);
procedure cmdAttackClick(Sender: TObject);
procedure cmdDoOrDieClick(Sender: TObject);
procedure cmdAttackUntil1Click(Sender: TObject);
procedure cmdAttackUntil2Click(Sender: TObject);
procedure cboUntilKeyPress(Sender: TObject; var Key: Char);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure cmdCancel(Sender: TObject);
private
procedure UpdateDisplay;
public
iTf, iTt: integer; // Territori Da e A attacco
end;
var
fAttack: TfAttack;
implementation
{$R *.lfm}
uses Globals, Main, Territ, Stats;
procedure TfAttack.FormShow(Sender: TObject);
begin
// size and controls depend on preferences
if bPrefExpertAttack then begin
cmdAttackUntil1.Visible := true;
cmdAttackUntil2.Visible := true;
lblUntil1.Visible := true;
lblUntil2.Visible := true;
cboUntil1.Visible := true;
cboUntil2.Visible := true;
Height := 254;
end
else begin
cmdAttackUntil1.Visible := false;
cmdAttackUntil2.Visible := false;
lblUntil1.Visible := false;
lblUntil2.Visible := false;
cboUntil1.Visible := false;
cboUntil2.Visible := false;
Height := 186;
end;
// dynamic window position
if arTerritory[iTf].Coord.X > fMain.Width div 2 then
Left := fMain.Left + 18
else
Left := fMain.Left + 338;
if arTerritory[iTf].Coord.Y > fMain.Height div 2 then
Top := fMain.Top + 70
else
Top := fMain.Top + 290;
// inizializzazione controlli
panFromTerr.Caption := arTerritory[iTf].Name;
panFromPlayer.Caption := arPlayer[iTurn].Name;
panFromColor.Color := arPlayer[iTurn].Color;
panToTerr.Caption := arTerritory[iTt].Name;
panToPlayer.Caption := arPlayer[arTerritory[iTt].Owner].Name;
panToColor.Color := arPlayer[arTerritory[iTt].Owner].Color;
UpdateDisplay;
end;
procedure TfAttack.FormKeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'A','a':
cmdAttackClick(Sender);
'D','d':
cmdDoOrDieClick(Sender);
'R','r':
ModalResult := mrCancel;
'M','m':
cmdAttackUntil1Click(Sender);
'E','e':
cmdAttackUntil2Click(Sender);
end;
end;
procedure TfAttack.UpdateDisplay;
begin
panFromArmies.Caption := IntToStr(arTerritory[iTf].Army);
panToArmies.Caption := IntToStr(arTerritory[iTt].Army);
cmdAttack.Enabled := (arTerritory[iTf].Army > 1);
cmdDoOrDie.Enabled := cmdAttack.Enabled;
end;
procedure TfAttack.cboUntilKeyPress(Sender: TObject; var Key: Char);
begin
if not(Key in ['0' .. '9', #08]) then
Key := #0;
end;
procedure TfAttack.cmdAttackClick(Sender: TObject);
begin
if PerformAttack(iTf, iTt) then begin
if chkAutoMoveAll.Checked then begin
inc(arTerritory[iTt].Army, arTerritory[iTf].Army - 1);
arTerritory[iTf].Army := 1;
DisplayTerritory(iTf);
DisplayTerritory(iTt);
UpdateStats;
end;
ModalResult := mrOK;
end
else begin
UpdateDisplay;
end;
end;
procedure TfAttack.cmdDoOrDieClick(Sender: TObject);
var
bConquista: boolean;
begin
repeat
bConquista := PerformAttack(iTf, iTt);
UpdateDisplay;
Application.ProcessMessages;
until bConquista or (arTerritory[iTf].Army < 2);
if bConquista then begin
if chkAutoMoveAll.Checked then begin
inc(arTerritory[iTt].Army, arTerritory[iTf].Army - 1);
arTerritory[iTf].Army := 1;
DisplayTerritory(iTf);
DisplayTerritory(iTt);
UpdateStats;
end;
ModalResult := mrOK;
end
else begin
ModalResult := mrCancel;
end;
end;
procedure TfAttack.cmdAttackUntil1Click(Sender: TObject);
var
bConquista: boolean;
iTarget: integer;
begin
bConquista := false;
iTarget := StrToIntDef(cboUntil1.Text, 0);
while not bConquista and (arTerritory[iTf].Army >= 2) and
(arTerritory[iTf].Army > iTarget) do begin
bConquista := PerformAttack(iTf, iTt);
UpdateDisplay;
Application.ProcessMessages;
end;
if bConquista then begin
if chkAutoMoveAll.Checked then begin
inc(arTerritory[iTt].Army, arTerritory[iTf].Army - 1);
arTerritory[iTf].Army := 1;
DisplayTerritory(iTf);
DisplayTerritory(iTt);
UpdateStats;
end;
ModalResult := mrOK;
end
else begin
ModalResult := mrCancel;
end;
end;
procedure TfAttack.cmdAttackUntil2Click(Sender: TObject);
var
bConquista: boolean;
iTarget: integer;
begin
bConquista := false;
iTarget := StrToIntDef(cboUntil2.Text, 0);
while not bConquista and (arTerritory[iTf].Army >= 2) and
(arTerritory[iTt].Army > iTarget) do begin
bConquista := PerformAttack(iTf, iTt);
UpdateDisplay;
Application.ProcessMessages;
end;
if bConquista then begin
if chkAutoMoveAll.Checked then begin
inc(arTerritory[iTt].Army, arTerritory[iTf].Army - 1);
arTerritory[iTf].Army := 1;
DisplayTerritory(iTf);
DisplayTerritory(iTt);
UpdateStats;
end;
ModalResult := mrOK;
end
else begin
ModalResult := mrCancel;
end;
end;
procedure TfAttack.cmdCancel(Sender: TObject);
begin
ModalResult := mrCancel;
end;
end.