퍼즐게일을만들려고 하는데 많이 어럽네요
먼저 버튼제어한다음 버튼16번이 렌덤으로 capton을 섞어주는건데
이상하게 위으버튼1~15번사이의 버튼을누르지 안으면 실행이 되지않고....
(위버튼을 한번누르고나면 렌덤은 실행이됨)
전에 되건 자리 바꾸기가 되지 않내요....(렌덤함수를 넣은다음부터)
이상하게 버튼2,5를 누른후에는 렌덤도 되고 이동도되는군요....
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Help1: TMenuItem;
New1: TMenuItem;
Pstop1: TMenuItem;
Restart1: TMenuItem;
Bast1: TMenuItem;
N1: TMenuItem;
End1: TMenuItem;
Imforation1: TMenuItem;
About1: TMenuItem;
Button16: TButton;
Button17: TButton;
Timer1: TTimer;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button8: TButton;
Button7: TButton;
Button6: TButton;
Button5: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button18: TButton;
Button15: TButton;
Button14: TButton;
Button13: TButton;
procedure End1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
private
{ Private declarations }
bbutton : array[0..15] of tbutton;
public
{ Public declarations }
end;
var
Form1: TForm1;
lf, tp : integer;
implementation
{$R *.DFM}
procedure TForm1.End1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,a : integer;
flag : boolean;
begin
bbutton[0] := button1;
bbutton[1] := button2;
bbutton[2] := button3;
bbutton[3] := button4;
bbutton[4] := button5;
bbutton[5] := button6;
bbutton[6] := button7;
bbutton[7] := button8;
bbutton[8] := button9;
bbutton[9] := button10;
bbutton[10] := button11;
bbutton[11] := button12;
bbutton[12] := button13;
bbutton[13] := button14;
bbutton[14] := button15;
bbutton[15] := button18;
j := (sender as tbutton).tag;
flag := false;
if ((bbutton[j].Left) = lf) and ((bbutton[j].top - 50) = tp) then flag := true;
if ((bbutton[j].Left) = lf) and ((bbutton[j].top + 50) = tp) then flag := true;
if ((bbutton[j].Left + 50) = lf) and ((bbutton[j].top) = tp) then flag := true;
if ((bbutton[j].Left - 50) = lf) and ((bbutton[j].top) = tp) then flag := true;
if not flag then exit;
for i := 0 to 15 do
begin
if bbutton[i].visible = false then
begin
bbutton[i].caption := bbutton[j].caption;
bbutton[i].visible := true;
bbutton[j].visible := false;
lf := bbutton[j].Left;
tp := bbutton[j].top;
end;
end;
end;
procedure TForm1.Button16Click(Sender: TObject);
var
i,ko, kl : integer;
swap: string;
begin
randomize;
for i := 0 to 15 do
begin
ko := random(15);
kl := random(15);
swap := bbutton[ko].caption;
bbutton[ko].caption:= bbutton[kl].caption;
bbutton[kl].caption:= swap;
end;
end;
end.