- •Часть 1
- •Implementation
- •Implementation
- •Implementation
- •Часть 1
- •Implementation
- •Implementation
- •Implementation
- •IBplementation
- •Implementation
- •Часть 1
- •Implementation
- •Implementation
- •Implementation
- •Implementation
- •Implementation
- •Interface
- •Часть 1
- •Interface
- •Часть 1 I. 104
- •Implementation
- •Implementation
- •Implementation
- •Часть I
- •Р ис. 1.46. Окно программы Звуки Windows
- •Implementation
- •Interface
- •Implementation
- •Interface
- •Implementation
- •Interface
- •Implementation
- •Interface
- •Implementation
- •Implementation
- •Implementation
- •Implementation
- •Implementation
- •Interface
- •Часть 1
- •168 Част
- •Implementation
- •Часть 1
- •Interface uses
- •Implementation
- •Interface
- •Implementation
- •Часть 1
- •Часть 1 I Примеры и задачи
- •Часть 1 I Примеры и задачи
- •Implementation
- •205 Часть
- •Interface
- •Implementation
- •216 Часть 1
- •Поле т ип Размер Информация
- •Часть 1
- •Implementation
- •Interface
- •Implementation
- •Implementation
- •Часть 2 Таблица 2.2 (окончание)
- •252 Часть 2
- •Часть 2 I Delphi — краткий справочник
- •Часть 2
Часть 1
Примеры и задачи
183
if Pole[row+l,col-l] » 9 then к := к + 1;
if Pole[row+1,col] = 9 then к := к + 1;
if Pole[row+1,col+1] = 9 then к := к + 1;
Pole[row,col] := k;
end;
status := 0; // начало игры nMin := 0; // нет обнаруженных мин nFlag := 0; // нет флагов
end;
// рисует мину
Procedure Mina (Canvas : TCanvas; x, у : integer),;
begin
with Canvas do begin
Brush.Color := clGreen;
Pen.Color := clBlack;
Rectangle(x+16,y+26,x+24, y+30) ;
Rectangle(x+8,y+30,x+16,y+34);
Rectangle(x+24,y+30,x+32,y+34) ;
Pie(x+6,y+28,x+34,y+4 4,x+34,y+36,x+6,y+36),
LineTo(x+26,y+32) LineTo(x+32,y+36) LineTo(x+20,y+26) LineTo(x+6,y+28); LineTo(x+34,y+28)
MoveTo(x+12,y+32); MoveTo(x+8,y+36); MoveTo(x+20,y+22); MoveTo(x+8, y+30); MoveTo(x+32,y+30); end;
end;
// рисует флаг
Procedure Flag( Canvas : TCanvas; x, у : integer); var
p : array [0..3] of TPoint
// координаты флажка и // нижней точки древка // буква М
array [0..4] of TPoint;
m begin
// зададим координаты точек флажка р[0].х:=х+4; р[0].у:=у+4; р[1].х:=х+30; р[1].у:=у+12; р[2].х:=х+4; р[2].у:=у+20;
p[3].x:=x+4;
ш[0].х:=х+8; ш[0].у:=у+14; т[1].х:=х+8; т[1].у:=у+8; т[2].х:=х+10; т[2].у:=у+10; т[3].х:=х+12; т[3].у:=у+8; т[4].х:=х+12; т[4].у:=у+14;
with Canvas do begin
// установим цвет кисти и карандаша Brush.Color := clRed; Pen.Color := clRed;
Polygon(p); // флажок
// древко
Pen.Color := clBlack; MoveTo(p[0] .x, p[0] .y); LineTo(p[3] .x, p[3] .y) ;
// буква М
Pen.Color := clWhite;
Polyline(m);
clBlack;
Pen.Color end;
end;
// выбор из меню ? команды О программе procedure TForml.N4Click(Sender: TObject); begin
AboutForm.Top := Trunc(Forml.Top + Fonnl.Height/2 -
AboutForm.Height/2); AboutForm.Left := Trunc(Forml.Left +Forml.Width/2 -
AboutForm.Width/2); AboutForm.ShowModal; end;
procedure TForml.FormlCreate(Sender: TObject);
var
row,col : integer;
begin
// В неотображаемые эл-ты массива, которые соответствуют // клеткам по границе игрового поля, запишем число -3. // Это значение используется функцией Open для завершения // рекурсивного процесса открытия соседних пустых клеток.
184
f or row :=0 to MR+l do
for col :=0 to MC+1 do Pole[row,col] := -3;
NewGameO; // "разбросать" мины Forml.ClientHeight := H*MR + 1; Forml.ClientWidth := W*MC + 1; end;
// нажатие кнопки мыши на игровом поле procedure TForml.FormlMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer) var
row, col : integer; begin
if status = 2 // игра завершена then exit;
if status • О then // первый щелчок status := 1;
// преобразуем координаты мыши -в индексы
// клетки поля
row : = Trunc(y/H) + 1;
col := Trunc(x/W) + 1;
if Button = mbLeft then begin
if Pole[row,col] = 9 then
begin // открыта клетка, в которой есть мина Pole[row,col] := Pole[row, col] + 100; status := 2; // игра закончена ShowPole(Forml.Canvas, status); end else if Pole[row,col] < 9 then
Open(row,col); end else
if Button = mbRight then
if Pole[row,col] > 200 then begin
// уберем флаг и закроем клетку nFlag : = nFlag — 1;
'■ 1асть 1
Pole[row,col] := Pole[row,col] - 200; x := (col-1)* W + 1; у := (row-1)* H + 1; Canvas.Brush.Color : = clLtGray; Canvas.Rectangle(x-l,y-l,x+W,y+H); end else
begin // поставить в клетку флаг nFlag := nFlag + 1; if Pole[row,col] ■ 9
then nMin := nMin + 1; Pole[row,col] := Pole[row,col]+ 200; if (nMin = NM) and (nFlag = NM) then
begin
status := 2; // игра закончена ShowPole(Forml.Canvas, status);
end
else KletkatForml.Canvas, row, col,
status); end;
end;
// выбор меню Новая игра
procedure TForml.NIClick(Sender: TObject);
begin
NewGame();
ShowPole(Forml.Canvas,status) ;
end;
// выбор из меню ? команды Справка procedure TForml.N3Click(Sender: TObject);
begin
// вывести справочную информацию
Winhelp(Forml.Handle,'saper.hlp',HELP_CONTEXT,1)
end;
// обработка события OnPaint
procedure TForml.FormlPaint(Sender: TObject);
begin
// отобразить игровое поле ShowPole(Forml.Canvas, status);
end; end.
//
модуль
формы О программе
\ЪБудильник
187
