xieyuan0553 发表于 2015-2-12 13:24:00

点灯游戏

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;

type
TForm1 = 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;
    procedure FormCreate(Sender: TObject);
    procedure Change(i:Integer);
    function CheckWin:Boolean;
    procedure Panel1Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;

var
    Form1: TForm1;
    p:Array of TPanel;
    c:Array of Boolean;
implementation
function TForm1.CheckWin:Boolean;
var
    i:Integer;
begin
    result:=True;
    for i:=1 to 25 do
      if not c then
      begin
            Result:=False;
            exit;
      end;
end;

{$R *.dfm}

procedure TForm1.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 TForm1.Change(i:Integer);
begin
    c:=Not c;
    if c then
      p.Color:=clBlack
    else
      p.Color:=clWhite;
end;



procedure TForm1.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 ShowMessage('<span style="font-family: 宋体; ">你赢了!</span>');
页: [1]
查看完整版本: 点灯游戏