Hallo
fange gerade an pacmna zu schreiben, Problem. schon jetzt klappt es nicht mehr.
Pacman verschwindet, wenn das Spiel gestartet wird.
Hier der Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, Menus;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
MainMenu1: TMainMenu;
Spiel1: TMenuItem;
NeuesSpiel1: TMenuItem;
Beenden1: TMenuItem;
Hilfe1: TMenuItem;
Anleitung1: TMenuItem;
Tipps1: TMenuItem;
Highscore1: TMenuItem;
Zeigen1: TMenuItem;
Credits1: TMenuItem;
procedure Spielfeldinitialisierung;
procedure Pacmaninitialisierung;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormActivate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure NeuesSpiel1Click(Sender: TObject);
procedure Start;
procedure Beenden1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
TPacman = record
bodyx,bodyy:integer; //koordinaten von pacman
Richtung:integer; //richtung des pacman
Punkte:integer; //gesammelte punkte
end;
const
north=124;
east=126;
south=125;
west=127;
var
Form1: TForm1;
Pacman:TPacman;
Abbruch:boolean;
implementation
{$R *.DFM}
{------------------------------------------------------------------------------}
procedure TForm1.Spielfeldinitialisierung; //feld für programm
var i:integer;
begin
for i:=0 to 4 do StringGrid1.Cells[i,0]:='M';
for i:=0 to 4 do StringGrid1.Cells[i,4]:='M';
for i:=1 to 3 do StringGrid1.Cells[0,i]:='M';
for i:=1 to 3 do StringGrid1.Cells[4,i]:='M';
StringGrid1.Cells[2,2]:='M';
for i:=1 to 3 do StringGrid1.Cells[i,1]:='f';
for i:=1 to 3 do StringGrid1.Cells[i,3]:='f';
StringGrid1.Cells[1,2]:='f';
StringGrid1.Cells[3,2]:='f';
end;
{------------------------------------------------------------------------------}
procedure TForm1.Pacmaninitialisierung;
begin
Pacman.bodyx:=2;
Pacman.bodyy:=1;
StringGrid1.Cells[Pacman.bodyx,Pacman.bodyy]:='Pacman';
Pacman.Richtung:=west;
end;
{------------------------------------------------------------------------------}
procedure TForm1.FormCreate(Sender: TObject);
begin
Spielfeldinitialisierung;
Pacmaninitialisierung;
end;
{------------------------------------------------------------------------------}
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); // sichtbares Feld
begin
if StringGrid1.Cells[ACol,ARow] = 'M' then
begin
StringGrid1.Canvas.Brush.Color := clblack;
StringGrid1.Canvas.Rectangle(Rect);
end;
if StringGrid1.Cells[ACol,ARow] = 'f' then
begin
StringGrid1.Canvas.Brush.Color := clwhite;
StringGrid1.Canvas.Rectangle(Rect);
end;
if StringGrid1.Cells[ACol,ARow] = 'Pacman' then
begin
StringGrid1.Canvas.Brush.Color := clyellow;
StringGrid1.Canvas.ellipse(Rect);
end;
end;
{------------------------------------------------------------------------------}
procedure TForm1.FormActivate(Sender: TObject);
begin
Spielfeldinitialisierung;
Pacmaninitialisierung;
end;
{------------------------------------------------------------------------------}
procedure TForm1.FormResize(Sender: TObject);
begin
Spielfeldinitialisierung;
Pacmaninitialisierung;
end;
{------------------------------------------------------------------------------}
procedure TForm1.NeuesSpiel1Click(Sender: TObject);
begin
Pacmaninitialisierung;
Spielfeldinitialisierung;
Abbruch:=false;
Start;
end;
{------------------------------------------------------------------------------}
procedure TForm1.Start;
var tot:boolean;
begin
Pacmaninitialisierung;
Spielfeldinitialisierung;
{tot:=false;}
repeat
Application.ProcessMessages;
case Pacman.richtung of // neue position festlegen
north: dec(Pacman.bodyy);
east: inc(Pacman.bodyx);
south: inc(Pacman.bodyy);
west: dec(Pacman.bodyx);
end; //endcase
{if Geist_kontakt
then tot:=true
else}
until Abbruch; {or tot }
end;
{------------------------------------------------------------------------------}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_UP then Pacman.Richtung := north;
if Key = VK_LEFT then Pacman.Richtung := west;
if Key = VK_DOWN then Pacman.Richtung := south;
if Key = VK_RIGHT then Pacman.Richtung := east;
if Key = VK_Escape then Abbruch := true;
end;
{------------------------------------------------------------------------------}
procedure TForm1.Beenden1Click(Sender: TObject);
begin
Application.Terminate;
end;
{------------------------------------------------------------------------------}
end.