Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > Графика и игры
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 08.06.2008, 21:46
kolyanb kolyanb вне форума
Прохожий
 
Регистрация: 08.06.2008
Сообщения: 1
Репутация: 10
По умолчанию lines

делаю игру lines все получилось одного не могу понять это процедура поиска пути для шара findzero объясните как она работает плиз.(кроме удаления я знаю как его делать).
Код:
  Form1: TForm1;
  ar:mas;
  b:mas;
  cvet1:mas;
  cvet2:mas;
  x1,x3: Integer; y1,z: Integer;
  sost:integer;
  cv1,cv2:integer;
  x_q,y_q:integer;
  x_p,y_p:integer;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
for I := 0 to 9 do
  begin
    Image1.Canvas.MoveTo(i*40,0);
    Image1.Canvas.LineTo(i*40,400);
  end;
  for I := 0 to 10 do
  begin
    Image1.Canvas.MoveTo(0,40*i);
    Image1.Canvas.LineTo(360,40*i);
  end;
  newgame;
end;


procedure TForm1.newgame;
var i,j:integer;
begin
for I := 0 to 8 do
  begin
    for j := 0 to 9 do
      ar[i,j]:=0;
      b[i,j]:=0;
      cvet1[i,j]:=clWhite;
      cvet2[i,j]:=clWhite;
  end;
  sost:=1;
  z:=0;
  ris;
end;


procedure TForm1.ris;
var x2,y2:string;
i,k,x3,y3:integer;
begin
k:=0;
repeat
randomize;
case random(4) of
0:begin
Image1.Canvas.Pen.Color:=clred;
Image1.Canvas.Brush.Color:=clred;
end;
1:begin
Image1.Canvas.Pen.Color:=clYellow;
Image1.Canvas.Brush.Color:=clYellow;
end;
2:begin
Image1.Canvas.Pen.Color:=clblue;
Image1.Canvas.Brush.Color:=clblue;
end;
3:begin
Image1.Canvas.Pen.Color:=clgreen;
Image1.Canvas.Brush.Color:=clgreen;
end;
end;
randomize;
  x1:=random(9);
  y1:=random(10);
  x2:=floattostr((x1+0.5)*40);
  y2:=floattostr((y1+0.5)*40);
  x3:=strtoint(x2);
  y3:=strtoint(y2);
  if (ar[x1,y1]=0) and (cvet1[x1,y1]<>clwhite) and ((cvet2[x1,y1]<>clwhite)) then
  begin
  Image1.Canvas.Ellipse(x3+10,y3+10,x3-10,y3-10);
  ar[x1,y1]:=1;

  cvet1[x1,y1]:=Image1.Canvas.Pen.Color;
  cvet2[x1,y1]:=Image1.Canvas.brush.Color;
  k:=k+1;
  z:=z+1;
  end;
until (k=3) or (z=90);
if z=90 then
showmessage('You Lose!!!');
  end;

  procedure Tform1.FindZero(x7,y7:integer);
var i,j:integer;
begin
for i:=x7-1 to x7+1 do
for j:=y7-1 to y7+1 do begin
if (i >= 0) and (i <9) and
   (j >= 0) and (j <10) and (b[i,j]=0) and (ar[i,j]=0) then begin

  if (i=x7-1) and (j=y7-1) then continue;
  if (i=x7+1) and (j=y7-1) then continue;
  if (i=x7+1) and (j=y7+1) then continue;
  if (i=x7-1) and (j=y7+1) then continue;

    b[i,j]:=1;
    FindZero(i,j);
 end;
end;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  var x2,y2:string;
  x4,y4:integer;
  w1,w2,i,j:integer;
  begin
  if (sost=1) then
           begin
x4:=x div 40;
y4:=y div 40;
if ar[x4,y4]=1 then
 begin
Image1.Canvas.Pen.Color:=clWhite;
Image1.Canvas.Brush.Color:=clWhite;
Image1.Canvas.FloodFill(x,y,clBlack,fsBorder);
sost:=0;
cv1:=cvet1[x4,y4];
cv2:=cvet2[x4,y4];
ar[x4,y4]:=0;
cvet1[x4,y4]:=clwhite;
cvet2[x4,y4]:=clwhite;
 for I := 0 to 8 do
     for j := 0 to 9 do
       b[i,j]:=0;
  findzero(x4,y4);
exit;
           end
           else
           exit;
           end;
if sost=0 then
begin
 x4:=x div 40;
 y4:=y div 40;
 if ar[x4,y4]<>1 then
 begin

  x2:=floattostr((x4+0.5)*40);
  y2:=floattostr((y4+0.5)*40);
  x_q:=strtoint(x2);
  y_q:=strtoint(y2);
  if (b[x4,y4]=1) then
              begin
 Image1.Canvas.Pen.Color:=cv1;
 Image1.Canvas.Brush.Color:=cv2;
 Image1.Canvas.Ellipse(x_q+10,y_q+10,x_q-10,y_q-10);
 sost:=1;
 ar[x4,y4]:=1;
 cvet1[x4,y4]:=Image1.Canvas.Pen.Color;
 cvet2[x4,y4]:=Image1.Canvas.Brush.Color;
 ris;
 exit;
              end;
end;
end;
end;


end.
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 13:03.


 

Сайт

Форум

FAQ

RSS лента

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2023

ВКонтакте   Facebook   Twitter