program Pacman;
uses
SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, ExtCtrls,
Buttons, Dialogs;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
GridWidth = 20;
GridHeight = 15;
InitialNumDots = 240;
Speed = 200;
var
Form1: TForm1;
Grid: array[1..GridWidth, 1..GridHeight] of Integer;
PacmanX, PacmanY, DotsEaten: Integer;
Direction: Char;
procedure DrawGrid;
var
X, Y: Integer;
begin
with Form1.Image1.Canvas do
begin
Pen.Color := clBlack;
Brush.Color := clWhite;
Rectangle(0, 0, GridWidth * 20, GridHeight * 20);
for X := 1 to GridWidth do
for Y := 1 to GridHeight do
if Grid[X, Y] = 1 then
begin
Brush.Color := clYellow;
Ellipse((X - 1) * 20, (Y - 1) * 20, X * 20, Y * 20);
end;
end;
end;
procedure DrawPacman;
var
X, Y: Integer;
begin
X := PacmanX * 20 + 10;
Y := PacmanY * 20 + 10;
with Form1.Image1.Canvas do
begin
Brush.Color := clYellow;
Pen.Color := clBlack;
case Direction of
'U': Arc(X - 10, Y - 10, X + 10, Y + 10, X, Y - 10, X, Y - 10);
'D': Arc(X - 10, Y - 10, X + 10, Y + 10, X, Y + 10, X, Y + 10);
'L': Arc(X - 10, Y - 10, X + 10, Y + 10, X - 10, Y, X - 10, Y);
'R': Arc(X - 10, Y - 10, X + 10, Y + 10, X + 10, Y, X + 10, Y);
end;
end;
end;
function Wall(X, Y: Integer): Boolean;
begin
Result := (X < 1) or (X > GridWidth) or (Y < 1) or (Y > GridHeight) or
(Grid[X, Y] = 2);
end;
procedure MovePacman;
var
NewX, NewY