📄 main.~pas
字号:
end;
end;
procedure tform1.moveup(select:byte);
begin
case block[select].kind of
1: if (block[select].stry>1) and (map[block[select].strx,block[select].stry-1]=0)
and (map[block[select].strx+1,block[select].stry-1]=0)
then
begin
map[block[select].strx,block[select].stry+1]:=0;
map[block[select].strx+1,block[select].stry+1]:=0;
map[block[select].strx,block[select].stry-1]:=select;
map[block[select].strx+1,block[select].stry-1]:=select;
image1.Canvas.Draw(block[select].strx*40-39,(block[select].stry+1)*40-39,back);
image1.canvas.draw((block[select].strx+1)*40-39,(block[select].stry+1)*40-39,back);
block[select].stry:=block[select].stry-1;
image1.Canvas.Draw(block[select].strx*40-39,block[select].stry*40-39,fk[1]);
end;
2:if (block[select].stry>1) and (map[block[select].strx,block[select].stry-1]=0)
then
begin
map[block[select].strx,block[select].stry+1]:=0;
map[block[select].strx,block[select].stry-1]:=select;
image1.Canvas.Draw(block[select].strx*40-39,(block[select].stry+1)*40-39,back);
block[select].stry:=block[select].stry-1;
image1.Canvas.Draw(block[select].strx*40-39,block[select].stry*40-39,fk[2]);
end;
3:if (block[select].stry>1) and (map[block[select].strx,block[select].stry-1]=0)
then
begin
map[block[select].strx,block[select].stry]:=0;
map[block[select].strx,block[select].stry-1]:=select;
image1.Canvas.Draw(block[select].strx*40-39,(block[select].stry)*40-39,back);
block[select].stry:=block[select].stry-1;
image1.Canvas.Draw(block[select].strx*40-39,block[select].stry*40-39,fk[3]);
end;
4:if (block[select].stry>1) and (map[block[select].strx,block[select].stry-1]=0)
and (map[block[select].strx+1,block[select].stry-1]=0)
then
begin
map[block[select].strx,block[select].stry]:=0;
map[block[select].strx+1,block[select].stry]:=0;
map[block[select].strx,block[select].stry-1]:=select;
map[block[select].strx+1,block[select].stry-1]:=select;
image1.Canvas.Draw(block[select].strx*40-39,(block[select].stry)*40-39,back);
image1.canvas.draw((block[select].strx+1)*40-39,(block[select].stry)*40-39,back);
block[select].stry:=block[select].stry-1;
image1.Canvas.Draw(block[select].strx*40-39,block[select].stry*40-39,fk[4]);
end;
end;
end;
procedure tform1.drawmap(maplx,maply,count:byte);
var i,j,k:byte;
begin
for i:=1 to maplx do
for j:=1 to maply do
begin
map[i,j]:=0;
image1.canvas.Draw(i*40-39,j*40-39,back);
end;
for i:=1 to count do
begin
case block[i].kind of
1:begin
map[block[i].strx,block[i].stry]:=i;
map[block[i].strx+1,block[i].stry]:=i;
map[block[i].strx,block[i].stry+1]:=i;
map[block[i].strx+1,block[i].stry+1]:=i;
end;
2:begin
map[block[i].strx,block[i].stry]:=i;
map[block[i].strx,block[i].stry+1]:=i;
end;
3:begin
map[block[i].strx,block[i].stry]:=i;
end;
4:begin
map[block[i].strx,block[i].stry]:=i;
map[block[i].strx+1,block[i].stry]:=i;
end;
end;
image1.Canvas.Draw(block[i].strx*40-39,block[i].stry*40-39,fk[block[i].kind]);
end;
end;
procedure TForm1.start1Click(Sender: TObject);
var i,j,count:byte;
filename:string;
mapfile:textfile;
begin
filename:='map\map'+inttostr(levl)+'.txt';
assignfile(mapfile,filename);
reset(mapfile);
read(mapfile,maplx,maply,count);
for i:=1 to count do
read(mapfile,block[i].strx,block[i].stry,block[i].kind);
read(mapfile,doorx1,doory1,doorx2,doory2);
closefile(mapfile);
select:=0;
image1.Enabled:=true;
drawmap(maplx,maply,count);
label2.Caption:='第'+inttostr(levl)+'关';
image1.canvas.Pen.color:=clwhite;
image1.Canvas.moveto(1,201);
image1.Canvas.LineTo(162,201);
image1.canvas.Pen.color:=clgreen;
image1.Canvas.moveto(doorx1*40-39,201);
image1.Canvas.LineTo(doorx2*40,201);
label1.Visible:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:byte;
begin
for i:=1 to 4 do
fk[i]:=tbitmap.Create;
fk[1].LoadFromFile('bmp\fk1.bmp');
fk[2].LoadFromFile('bmp\fk2.bmp');
fk[3].LoadFromFile('bmp\fk3.bmp');
fk[4].LoadFromFile('bmp\fk4.bmp');
back:=tbitmap.Create;
back.LoadFromFile('bmp\back.bmp');
maplx:=0;
maply:=0;
mouseoldx:=-1;
mouseoldy:=-1;
levl:=1;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var mapx,mapy:byte;
begin
mapx:=((x-1) div 40)+1;
mapy:=((y-1) div 40)+1;
select:=map[mapx,mapy];
mouseoldx:=x;
mouseoldy:=y;
// if (mapx<=maplx) and (mapy<=maply) and (map[mapx,mapy]<>0) then
// begin
// image1.Cursor:=crhandpoint;
// select:=map[mapx,mapy];
// end
// else
// image1.Cursor:=crcross;
// label1.Caption:=inttostr(mapx)+inttostr(maplx);
// label2.Caption:=inttostr(mapy)+inttostr(maply);
// label3.Caption:=inttostr(map[mapx,mapy]);
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
select:=0;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var mapx,mapy:byte;
dx,dy:integer;
begin
mapx:=((x-1) div 40)+1;
mapy:=((y-1) div 40)+1;
if (mapx<=maplx) and (mapy<=maply) and (map[mapx,mapy]<>0) then
begin
image1.Cursor:=crhandpoint;
// select:=map[mapx,mapy];
end
else
image1.Cursor:=crarrow;
if (mouseoldx<>-1) and (select<>0) then
begin
dx:=x-mouseoldx;
dy:=y-mouseoldy;
if (abs(dx)>10) or (abs(dy)>10) then
begin
if (abs(dx)>abs(dy)) then
if dx>0 then
moveright(select)
else
moveleft(select)
else
if dy>0 then
movedown(select)
else
moveup(select);
mouseoldx:=x;
mouseoldy:=y;
select:=0;
end;
end;
if (map[doorx1,doory1]=2) and (map[doorx2,doory2]=2) then
begin
image1.Enabled:=false;
messagedlg('过关,恭喜你!',mtInformation,[mbOk], 0);
end;
end;
procedure TForm1.exit1Click(Sender: TObject);
begin
if messagedlg('真的退出吗?',mtconfirmation,[mbYes, mbNo], 0) = mrYes then
close;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
form2.showmodal;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
form3.showmodal;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -