📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils,unit2, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ExtCtrls, StdCtrls, Buttons, ExtDlgs, ComCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
Panel2: TPanel;
Image2: TImage;
Panel3: TPanel;
Image3: TImage;
Panel4: TPanel;
Image4: TImage;
Panel5: TPanel;
Image5: TImage;
Panel6: TPanel;
Image6: TImage;
Panel7: TPanel;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
Panel8: TPanel;
Panel9: TPanel;
Panel10: TPanel;
Image7: TImage;
Image8: TImage;
Image9: TImage;
Image10: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Panel11: TPanel;
Image11: TImage;
Label1: TLabel;
Timer1: TTimer;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
PopupMenu1: TPopupMenu;
N5: TMenuItem;
N8: TMenuItem;
StatusBar1: TStatusBar;
N10: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure N2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure N8Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure N10Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
table=array[1..3]of integer;
tab=array[1..3,1..3] of integer;
var
Form1: TForm1;
bm:tbitmap;
x,y:table;
number:tab;
m:integer;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
//种下随机种子,初始化变量
begin
randomize;
bm:=tbitmap.Create;
form1.DoubleBuffered:=true;
m:=0;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
//释放变量
begin
bm.FreeImage;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
//响应按键操作
begin
if panel1.Caption=''
then begin
if key=vk_up then begin
image1.picture:=image4.picture;
image4.Picture:=nil;
panel1.Caption:=panel4.Caption;
panel4.caption:='';
end;
if key=vk_down then begin
image1.picture:=image10.picture;
image10.Picture:=nil;
panel1.Caption:=panel10.Caption;
panel10.caption:='';
end;
if key=vk_left then begin
image1.picture:=image2.picture;
image2.Picture:=nil;
panel1.Caption:=panel2.Caption;
panel2.caption:='';
end;
end;
if panel2.Caption=''
then begin
if key=vk_up then begin
image2.picture:=image5.picture;
image5.Picture:=nil;
panel2.Caption:=panel5.Caption;
panel5.caption:='';
end;
if key=vk_right then begin
image2.picture:=image1.picture;
image1.Picture:=nil;
panel2.Caption:=panel1.Caption;
panel1.caption:='';
end;
if key=vk_left then begin
image2.picture:=image3.picture;
image3.Picture:=nil;
panel2.Caption:=panel3.Caption;
panel3.caption:='';
end;
end;
if panel3.Caption=''
then begin
if key=vk_up then begin
image3.picture:=image6.picture;
image6.Picture:=nil;
panel3.Caption:=panel6.Caption;
panel6.caption:='';
end;
if key=vk_right then begin
image3.picture:=image2.picture;
image2.Picture:=nil;
panel3.Caption:=panel2.Caption;
panel2.caption:='';
end;
end;
if panel4.Caption=''
then begin
if key=vk_up then begin
image4.picture:=image7.picture;
image7.Picture:=nil;
panel4.Caption:=panel7.Caption;
panel7.caption:='';
end;
if key=vk_down then begin
image4.picture:=image1.picture;
image1.Picture:=nil;
panel4.Caption:=panel1.Caption;
panel1.caption:='';
end;
if key=vk_left then begin
image4.picture:=image5.picture;
image5.Picture:=nil;
panel4.Caption:=panel5.Caption;
panel5.caption:='';
end;
end;
if panel5.Caption=''
then begin
if key=vk_up then begin
image5.picture:=image8.picture;
image8.Picture:=nil;
panel5.Caption:=panel8.Caption;
panel8.caption:='';
end;
if key=vk_down then begin
image5.picture:=image2.picture;
image2.Picture:=nil;
panel5.Caption:=panel2.Caption;
panel2.caption:='';
end;
if key=vk_left then begin
image5.picture:=image6.picture;
image6.Picture:=nil;
panel5.Caption:=panel6.Caption;
panel6.caption:='';
end;
if key=vk_right then begin
image5.picture:=image4.picture;
image4.Picture:=nil;
panel5.Caption:=panel4.Caption;
panel4.caption:='';
end;
end;
if panel6.Caption=''
then begin
if key=vk_up then begin
image6.picture:=image9.picture;
image9.Picture:=nil;
panel6.Caption:=panel9.Caption;
panel9.caption:='';
end;
if key=vk_down then begin
image6.picture:=image3.picture;
image3.Picture:=nil;
panel6.Caption:=panel3.Caption;
panel3.caption:='';
end;
if key=vk_right then begin
image6.picture:=image5.picture;
image5.Picture:=nil;
panel6.Caption:=panel5.Caption;
panel5.caption:='';
end;
end;
if panel7.Caption=''
then begin
if key=vk_down then begin
image7.picture:=image4.picture;
image4.Picture:=nil;
panel7.Caption:=panel4.Caption;
panel4.caption:='';
end;
if key=vk_left then begin
image7.picture:=image8.picture;
image8.Picture:=nil;
panel7.Caption:=panel8.Caption;
panel8.caption:='';
end;
end;
if panel8.Caption=''
then begin
if key=vk_right then begin
image8.picture:=image7.picture;
image7.Picture:=nil;
panel8.Caption:=panel7.Caption;
panel7.caption:='';
end;
if key=vk_down then begin
image8.picture:=image5.picture;
image5.Picture:=nil;
panel8.Caption:=panel5.Caption;
panel5.caption:='';
end;
if key=vk_left then begin
image8.picture:=image9.picture;
image9.Picture:=nil;
panel8.Caption:=panel9.Caption;
panel9.caption:='';
end;
end;
if panel9.Caption=''
then begin
if key=vk_right then begin
image9.picture:=image8.picture;
image8.Picture:=nil;
panel9.Caption:=panel8.Caption;
panel8.caption:='';
end;
if key=vk_down then begin
image9.picture:=image6.picture;
image6.Picture:=nil;
panel9.Caption:=panel6.Caption;
panel6.caption:='';
end;
end;
if panel10.caption=''
then begin
if key=vk_up then begin
image10.picture:=image1.picture;
image1.Picture:=nil;
panel10.Caption:=panel1.Caption;
panel1.Caption:='';
end;
end;
end;
procedure TForm1.N2Click(Sender: TObject);
//打开位图
var
wi,he:integer;
i,j,p,t,r,q:integer;
myrect,otherrect:trect;
timenow:tdatetime;
rox,roy:integer;
begin
openpicturedialog1.Execute;
if openpicturedialog1.FileName<>''
then begin
bm.LoadFromFile(openpicturedialog1.filename);
image11.Picture.Graphic:=bm;
panel11.Width:=panel1.Width+panel2.Width+panel3.Width;
panel11.Height:=panel1.Height+panel4.Height+panel7.Height;
rox:=image11.Width div 3;
roy:=image11.Height div 3;
wi:=bm.Width div 3;
he:=bm.Height div 3;
for i:=1 to 3 do begin
x[i]:=i;y[i]:=i;
end;
for i:=1 to 3 do begin
r:=random(2)+1;
t:=x[i];
x[i]:=x[r];
x[r]:=t;
p:=random(2)+1;
q:=y[i];
y[i]:=y[p];
y[p]:=q;
end;
image1.Canvas.CopyRect(rect(0,0,rox,roy),bm.canvas,rect((x[1]-1)*wi,(y[1]-1)*he,x[1]*wi,y[1]*he));
image2.Canvas.CopyRect(rect(0,0,rox,roy),image11.canvas,rect((x[2]-1)*wi,(y[1]-1)*he,x[2]*wi,y[1]*he));
image3.Canvas.CopyRect(rect(0,0,rox,roy),image11.canvas,rect((x[3]-1)*wi,(y[1]-1)*he,x[3]*wi,y[1]*he));
image4.Canvas.CopyRect(rect(0,0,rox,roy),image11.canvas,rect((x[1]-1)*wi,(y[2]-1)*he,x[1]*wi,y[2]*he));
image5.Canvas.CopyRect(rect(0,0,rox,roy),image11.canvas,rect((x[2]-1)*wi,(y[2]-1)*he,x[2]*wi,y[2]*he));
image6.Canvas.CopyRect(rect(0,0,rox,roy),image11.canvas,rect((x[3]-1)*wi,(y[2]-1)*he,x[3]*wi,y[2]*he));
image7.Canvas.CopyRect(rect(0,0,rox,roy),image11.canvas,rect((x[1]-1)*wi,(y[3]-1)*he,x[1]*wi,y[3]*he));
image8.Canvas.CopyRect(rect(0,0,rox,roy),image11.canvas,rect((x[2]-1)*wi,(y[3]-1)*he,x[2]*wi,y[3]*he));
image9.Canvas.CopyRect(rect(0,0,rox,roy),image11.canvas,rect((x[3]-1)*wi,(y[3]-1)*he,x[3]*wi,y[3]*he));
image10.Picture:=nil;
//储存图片信息
for i:=1 to 3 do begin
for j:=1 to 3 do begin
number[i,j]:=i+(j-1)*3;
end;
end;
panel1.Caption:=inttostr(number[1,1]);
panel2.Caption:=inttostr(number[2,1]);
panel3.Caption:=inttostr(number[3,1]);
panel4.Caption:=inttostr(number[1,2]);
panel5.Caption:=inttostr(number[2,2]);
panel6.Caption:=inttostr(number[3,2]);
panel7.Caption:=inttostr(number[1,3]);
panel8.Caption:=inttostr(number[2,3]);
panel9.Caption:=inttostr(number[3,3]);
panel10.Caption:='';
timenow:=time;
label4.Caption:=timetostr(timenow);
end;
bm.FreeImage;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
//记录时间
var
datetime : TDateTime;
begin
datetime:=time;
label5.Caption:=timetostr(datetime);
end;
procedure TForm1.N8Click(Sender: TObject);//退出程序
begin
close;
end;
procedure TForm1.N5Click(Sender: TObject);
begin
form1.N2.Click;
end;
procedure TForm1.N10Click(Sender: TObject);
begin
Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -