forked from brian-scott-andrews/TurboRisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Move.pas
148 lines (131 loc) · 3.84 KB
/
Move.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
unit Move;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, LMessages, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls, ExtCtrls;
type
TfMove = class(TForm)
panFromTerr: TPanel;
Label1: TLabel;
Label2: TLabel;
panFromArmies: TPanel;
panToTerr: TPanel;
panToArmies: TPanel;
cmdOk: TBitBtn;
cmdCancel: TBitBtn;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
cmdAll: TBitBtn;
cmdBalance: TBitBtn;
procedure FormShow(Sender: TObject);
procedure MoveArmiesClick(Sender: TObject);
procedure cmdOkClick(Sender: TObject);
procedure cmdAllClick(Sender: TObject);
procedure cmdBalanceClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure cmdCancelClick(Sender: TObject);
private
procedure UpdateDisplay;
public
iProv, iDest, iMinDest,
iTf, iTt: integer; // Territori Da e A attacco
end;
var
fMove: TfMove;
implementation
{$R *.lfm}
uses Globals, Main, Territ, Log;
procedure TfMove.FormShow(Sender: TObject);
begin
// posizionamento dinamico finestra
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
iProv := arTerritory[iTf].Army;
iDest := arTerritory[iTt].Army;
iMinDest := iDest;
panFromTerr.Caption := arTerritory[iTf].Name;
panToTerr.Caption := arTerritory[iTt].Name;
UpdateDisplay;
end;
procedure TfMove.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (ModalResult<>mrCancel) and arPlayer[iTurn].KeepLog then
ScriviLog('Troops move (' + IntToStr(arTerritory[iTt].Army-iMinDest)
+ ') from ' + arTerritory[iTf].Name + ' to ' + arTerritory[iTt].Name);
end;
procedure TfMove.UpdateDisplay;
begin
panFromArmies.Caption := IntToStr(iProv);
panToArmies.Caption := IntToStr(iDest);
end;
procedure TfMove.MoveArmiesClick(Sender: TObject);
var
iMove: integer;
begin
iMove := (Sender as TControl).Tag;
if iProv-iMove<1 then iMove := iProv - 1;
if iDest+iMove<iMinDest then iMove := iMinDest - iDest;
dec(iProv,iMove);
inc(idest,iMove);
UpdateDisplay;
end;
procedure TfMove.cmdOkClick(Sender: TObject);
begin
arTerritory[iTf].Army := iProv;
arTerritory[iTt].Army := iDest;
DisplayTerritory(iTf);
DisplayTerritory(iTt);
if arTerritory[iTt].Army=iMinDest then // Se la situazione è quella iniziale
ModalResult := mrCancel // non considero lo spostamento avvenuto
else
ModalResult := mrOK;
end;
procedure TfMove.cmdAllClick(Sender: TObject);
begin
arTerritory[iTf].Army := 1;
arTerritory[iTt].Army := iDest + iProv - 1;
DisplayTerritory(iTf);
DisplayTerritory(iTt);
if arTerritory[iTt].Army=iMinDest then // Se la situazione è quella iniziale
ModalResult := mrCancel // non considero lo spostamento avvenuto
else
ModalResult := mrOK;
end;
procedure TfMove.cmdBalanceClick(Sender: TObject);
var
iBal, iResto: integer;
begin
iBal := (iProv + iDest) div 2;
iResto := (iProv + iDest) mod 2;
iProv := iBal;
iDest := iBal + iResto;
while iDest<iMinDest do begin
inc(iDest);
dec(iProv);
end;
arTerritory[iTf].Army := iProv;
arTerritory[iTt].Army := iDest;
DisplayTerritory(iTf);
DisplayTerritory(iTt);
if arTerritory[iTt].Army=iMinDest then // Se la situazione è quella iniziale
ModalResult := mrCancel; // non considero lo spostamento avvenuto
end;
procedure TfMove.cmdCancelClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
end.