鱼C论坛

 找回密码
 立即注册
查看: 2945|回复: 1

点灯游戏

[复制链接]
发表于 2017-1-19 11:38:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 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[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.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显示我点击的次数。
点灯游戏3.JPG
点灯游戏4.JPG
点灯游戏5.JPG
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-9-19 11:48:04 | 显示全部楼层
学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-28 22:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表