📄 rei_34.pas
字号:
unit Rei_34;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ExtCtrls, StdCtrls;
type
TRei40_34 = class(TForm)
MainMenu1: TMainMenu;
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label7: TLabel;
Edit8: TEdit;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private 定义 }
public
{ Public 定义 }
end;
var
Rei40_34: TRei40_34;
// 定义各种变量(Byte类型、Word类型、LongInt类型)
St, Area, Ptime, Emy: Byte;
Pcen1, Pcen2, Walks: Word;
Wsum, Esum: LongInt;
Base: array[0..19] of Byte = (
0,0, 0,1, 2,1, 2,2, 3,2, 3,3, 4,3, 4,4, 5,5, 6,6
);
Ememo: array[0..9] of Byte = (
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
);
implementation
{$R *.DFM}
procedure TRei40_34.FormCreate(Sender: TObject);
begin
// 设定Form属性
Rei40_34.Height := 480;
Rei40_34.Width := 640;
Panel1.Width := 350;
Label1.Height := 23;
Label1.Left := 30;
Label1.Top := 20;
Label1.Width := 100;
Label2.Height := 23;
Label2.Left := 30;
Label2.Top := 60;
Label2.Width := 100;
Label3.Height := 23;
Label3.Left := 30;
Label3.Top := 100;
Label3.Width := 100;
Label4.Height := 23;
Label4.Left := 30;
Label4.Top := 140;
Label4.Width := 100;
Label5.Height := 23;
Label5.Left := 30;
Label5.Top := 180;
Label5.Width := 100;
Label6.Height := 23;
Label6.Left := 30;
Label6.Top := 300;
Label6.Width := 100;
Label7.Height := 23;
Label7.Left := 30;
Label7.Top := 380;
Label7.Width := 100;
Edit1.Height := 23;
Edit1.Left := 144;
Edit1.Top := 20;
Edit1.Width := 121;
Edit2.Height := 23;
Edit2.Left := 144;
Edit2.Top := 60;
Edit2.Width := 121;
Edit3.Height := 23;
Edit3.Left := 144;
Edit3.Top := 100;
Edit3.Width := 121;
Edit4.Height := 23;
Edit4.Left := 144;
Edit4.Top := 140;
Edit4.Width := 121;
Edit5.Height := 23;
Edit5.Left := 144;
Edit5.Top := 180;
Edit5.Width := 121;
Edit6.Height := 31;
Edit6.Left := 60;
Edit6.Top := 240;
Edit6.Width := 235;
Edit7.Height := 23;
Edit7.Left := 30;
Edit7.Top := 330;
Edit7.Width := 290;
Edit8.Height := 23;
Edit8.Left := 144;
Edit8.Top := 380;
Edit8.Width := 121;
Button1.Height := 60;
Button1.Left := 450;
Button1.Top := 20;
Button1.Width := 130;
Button2.Height := 60;
Button2.Left := 450;
Button2.Top := 100;
Button2.Width := 130;
Button3.Height := 60;
Button3.Left := 450;
Button3.Top := 180;
Button3.Width := 130;
// 变量的初始设定
Randomize;
St := 0;
Area := 0;
Walks := 0;
Wsum := 0;
Esum := 0;
Pcen1 := Base[Area * 2];
Ptime := Base[Area * 2 + 1];
Pcen2 := Pcen1 + Ptime * Walks;
end;
procedure TRei40_34.Timer1Timer(Sender: TObject);
var
// 定义局部变量
n: Byte;
begin
// 前进与敌军出现之检查
if St = 1 then
begin
Walks := Walks + 1;
Edit4.Text := ' ' + IntToStr(Walks);
Pcen2 := Pcen1 + Ptime * Walks;
Edit5.Text := ' ' + FloatToStr(Pcen2 / 10) + '%';
Edit6.Text := ' ';
if Random(1000) < Pcen2 then
begin
Emy := Random(9) + 1;
Edit6.Text := '敌军' + IntToStr(Emy) + '出现了!';
for n := 8 downto 0 do
Ememo[n + 1] := Ememo[n];
Ememo[0] := Walks;
n := 0;
Edit7.Text := ' ';
repeat
Edit7.Text := Edit7.Text + ' ' + IntToStr(Ememo[n]);
n := n + 1;
until (n = 10) or (Ememo[n] = 0);
Wsum := Wsum + Walks;
Esum := Esum + 1;
Edit8.Text := ' ' + IntToStr(Wsum div Esum) + '步';
Walks := 0;
St := 0;
end;
end;
end;
procedure TRei40_34.Button1Click(Sender: TObject);
begin
// 前进/停止的指定
St := St xor 1;
end;
procedure TRei40_34.Button2Click(Sender: TObject);
begin
// 局部层次的变更
St := 0;
if Area < 9 then
Area := Area + 1
else
Area := 0;
Pcen1 := Base[Area * 2];
Ptime := Base[Area * 2 + 1];
Pcen2 := Pcen1 + Ptime * Walks;
Edit1.Text := ' ' + IntToStr(Area);
Edit2.Text := ' ' + IntToStr(Pcen1);
Edit3.Text := ' ' + IntToStr(Ptime);
Edit4.Text := ' ' + IntToStr(Walks);
Edit5.Text := ' ' + FloatToStr(Pcen2 / 10) + '%';
end;
procedure TRei40_34.Button3Click(Sender: TObject);
begin
// Reset
St := 0;
Walks := 0;
Wsum := 0;
Esum := 0;
Pcen1 := Base[Area * 2];
Ptime := Base[Area * 2 + 1];
Pcen2 := Pcen1 + Ptime * Walks;
Ememo[0] := 0;
Edit1.Text := ' ' + IntToStr(Area);
Edit2.Text := ' ' + IntToStr(Pcen1);
Edit3.Text := ' ' + IntToStr(Ptime);
Edit4.Text := ' ' + IntToStr(Walks);
Edit5.Text := ' ' + FloatToStr(Pcen2 / 10) + '%';
Edit6.Text := ' ';
Edit7.Text := ' ';
Edit8.Text := ' ';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -