xieyuan0553 发表于 2017-1-19 11:38:48

点灯游戏

本帖最后由 xieyuan0553 于 2017-1-19 12:32 编辑

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 of TPanel;
c:Array of Boolean;

implementation

{$R *.dfm}

procedure TFormLight.FormCreate(Sender: TObject);
var
    i:Integer;
begin
    p:=Panel1;p:=Panel2;p:=Panel3;p:=Panel4;p:=Panel5;
    p:=Panel6;p:=Panel7;p:=Panel8;p:=Panel9;p:=Panel10;
    p:=Panel11;p:=Panel12;p:=Panel13;p:=Panel14;p:=Panel15;
    p:=Panel16;p:=Panel17;p:=Panel18;p:=Panel19;p:=Panel20;
    p:=Panel21;p:=Panel22;p:=Panel23;p:=Panel24;p:=Panel25;
    for i:=1 to 25 do
    begin
      p.Tag:=i;
      c:=False;
    end;
end;

procedure TFormLight.Change(i:Integer);
begin
    c:=Not c;
    if c then
      p.Color:=clBlack
    else
      p.Color:=clWhite;
end;

function TFormLight.CheckWin:Boolean;
var
    i:Integer;
begin
    result:=True;
    for i:=1 to 25 do
      if not c 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显示我点击的次数。

心驰神往 发表于 2020-9-19 11:48:04

学习
页: [1]
查看完整版本: 点灯游戏