seb33000
Messages postés1Date d'inscriptionmardi 29 novembre 2005StatutMembreDernière intervention29 novembre 2005
-
29 nov. 2005 à 15:32
jlen100
Messages postés1606Date d'inscriptionsamedi 10 juillet 2004StatutMembreDernière intervention25 juillet 2014
-
29 nov. 2005 à 16:50
salut, j ai un souci sur la progr de mon serpent, mon prof n a pas su m aider. j ai un message de violation a l execution. le serpent est un peu basic mais pour moi c est pas facile. il doit tester le labyrinthe et doit retrouver le bon chemin la foi suivante. j ai essayé de stocker des valeur dans une liste pour qu il retrouve son chemin et c est depuis ca qu il plante. ma source:
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.enabled := true;
i:=0;
end;
procedure TForm1.Timer1timer(Sender: TObject);
Begin
ratleft := shape1.Left;
rattop := shape1.Top ;
if image3.canvas.Pixels[ratleft,rattop-10] = clblue then begin
timer1.Enabled :=false
end;
//en noir
//aller a droite
if image3.canvas.Pixels[ratleft+10,rattop] = clblack then begin
shape1.Left := shape1.left+10;
shape1.Top := shape1.top;
image3.Canvas.pen.Color := clyellow ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left-10,shape1.top);
image3.Canvas.lineto(shape1.left-10,shape1.top);
stringlist1.add(inttostr(2));inc(i);
end
//aller en bas
else if image3.canvas.Pixels[ratleft,rattop+10] = clblack then begin
shape1.Left := shape1.left;
shape1.Top := shape1.top+10;
image3.Canvas.pen.Color := clyellow ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left,shape1.top-10);
image3.Canvas.lineto(shape1.left,shape1.top-10);
stringlist1.add(inttostr(1));inc(i);
end
//aller a gauche
else if image3.canvas.Pixels[ratleft-10,rattop] = clblack then begin
shape1.Left := shape1.left-10;
shape1.Top := shape1.top;
image3.Canvas.pen.Color := clyellow ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left+10,shape1.top);
image3.Canvas.lineto(shape1.left+10,shape1.top);
stringlist1.add(inttostr(3));inc(i);
end
//aller en haut
else if image3.canvas.Pixels[ratleft,rattop-10] = clblack then begin
shape1.Left := shape1.left;
shape1.Top := shape1.top-10;
image3.Canvas.pen.Color := clyellow ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left,shape1.top+10);
image3.Canvas.lineto(shape1.left,shape1.top+10);
stringlist1.add(inttostr(4));inc(i);
end
//en jaune
//aller a droite
else if image3.canvas.Pixels[ratleft+10,rattop] = clyellow then begin
shape1.Left := shape1.left+10;
shape1.Top := shape1.top;
image3.Canvas.pen.Color := clred ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left-10,shape1.top);
image3.Canvas.lineto(shape1.left-10,shape1.top);
stringlist1.Delete(i);dec(i);
end
else if image3.canvas.Pixels[ratleft,rattop+10] = clyellow then begin
shape1.Left := shape1.left;
shape1.Top := shape1.top+10;
image3.Canvas.pen.Color := clred ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left,shape1.top-10);
image3.Canvas.lineto(shape1.left,shape1.top-10);
stringlist1.Delete(i);dec(i);
end
else if image3.canvas.Pixels[ratleft-10,rattop] = clyellow then begin
shape1.Left := shape1.left-10;
shape1.Top := shape1.top;
image3.Canvas.pen.Color := clred ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left+10,shape1.top);
image3.Canvas.lineto(shape1.left+10,shape1.top);
stringlist1.Delete(i);dec(i);
end
else if image3.canvas.Pixels[ratleft,rattop-10] = clyellow then begin
shape1.Left := shape1.left;
shape1.Top := shape1.top-10;
image3.Canvas.pen.Color := clred ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left,shape1.top+10);
image3.Canvas.lineto(shape1.left,shape1.top+10);
stringlist1.Delete(i);dec(i);
end
{ else if shape1.Left = 480 then
if shape1.Top = 300 then timer1.Enabled := false;
if timer1.enabled = false then showmessage('Coucou SEB!!j''ai trouvé l''entrée!!!');}
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
timer2.Enabled:=true;
i:=0;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
ratleft := shape1.Left;
rattop := shape1.Top ;
if image3.canvas.Pixels[ratleft,rattop-10] = clblue then begin
timer2.Enabled :=false
end;
//en noir
//aller a droite
if stringlist1[i]=inttostr(2) then begin
shape1.Left := shape1.left+10;
shape1.Top := shape1.top;
image3.Canvas.pen.Color := clyellow ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left-10,shape1.top);
image3.Canvas.lineto(shape1.left-10,shape1.top);
inc(i);
end
//aller en bas
else if stringlist1[i]=inttostr(1) then begin
shape1.Left := shape1.left;
shape1.Top := shape1.top+10;
image3.Canvas.pen.Color := clyellow ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left,shape1.top-10);
image3.Canvas.lineto(shape1.left,shape1.top-10);
inc(i);
end
//aller a gauche
else if stringlist1[i]=inttostr(3) then begin
shape1.Left := shape1.left-10;
shape1.Top := shape1.top;
image3.Canvas.pen.Color := clyellow ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left+10,shape1.top);
image3.Canvas.lineto(shape1.left+10,shape1.top);
inc(i);
end
//aller en haut
else if stringlist1[i]=inttostr(4) then begin
shape1.Left := shape1.left;
shape1.Top := shape1.top-10;
image3.Canvas.pen.Color := clyellow ;
image3.canvas.pen.Width:= 15;
image3.Canvas.moveto(shape1.left,shape1.top+10);
image3.Canvas.lineto(shape1.left,shape1.top+10);
inc(i);
end
end;
end.