1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ImgList, ExtCtrls;
const
Map: array[0..9,0..9] of Byte =
(
(0,0,0,0,0,0,0,0,0,0),
(0,1,1,1,1,1,1,1,1,0),
(0,1,0,0,0,0,0,0,1,0),
(0,1,1,1,1,1,1,1,1,0),
(0,1,0,1,0,0,1,0,1,0),
(0,1,0,1,0,0,1,0,1,0),
(0,1,1,1,1,1,1,1,1,0),
(0,1,0,0,0,0,0,0,1,0),
(0,1,1,1,1,1,1,1,1,0),
(0,0,0,0,0,0,0,0,0,0)
);
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
ImageList1: TImageList;
procedure PaintBox1Paint(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
PosX, PosY: Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
x,y: integer;
begin
for y:=0 to 9 do begin
for x:=0 to 9 do begin
imagelist1.Draw(PaintBox1.Canvas,x * 20,y * 20, Map[y,x]);
end;
end;
imagelist1.draw(PaintBox1.Canvas,Posx * 20,Posy * 20, 2);
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_LEFT:
if Map[PosY, PosX-1] <> 0 then
Dec(PosX);
VK_RIGHT:
if Map[PosY, PosX+1] <> 0 then
Inc(PosX);
VK_UP:
if Map[PosY-1, PosX] <> 0 then
Dec(PosY);
VK_DOWN:
if Map[PosY+1, PosX] <> 0 then
Inc(PosY);
end;
PaintBox1Paint(Self);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PosX := 1;
PosY := 1;
end; |