Автор работы: Пользователь скрыл имя, 26 Октября 2010 в 17:19, Не определен
Игрушка, созданная на языке Delphi
1..8: case z of
0: if (b2[m,n]<>2) and
(b2[m+1,n+1]<>2) and
(b2[m,n+1]<>2) and
(b2[m-1,n+1]<>2) and
(b2[m-1,n]<>2)and
(b2[m-1,n-1]<>2)and
(b2[m,n-1]<>2) and
(b2[m+1,n-1]<>2) and
(b2[m+2,n-1]<>2) and
(b2[m+2,n+1]<>2) and
(b2[m+2,n]<>2) then begin
for i:=0 to 1 do
b2[m+i,n]:=2;
m2:=m2+1
1: if (b2[m,n]<>2) and
(b2[m-1,n-1]<>2) and
(b2[m-1,n]<>2) and
(b2[m-1,n+1]<>2) and
(b2[m,n-1]<>2)and
(b2[m+1,n+1]<>2)and
(b2[m+1,n]<>2) and
(b2[m+1,n-1]<>2) and
(b2[m+1,n-2]<>2) and
(b2[m-1,n-2]<>2) and
(b2[m,n-2]<>2) then
begin
for i:=0 to 1 do
b2[m,n-i]:=2;
end
end;
9..10: case z of
0: if (b2[m,n]<>2) and
(b2[m-1,n-1]<>2) and
(b2[m-1,n]<>2) and
(b2[m-1,n+1]<>2) and
(b2[m,n-1]<>2)and
(b2[m+1,n+1]<>2)and
(b2[m+1,n]<>2) and
(b2[m+1,n-1]<>2) and
(b2[m+1,n-2]<>2) and
(b2[m-1,n-2]<>2) and
(b2[m,n-2]<>2) then
begin
for i:=0 to 1 do
b2[m,n-i]:=2;
end;
1: if (b2[m,n]<>2) and
(b2[m+1,n+1]<>2) and
(b2[m,n+1]<>2) and
(b2[m-1,n+1]<>2) and
(b2[m-1,n]<>2)and
(b2[m-1,n-1]<>2)and
(b2[m,n-1]<>2) and
(b2[m+1,n-1]<>2) and
(b2[m-2,n-1]<>2) and
(b2[m-2,n+1]<>2) and
(b2[m-2,n]<>2) then
begin
for i:=0 to 1 do
b2[m-i,n]:=2;
m2:=m2+1
end
end
end
end
end;
//подлодки
while m1<4 do begin
m:=random(10)+1;
n:=random(10)+1;
while m1<4 do begin
m:=random(10)+1;
n:=random(10)+1;
if (b2[m,n]<>2) and
(b2[m+1,n+1]<>2) and
(b2[m,n+1]<>2) and
(b2[m-1,n+1]<>2) and
(b2[m-1,n]<>2)and
(b2[m-1,n-1]<>2)and
(b2[m,n-1]<>2) and
(b2[m+1,n-1]<>2) and
(b2[m+1,n]<>2) then begin
b2[m,n]:=2;
m1:=m1+1;
end
end;
end;
end;
procedure TForm1.rastkor(Sender: TObject; Shift: TShiftState; X,
Y: Integer); //расстановка кораблей на поле игрока
begin
image1.Canvas.Brush.Color:=
y1:=(Y div 20)+1;
x1:=(X div 20)+1;
For i:=1 to 10 do
for j:=1 to 10 do
begin
if (b1[i,j]<>2) and (b1[i,j]<>3) and (b1[i,j]<>4) then
begin
b1[i,j]:=0;
image1.Canvas.Rectangle(20*i-
end;
end;
if rot=false
then begin //ротация кораблей
по горизонтали
case k11 of //смотрит какой корабль надо располагать
0: begin if (b1[x1,y1]<>2) then
for i:=0 to 0 do
b1[x1+i,y1]:=1; end;
1: begin if (b1[x1,y1]<>2) and (b1[x1+1,y1]<>2)then
for i:=0 to 1 do begin
b1[x1+i,y1]:=1 end; end;
2: begin if (b1[x1,y1]<>2) and (b1[x1+1,y1]<>2) and (b1[x1+2,y1]<>2) then
for i:=0 to 2 do
b1[x1+i,y1]:=1; end;
3: begin if (b1[x1,y1]<>2) and (b1[x1+1,y1]<>2) and (b1[x1+2,y1]<>2) and (b1[x1+3,y1]<>2) then
for i:=0 to 3 do
b1[x1+i,y1]:=1; end;
end;
For i:=1 to
10 do
//рисует желтым цветом
for j:=1 to 10 do
begin
if (b1[i,j]=1) then
begin
image1.Canvas.Brush.Color:=
image1.Canvas.Rectangle(20*i-
end;
end;
end
else
//ротация кораблей по
begin
case k11 of
0: begin if (b1[x1,y1]<>2) then
for i:=0 to 0 do
b1[x1,y1+i]:=1; end;
1: begin if (b1[x1,y1]<>2) and (b1[x1,y1+1]<>2)then
for i:=0 to 1 do begin
b1[x1,y1+i]:=1 end; end;
2: begin if (b1[x1,y1]<>2) and (b1[x1,y1+1]<>2) and (b1[x1,y1+2]<>2) then
for i:=0 to 2 do
b1[x1,y1+i]:=1; end;
3: begin if (b1[x1,y1]<>2) and (b1[x1,y1+1]<>2) and (b1[x1,y1+2]<>2) and (b1[x1,y1+3]<>2) then
for i:=0 to 3 do
b1[x1,y1+i]:=1; end;
end;
For i:=1 to 10 do
for j:=1 to 10 do
begin
if (b1[i,j]=1) then
begin
image1.Canvas.Brush.Color:=
image1.Canvas.Rectangle(20*i-
end;
end;
end;
end;
procedure TForm1.nash(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); //процедура постановки корабля
begin
x1:=(X div 20)+1;
y1:=(Y div 20)+1;
if k11>=0 then begin //смотрит поставлены все корабли или нет
if button=mbright then begin //производит ротацию корабля по нажатии правой кн мыши
if rot=true then
rot:=false
else
rot:=true;
begin
image1.Canvas.Brush.Color:=
For i:=1 to 10 do //рисует в пустых клетках белые квадрвты
for j:=1 to 10 do
begin
if b1[i,j]<>2 then
begin
b1[i,j]:=0;
image1.Canvas.Rectangle(20*i-
end;
end;
if rot=false
then begin //ротация кораблей
по горизонтали
case k11 of
//смотрит какой корабль
0: begin if (b1[x1,y1]<>2) then
b1[x1,y1]:=1; end;
1: begin if (b1[x1,y1]<>2) and (b1[x1+1,y1]<>2)then
for i:=0 to 1 do begin
b1[x1+i,y1]:=1 end; end;
2: begin if (b1[x1,y1]<>2) and (b1[x1+1,y1]<>2) and (b1[x1+2,y1]<>2) then
for i:=0 to 2 do
b1[x1+i,y1]:=1; end;
3: begin if (b1[x1,y1]<>2) and (b1[x1+1,y1]<>2) and (b1[x1+2,y1]<>2) and (b1[x1+3,y1]<>2) then
for i:=0 to 3 do
b1[x1+i,y1]:=1; end;
end;
For i:=1 to 10 do //рисует желтым цветом корабль(ещё не поставленный)
for j:=1 to 10 do
begin
if (b1[i,j]=1) then
begin
image1.Canvas.Brush.Color:=
image1.Canvas.Rectangle(20*i-
end;
end;