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

Delphi Sources



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

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

делаю игру lines все получилось одного не могу понять это процедура поиска пути для шара findzero объясните как она работает плиз.(кроме удаления я знаю как его делать).
Код:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  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:27.


 

Сайт

Форум

FAQ

Соглашения

Прочее

 

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