Einzelnen Beitrag anzeigen

nick-1212

Registriert seit: 6. Jun 2004
2 Beiträge
 
#1

snake problem dringend "aufnahme" von futter klapp

  Alt 6. Jun 2004, 16:53
hi ich hab ein kleines problem bei meinem snake programm


Delphi-Quellcode:


unit Usnake;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
procedure kol;
procedure futter;
var

  Form1: TForm1;
  x1,y1,dx1,dy1,n,fx1,fy1 : integer;
  xy:array [1..10,1..2] of integer;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
futter;
x1 := 230;
y1 := 190;
dx1:= 10;
dy1:= 0;
n := 10;

end;

procedure TForm1.Timer1Timer(Sender: TObject);
var i : integer;
begin
 kol;

 for i := n downto 2
 do begin
  xy[i,1] := xy[i-1,1];
  xy[i,2] := xy[i-1,2];

 end;

 xy[1,1] := x1;
 xy[1,2] := y1;


 with image1.canvas do begin
    brush.color := clWhite;
    pen.color := clWhite;
    rectangle(xy[n,1],xy[n,2],xy[n,1]+10,xy[n,2]+10);
end;


 with image1.canvas do begin
     x1:=x1+dx1;
     y1:=y1+dy1;
     brush.color := clBlack;
     pen.color := clBlack;
     rectangle(x1,y1,x1+10,y1+10)
end;

end;

procedure futter;
var fx1,fy1 : integer;
begin
 randomize;
 fx1 := 100;
 fy1 := 100;

 form1.image1.Canvas.Brush.Color := clblue;
 form1.image1.canvas.pen.color := clBlue;
 form1.image1.Canvas.rectangle (fx1 ,fy1 ,fx1 +10 ,fy1 + 10 );
end;

procedure kol;
var i : integer;
begin
if (x1 <= 0) or (y1 <=0) or (x1 >= form1.Image1.Width) or (y1 >= form1.Image1.height)
then begin form1.timer1.enabled := false;
           showmessage ('verloren') ;

end;

if (x1 >= fx1) and (x1 <= (fx1+10))
then
if (y1 >= fy1) and (y1 <= (fy1+10)) then begin


showmessage('Game Over!');
//for i:=n downto 1
// do begin
// if (fx1 = xy[i,1]) and (fy1 = xy[i,2])
// then begin

n := n +1 ;
futter;


end;


for i:= n downto 1
     do begin
     if (x1 = xy[i,1]) and (y1 = xy[i,2])
        then begin
form1.timer1.enabled:=false;
showmessage('Game Over!');

end;
end;
end;
es funktioniert alles bis auf die "aufnahme" des futters. Irgendwas stimmt mit den koordinaten nicht
Ich hoffe ihr könnt mir helfen

das problem befindet sich in dieser zeile :
Delphi-Quellcode:

if (x1 <= 0) or (y1 <=0) or (x1 >= form1.Image1.Width) or (y1 >= form1.Image1.height)
then begin form1.timer1.enabled := false;
           showmessage ('verloren') ;

end;

if (x1 >= fx1) and (x1 <= (fx1+10))
then
if (y1 >= fy1) and (y1 <= (fy1+10)) then begin


showmessage('Game Over!');
//for i:=n downto 1
// do begin
// if (fx1 = xy[i,1]) and (fy1 = xy[i,2])
// then begin

n := n +1 ;
futter;
thx
  Mit Zitat antworten Zitat