Листинги
if Pole[row,col] < 100 then begin Canvas.Brush.Color: = clLtGray; // не открытые – серые Canvas.Rectangle(x-1,y-1,x+W,y+H); // если игра завершена (status = 2), то показать мины if (status = 2) and (Pole[row,col] = 9) then Mina(Canvas, x, y); exit; end; // открываем клетку Canvas.Brush.Color: = clWhite; // открытые белые Canvas.Rectangle(x-1,y-1,x+W,y+H); if (Pole[row,col] = 100) then exit; // клетка открыта, но она пустая if (Pole[row,col] >= 101) and (Pole[row,col] <= 108) then begin Canvas.Font.Size: = 14; Canvas.Font.Color: = clBlue; Canvas.TextOut(x+3,y+2,IntToStr(Pole[row,col] -100)); exit; end; if (Pole[row,col] >= 200) then Flag(Canvas, x, y); if (Pole[row,col] = 109) then // на этой мине подорвались! begin Canvas.Brush.Color: = clRed; Canvas.Rectangle(x-1,y-1,x+W,y+H); end; if ((Pole[row,col] mod 10) = 9) and (status = 2) then Mina(Canvas, x, y); end; // Показывает поле Procedure ShowPole(Canvas: TCanvas; status: integer); var row,col: integer; begin for row: = 1 to MR do for col: = 1 to MC do Kletka(Canvas, row, col, status); end; // рекурсивная функция открывает текущую и все соседние // клетки, в которых нет мин Procedure Open(row, col: integer); begin if Pole[row,col] = 0 then begin Pole[row,col]: = 100; Kletka(Form1.Canvas, row,col, 1); Open(row,col-1); Open(row-1,col); Open(row,col+1); Open(row+1,col); //примыкающие диагонально Open(row-1,col-1); Open(row-1,col+1); Open(row+1,col-1); Open(row+1,col+1); end else if (Pole[row,col] < 100) and (Pole[row,col] <> -3) then begin Pole[row,col]: = Pole[row,col] + 100; Kletka(Form1.Canvas, row, col, 1); end; end; // новая игра – генерирует новое поле procedure NewGame(); var row,col: integer; // координаты клетки n: integer; // количество поставленных мин k: integer; // кол-во мин в соседних клетках begin // Очистим эл-ты массива, соответствующие клеткам // игрового поля. for row: = 1 to MR do for col: = 1 to MC do Pole[row,col]: = 0; // расставим мины Randomize(); // инициализация ГСЧ n: = 0; // кол-во мин repeat row: = Random(MR) + 1; col: = Random(MC) + 1; if (Pole[row,col] <> 9) then begin Pole[row,col]: = 9; n: = n+1; end;
