|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 xieyuan0553 于 2017-1-19 12:32 编辑
[b][b]unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TFormLight = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Panel7: TPanel;
Panel8: TPanel;
Panel9: TPanel;
Panel10: TPanel;
Panel11: TPanel;
Panel12: TPanel;
Panel13: TPanel;
Panel14: TPanel;
Panel15: TPanel;
Panel16: TPanel;
Panel17: TPanel;
Panel18: TPanel;
Panel19: TPanel;
Panel20: TPanel;
Panel21: TPanel;
Panel22: TPanel;
Panel23: TPanel;
Panel24: TPanel;
Panel25: TPanel;
EditResult: TEdit;
Label1: TLabel;
Hour: TLabel;
Label2: TLabel;
Minute: TLabel;
Label3: TLabel;
Second: TLabel;
Label4: TLabel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
procedure Change(i:Integer);
function CheckWin:Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
FormLight: TFormLight;
p:Array[1..25] of TPanel;
c:Array[1..25] of Boolean;
implementation
{$R *.dfm}
procedure TFormLight.FormCreate(Sender: TObject);
var
i:Integer;
begin
p[1]:=Panel1;p[2]:=Panel2;p[3]:=Panel3;p[4]:=Panel4;p[5]:=Panel5;
p[6]:=Panel6;p[7]:=Panel7;p[8]:=Panel8;p[9]:=Panel9;p[10]:=Panel10;
p[11]:=Panel11;p[12]:=Panel12;p[13]:=Panel13;p[14]:=Panel14;p[15]:=Panel15;
p[16]:=Panel16;p[17]:=Panel17;p[18]:=Panel18;p[19]:=Panel19;p[20]:=Panel20;
p[21]:=Panel21;p[22]:=Panel22;p[23]:=Panel23;p[24]:=Panel24;p[25]:=Panel25;
for i:=1 to 25 do
begin
p[i].Tag:=i;
c[i]:=False;
end;
end;
procedure TFormLight.Change(i:Integer);
begin
c[i]:=Not c[i];
if c[i] then
p[i].Color:=clBlack
else
p[i].Color:=clWhite;
end;
function TFormLight.CheckWin:Boolean;
var
i:Integer;
begin
result:=True;
for i:=1 to 25 do
if not c[i] then
begin
result:=False;
Exit;
end;
end;
procedure TFormLight.Panel1Click(Sender: TObject);
var
i,j:Integer;
begin
i:=TPanel(Sender).Tag;
Change(i);
if i>5 then Change(i-5);
if i<21 then Change(i+5);
if (i mod 5)<>0 then Change(i+1);
if (i mod 5)<>1 then Change(i-1);
if CheckWin then
begin
EditResult.Visible:=True;
Timer1.Enabled:=False;
end;
end;
procedure TFormLight.Timer1Timer(Sender: TObject);
begin
Second.Caption:=IntToStr(StrToInt(Second.Caption)+1);
if Second.Caption='60' then
begin
Second.Caption:='0';
Minute.Caption:=IntToStr(StrToInt(Minute.Caption)+1);
end
else
if Minute.Caption='60' then
begin
Minute.Caption:='0';
Hour.Caption:=IntToStr(StrToInt(Hour.Caption)+1);
end;
end;
end.
这就是我编的“点灯游戏”有以下两个问题:
1.如何编程可以让25个面板控件,最后显示“你赢了”的时候,点了面板控件没有反应。
2.如何编程可以显示我点击面板控件的次数,当最后显示“你赢了”的时候,不在计数。标签LabelStep显示我点击的次数。[/b][/b] |
|