unit Wing;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls, Buttons, ExtCtrls, Spin, MPlayer, FileCtrl;

type
  rec=record
   geo,map,monst:array[0..26,0..26] of integer;
   vid:array[0..26,0..26] of boolean;
   balans:array[0..6] of integer;
   money,nalog,mes,day,god,razmer,date:integer;
   pribl_obshaja,tehno_level,cols,rows:integer;
   level,aim:integer;
   hodil,give_tehno:boolean;
  end;
  TForm1 = class(TForm)
    Label2: TLabel;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton13: TSpeedButton;
    RadioGroup1: TRadioGroup;
    Memo1: TMemo;
    Label1: TLabel;
    StaticText1: TStaticText;
    Label3: TLabel;
    StaticText2: TStaticText;
    Label4: TLabel;
    StaticText3: TStaticText;
    Label5: TLabel;
    StaticText4: TStaticText;
    Bevel1: TBevel;
    Button1: TButton;
    Label6: TLabel;
    StaticText5: TStaticText;
    Label7: TLabel;
    StaticText6: TStaticText;
    Label8: TLabel;
    StaticText7: TStaticText;
    Bevel2: TBevel;
    Label9: TLabel;
    StaticText8: TStaticText;
    ScrollBar1: TScrollBar;
    ScrollBar2: TScrollBar;
    Button2: TButton;
    SaveDialog1: TSaveDialog;
    Button3: TButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    CheckBox1: TCheckBox;
    Label10: TLabel;
    SpinEdit1: TSpinEdit;
    MediaPlayer1: TMediaPlayer;
    FileListBox1: TFileListBox;
    Timer1: TTimer;
    procedure FormShow(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton4MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton5MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton6MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton7MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton8MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton9MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton10MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton11MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton12MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton13Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);
    procedure ScrollBar2Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);
    procedure Button2Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
 cena:array[1..13] of integer=(10,20,30,10,35,40,65,100,150,45,50,60,200);
 pribl:array[1..13] of integer=(1,3,1,0,0,3,12,25,45,0,0,30,60);
 lgota:array[1..13] of integer=(0,0,4,0,6,4,0,0,0,10,15,0,0);
 mes_length:array[1..12] of integer=(30,28,31,30,31,30,31,31,30,31,30,31);
 mes_name:array[1..12] of string=('Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь');
var
  Form1: TForm1;
  game:rec;
  i,j,i1,i2,j1,j2,number,obsh_lgota,chislo:integer;
  v:variant;
  mon:boolean;
  //Play
  Chet_Play_Music:integer;
  mas_Play_Mid:array [0..100] of string;
  play:boolean;

implementation

uses Wing_Menu, Wing_Show, Wing_Die, Wing_Win;

{$R *.DFM}

procedure generator_monster;

procedure new_monster(tip:integer);
var
 x1,y1:integer;
begin
 randomize;
 for i:=1 to 10 do
 begin
  x1:=random(game.razmer-1)+1;
  y1:=random(game.razmer-1)+1;
  if (game.monst[x1,y1]=0)and(game.geo[x1,y1]<5)and(game.vid[x1,y1]=false)then
  begin
   game.monst[x1,y1]:=tip;
   break;
  end;
 end;
end;

begin
 case game.razmer of
 5:begin
    new_monster(1);
    new_monster(1);
   end;
 10:begin
    new_monster(1);
    new_monster(1);
    new_monster(2);
    new_monster(2);
   end;
 15:begin
    new_monster(1);
    new_monster(1);
    new_monster(2);
    new_monster(2);
    new_monster(3);
   end;
 20:begin
    new_monster(1);
    new_monster(1);
    new_monster(1);
    new_monster(2);
    new_monster(2);
    new_monster(2);
    new_monster(3);
   end;
 25:begin
    new_monster(1);
    new_monster(1);
    new_monster(1);
    new_monster(2);
    new_monster(2);
    new_monster(2);
    new_monster(3);
    new_monster(3);
   end;
 end;
end;



procedure ris_money;
var
 s,s1:string;
 long,chislo1:integer;
begin
 //Деньги
 if game.money>9999 then game.money:=9999;
 str(game.money,s1);
 long:=(16-length(s1)) div 2;
 for i:=1 to long do s:=s+' ';
 s:=s+s1;
 for i:=1 to long do s:=s+' ';
 Form1.StaticText1.Caption:=s;
 s:='';
 //Налоги
 chislo:=game.nalog-obsh_lgota;
 if chislo<0 then chislo:=0;
 str(chislo,s1);
 long:=(16-length(s1)) div 2;
 for i:=1 to long do s:=s+' ';
 s:=s+s1;
 for i:=1 to long do s:=s+' ';
 Form1.StaticText5.Caption:=s;
 s:='';
 //Через
 chislo:=7-(game.date mod 7);
 str(chislo,s1);
 long:=(16-length(s1)) div 2;
 for i:=1 to long do s:=s+' ';
 s:=s+s1;
 for i:=1 to long do s:=s+' ';
 Form1.StaticText7.Caption:=s;
 s:='';
 //Баланс
 chislo1:=game.date mod 7;
 chislo:=0;
 if game.date mod 7=0 then
 begin
  for i:=1 to 7 do
  if i=7 then chislo:=chislo+game.balans[0]
  else chislo:=chislo+game.balans[i];
  chislo:=round(chislo/7);
  str(chislo,s1);
  long:=(16-length(s1)) div 2;
  for i:=1 to long do s:=s+' ';
  s:=s+s1;
  for i:=1 to long do s:=s+' ';
  Form1.StaticText6.Caption:=s;
  s:='';
  if (game.tehno_level<13)and(chislo>=cena[game.tehno_level+1])and(game.date mod 7=0)and(game.give_tehno=false) then
  begin
   game.give_tehno:=true;
   game.tehno_level:=game.tehno_level+1;
   case game.tehno_level of
   2:Form1.SpeedButton2.Show;
   3:Form1.SpeedButton3.Show;
   4:Form1.SpeedButton4.Show;
   5:Form1.SpeedButton5.Show;
   6:Form1.SpeedButton6.Show;
   7:Form1.SpeedButton7.Show;
   8:Form1.SpeedButton8.Show;
   9:Form1.SpeedButton9.Show;
   10:Form1.SpeedButton10.Show;
   11:Form1.SpeedButton11.Show;
   12:Form1.SpeedButton12.Show;
   13:Form1.SpeedButton13.Show;
   end;
   Form3.ShowModal;
  end;
 end
 else Form1.StaticText6.Caption:='      ???     ';
 //Прибль
 str(game.pribl_obshaja,s1);
 long:=(16-length(s1)) div 2;
 for i:=1 to long do s:=s+' ';
 s:=s+s1;
 for i:=1 to long do s:=s+' ';
 Form1.StaticText8.Caption:=s;
 s:='';
 //Дата
 str(game.day,s1);
 long:=(16-length(s1)) div 2;
 for i:=1 to long do s:=s+' ';
 s:=s+s1;
 for i:=1 to long do s:=s+' ';
 Form1.StaticText2.Caption:=s;
 s:='';
 s1:=mes_name[game.mes];
 long:=(12-length(s1)) div 2;
 for i:=1 to long do s:=s+' ';
 s:=s+s1;
 for i:=1 to long do s:=s+' ';
 Form1.StaticText3.Caption:=s;
 s:='';
 str(game.god,s1);
 long:=(16-length(s1)) div 2;
 for i:=1 to long do s:=s+' ';
 s:=s+s1;
 for i:=1 to long do s:=s+' ';
 Form1.StaticText4.Caption:=s;
 s:='';
end;

procedure izo;
begin
 Form1.StringGrid1.Color:=clWhite;
 for i:=1 to game.razmer do
 for j:=1 to game.razmer do
 begin
  if (game.vid[i,j]=true)and(game.monst[i,j]>0) then
  Form1.StringGrid1.Color:=clRed;
  if game.vid[i,j]=true then
  begin
   case game.geo[i,j] of
    1:Form1.StringGrid2.Cells[i-1,j-1]:='I';
    2:Form1.StringGrid2.Cells[i-1,j-1]:='P';
    3:Form1.StringGrid2.Cells[i-1,j-1]:='E';
    4:Form1.StringGrid2.Cells[i-1,j-1]:='J';
    5:Form1.StringGrid2.Cells[i-1,j-1]:='M';
    6:Form1.StringGrid2.Cells[i-1,j-1]:='Ф';
   end;
   if game.map[i,j]=0 then Form1.StringGrid1.Cells[i-1,j-1]:=Form1.StringGrid2.Cells[i-1,j-1];
   if game.vid[i,j]=true then
   case game.monst[i,j] of
    1:Form1.StringGrid1.Cells[i-1,j-1]:='m';
    2:Form1.StringGrid1.Cells[i-1,j-1]:='j';
    3:Form1.StringGrid1.Cells[i-1,j-1]:='!';
   end;

  end
  else
  begin
   Form1.StringGrid2.Cells[i-1,j-1]:='s';
   Form1.StringGrid1.Cells[i-1,j-1]:='s';
  end;
 end;
 ris_money;
end;

procedure Hints(n:integer);
var
 obr:string;
 el:integer;
begin
 for i:=1 to 4 do Form1.Memo1.Lines[i]:='';
 number:=n;
 str(cena[n],obr);
 Form1.Memo1.Lines[1]:='Цена = '+obr;
 el:=2;
 if pribl[n]>0 then
 begin
  str(pribl[n],obr);
  Form1.Memo1.Lines[2]:='Прибль = '+obr;
  el:=3;
 end;
 if lgota[n]>0 then
 begin
  str(lgota[n],obr);
  Form1.Memo1.Lines[el]:='Льготы +'+obr;
 end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
 Memo1.Lines[0]:=SpeedButton1.Hint;
 Hints(1);
 number:=1;
 izo;
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
 case RadioGroup1.ItemIndex of
 0:begin
    StringGrid1.Show;
    StringGrid2.Hide;
   end;
 1:begin
   StringGrid1.Hide;
   StringGrid2.Show;
  end;
 end;
 izo;
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
 col,row:integer;
begin
col:=ScrollBar2.Position+(X div (StringGrid1.DefaultColWidth+StringGrid1.GridLineWidth));
row:=ScrollBar1.Position+(Y div (StringGrid1.DefaultRowHeight+StringGrid1.GridLineWidth));
if SpeedButton14.Down=true then
begin
 if (game.map[col+1,row+1]>0)and(game.map[col+1,row+1]<14)and(game.map[col+1,row+1]<14)then
 begin
  game.map[col+1,row+1]:=0;
  game.money:=game.money+5;
  StringGrid1.Cells[col,row]:=StringGrid2.Cells[col,row];
  izo;
 end
 else ShowMessage('Нечего сносить');
end
else
if SpeedButton15.Down=true then
begin
 if (game.money>2)and(game.vid[col+1,row+1]=true) then
 begin
  game.money:=game.money-3;
  for i:=-1 to 1 do
  for j:=-1 to 1 do
  begin
   game.monst[(col+1)+i,(row+1)+j]:=0;
   game.map[(col+1)+i,(row+1)+j]:=0;
   if (col+i>0)and(row+j>0)and(col+i<game.razmer)and(row+j<game.razmer)then StringGrid1.Cells[col+i,row+j]:=StringGrid2.Cells[col+i,row+j];
  end;
  izo;
 end
 else ShowMessage('Взрыв стоит 3! Не хватает денег!');
end
else
if (game.hodil=false)or(SpeedButton4.Down=true) then
begin
if (game.map[col+1,row+1]=0)and(game.geo[col+1,row+1]<5)then
begin
 if game.money>=cena[number] then
 begin
  if game.vid[col+1,row+1]=true then
  begin
   game.money:=game.money-cena[number];
   ris_money;
   if SpeedButton1.Down=true then StringGrid1.Cells[col,row]:=SpeedButton1.Caption;
   if SpeedButton2.Down=true then StringGrid1.Cells[col,row]:=SpeedButton2.Caption;
   if SpeedButton3.Down=true then StringGrid1.Cells[col,row]:=SpeedButton3.Caption;
   if SpeedButton4.Down=true then StringGrid1.Cells[col,row]:=SpeedButton4.Caption;
   if SpeedButton5.Down=true then StringGrid1.Cells[col,row]:=SpeedButton5.Caption;
   if SpeedButton6.Down=true then StringGrid1.Cells[col,row]:=SpeedButton6.Caption;
   if SpeedButton7.Down=true then StringGrid1.Cells[col,row]:=SpeedButton7.Caption;
   if SpeedButton8.Down=true then StringGrid1.Cells[col,row]:=SpeedButton8.Caption;
   if SpeedButton9.Down=true then StringGrid1.Cells[col,row]:=SpeedButton9.Caption;
   if SpeedButton10.Down=true then StringGrid1.Cells[col,row]:=SpeedButton10.Caption;
   if SpeedButton11.Down=true then StringGrid1.Cells[col,row]:=SpeedButton11.Caption;
   if SpeedButton12.Down=true then StringGrid1.Cells[col,row]:=SpeedButton12.Caption;
   if SpeedButton13.Down=true then StringGrid1.Cells[col,row]:=SpeedButton13.Caption;
   if SpeedButton1.Down=true then game.map[col+1,row+1]:=1;
   if SpeedButton2.Down=true then game.map[col+1,row+1]:=2;
   if SpeedButton3.Down=true then game.map[col+1,row+1]:=3;
   if SpeedButton4.Down=true then game.map[col+1,row+1]:=4;
   if SpeedButton5.Down=true then game.map[col+1,row+1]:=5;
   if SpeedButton6.Down=true then game.map[col+1,row+1]:=6;
   if SpeedButton7.Down=true then game.map[col+1,row+1]:=7;
   if SpeedButton8.Down=true then game.map[col+1,row+1]:=8;
   if SpeedButton9.Down=true then game.map[col+1,row+1]:=9;
   if SpeedButton10.Down=true then game.map[col+1,row+1]:=10;
   if SpeedButton11.Down=true then game.map[col+1,row+1]:=11;
   if SpeedButton12.Down=true then game.map[col+1,row+1]:=12;
   if SpeedButton13.Down=true then game.map[col+1,row+1]:=13;
   for i:=(col+1)-1 to (col+1)+1 do
   for j:=(row+1)-1 to (row+1)+1 do
    game.vid[i,j]:=true;
   game.hodil:=true;
   izo;
  end
  else ShowMessage('Нельзя строить на неразведанной территории!');
 end
 else ShowMessage('У вас не хватает денег на постройку этого здание!');
end
else ShowMessage('На этой территории нельзя строить!');
end
else ShowMessage('Вы уже походили.');
end;

procedure TForm1.SpeedButton1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton1.Hint;
 Memo1.Lines[0]:=v;
 Hints(1);
end;

procedure TForm1.SpeedButton2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton2.Hint;
 Memo1.Lines[0]:=v;
 Hints(2);
end;

procedure TForm1.SpeedButton3MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton3.Hint;
 Memo1.Lines[0]:=v;
 Hints(3);
end;

procedure TForm1.SpeedButton4MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton4.Hint;
 Memo1.Lines[0]:=v;
 Hints(4);
end;

procedure TForm1.SpeedButton5MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton5.Hint;
 Memo1.Lines[0]:=v;
 Hints(5);
end;

procedure TForm1.SpeedButton6MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton6.Hint;
 Memo1.Lines[0]:=v;
 Hints(6);
end;

procedure TForm1.SpeedButton7MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton7.Hint;
 Memo1.Lines[0]:=v;
 Hints(7);
end;

procedure TForm1.SpeedButton8MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton8.Hint;
 Memo1.Lines[0]:=v;
 Hints(8);
end;

procedure TForm1.SpeedButton9MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton9.Hint;
 Memo1.Lines[0]:=v;
 Hints(9);
end;

procedure TForm1.SpeedButton10MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton10.Hint;
 Memo1.Lines[0]:=v;
 Hints(10);
end;

procedure TForm1.SpeedButton11MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton11.Hint;
 Memo1.Lines[0]:=v;
 Hints(11);
end;

procedure TForm1.SpeedButton12MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 v:=SpeedButton12.Hint;
 Memo1.Lines[0]:=v;
 Hints(12);
end;

procedure TForm1.SpeedButton13Click(Sender: TObject);
begin
 v:=SpeedButton13.Hint;
 Memo1.Lines[0]:=v;
 Hints(13);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 r,q,napr,aim1,aim2:integer;
begin
 with game do
 begin
  give_tehno:=false;
  date:=date+1;
  day:=day+1;
  if mes=2 then
  begin
   if((day>29)and(god mod 4=0))or((day>28)and(god mod 4<>0))then
   begin
    mes:=mes+1;
    day:=1;
   end;
  end
  else if day>mes_length[mes] then
  begin
   mes:=mes+1;
   day:=1;
  end;
  if mes=13 then
  begin
   god:=god+1;
   mes:=1;
  end;
  case game.aim of
  1:for i:=1 to razmer do
    for j:=1 to razmer do
    if game.map[i,j]=13 then Form5.ShowModal;
  2:if money>=9999 then Form5.ShowModal;
  3:begin
     aim1:=0;
     aim2:=0;
     for i:=1 to razmer do
     for j:=1 to razmer do
     begin
      if game.geo[i,j]<5 then aim1:=aim1+1;
      if game.map[i,j]>0 then aim2:=aim2+1;
     end;
     if aim2>=aim1 then Form5.ShowModal;
    end;
  4:begin
     if mes=7 then
     begin
      Form4.ShowModal;
      Form4.Label4.Show;
     end;
     for i:=1 to 7 do
      if i=7 then chislo:=chislo+game.balans[0]
      else chislo:=chislo+game.balans[i];
     chislo:=round(chislo/7);
     if (game.date mod 7=0)and(chislo>=1000) then Form5.ShowModal;
    end;
   end;
  hodil:=false;
  pribl_obshaja:=0;
  balans[date mod 7]:=0;
  for i:=1 to razmer do
  for j:=1 to razmer do
  begin
   //vid[i,j]:=true;
   if (map[i,j]>0)and(map[i,j]<14) then
   begin
    money:=money+pribl[map[i,j]];
    balans[date mod 7]:=balans[date mod 7]+pribl[map[i,j]];
    pribl_obshaja:=pribl_obshaja+pribl[map[i,j]];
   end;
  end;
  if (date mod SpinEdit1.Value=0)and(CheckBox1.Checked=true)then Button2.Click;
  if date mod 14=0 then
  begin
   nalog:=(nalog*2)+((nalog div 10)*level);
   generator_monster;
  end;
  Form1.StringGrid1.Color:=clWhite;
  obsh_lgota:=0;
  for i:=1 to game.razmer do
  for j:=1 to game.razmer do
  begin
   if (game.vid[i,j]=true)and(game.monst[i,j]>0) then
   Form1.StringGrid1.Color:=clRed;
   if (game.map[i,j]>0)and(game.map[i,j]<14)then
   obsh_lgota:=obsh_lgota+lgota[game.map[i,j]];
   randomize;
   if (game.monst[i,j]>0) then
    for i1:=-1 to 1 do
    for j1:=-1 to 1 do
    if game.map[i+i1,j+j1]=4 then
    begin
     game.monst[i,j]:=0;
     izo;
    end;
   if (game.monst[i,j]>0) then
   begin
    Form1.StringGrid1.Color:=clRed;
    for i1:=-1 to 1 do
    for j1:=-1 to 1 do
    begin
    if game.map[i+i1,j+j1]>0 then
    begin
     if game.monst[i,j]<3 then
     begin
      for i2:=-1 to 1 do
      for j2:=-1 to 1 do
      begin
       game.map[i+i2,j+j2]:=0;
       game.monst[i+i2,j+j2]:=0;
       Form1.StringGrid1.Color:=clWhite;
      end;
     end;
     if game.monst[i,j]=3 then
     for i2:=-1 to 1 do
     for j2:=-1 to 1 do
     if game.map[i+i2,j+j2]>0 then
     begin
      Form1.StringGrid1.Cells[(i-1)+i2,(j-1)+j2]:='"';
      game.map[i+i2,j+j2]:=14;
     end;
    end;
   end;
   end;
   mon:=false;
   for q:=1 to 10 do
   begin
    randomize;
    napr:=random(198)+1;
    case (napr div 25) of
    0:if (mon=false)and(game.map[i-1,j]=0)and(game.monst[i-1,j]=0)and(i-1>0)and(j>0)and(i-1<=game.razmer)and(j<=game.razmer)then
      begin
       game.monst[i-1,j]:=game.monst[i,j];
       game.monst[i,j]:=0;
       mon:=true;
      end;
    1:if (mon=false)and(game.map[i+1,j]=0)and(game.monst[i+1,j]=0)and(i+1>0)and(j>0)and(i+1<=game.razmer)and(j<=game.razmer)then
    begin
       game.monst[i+1,j]:=game.monst[i,j];
       game.monst[i,j]:=0;
       mon:=true;
      end;
    2:if (mon=false)and(game.map[i,j-1]=0)and(game.monst[i,j-1]=0)and(i>0)and(j-1>0)and(i<=game.razmer)and(j<=game.razmer)then
    begin
       game.monst[i,j-1]:=game.monst[i,j];
       game.monst[i,j]:=0;
       mon:=true;
      end;
    3:if (mon=false)and(game.map[i,j+1]=0)and(game.monst[i,j+1]=0)and(i>0)and(j+1>0)and(i<=game.razmer)and(j+1<=game.razmer)then
    begin
       game.monst[i,j+1]:=game.monst[i,j];
       game.monst[i,j]:=0;
       mon:=true;
      end;
    4:if (mon=false)and(game.map[i-1,j-1]=0)and(game.monst[i-1,j-1]=0)and(i-1>0)and(j-1>0)and(i-1<=game.razmer)and(j-1<=game.razmer)then
    begin
       game.monst[i-1,j-1]:=game.monst[i,j];
       game.monst[i,j]:=0;
       mon:=true;
      end;
    5:if (mon=false)and(game.map[i+1,j+1]=0)and(game.monst[i+1,j+1]=0)and(i+1>0)and(j+1>0)and(i+1<=game.razmer)and(j+1<=game.razmer)then
    begin
       game.monst[i+1,j+1]:=game.monst[i,j];
       game.monst[i,j]:=0;
       mon:=true;
      end;
    6:if (mon=false)and(game.map[i-1,j+1]=0)and(game.monst[i-1,j+1]=0)and(i-1>0)and(j+1>0)and(i-1<=game.razmer)and(j+1<=game.razmer)then
    begin
       game.monst[i-1,j+1]:=game.monst[i,j];
       game.monst[i,j]:=0;
       mon:=true;
      end;
    7:if (mon=false)and(game.map[i+1,j-1]=0)and(game.monst[i+1,j-1]=0)and(i+1>0)and(j-1>0)and(i+1<=game.razmer)and(j-1<=game.razmer)then
    begin
       game.monst[i+1,j-1]:=game.monst[i,j];
       game.monst[i,j]:=0;
       mon:=true;
      end;
    end;
    //if game.monst[i,j]=0 then goto l1;
   end;
  end;
  if date mod 7=0 then money:=money-(nalog-obsh_lgota);
  if money<0 then Form4.ShowModal;
 end;
 izo;
end;

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
 Form1.StringGrid1.TopRow:=ScrollBar1.Position;
 Form1.StringGrid2.TopRow:=ScrollBar1.Position;
 game.rows:=ScrollBar1.Position;
end;

procedure TForm1.ScrollBar2Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
  Form1.StringGrid1.LeftCol:=ScrollBar2.Position;
  Form1.StringGrid2.LeftCol:=ScrollBar2.Position;
  game.cols:=ScrollBar2.Position;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 f:file of rec;
begin
 if (SaveDialog1.Execute)and(SaveDialog1.FileName<>'') then
 begin
  AssignFile(f,SaveDialog1.FileName);
  rewrite(f);
  write(f,game);
  CloseFile(f);
 end;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if Key=#32 then Button1.Click;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 Form2.visible:=true;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
 if CheckBox1.Checked=true then SpinEdit1.Enabled:=true
 else SpinEdit1.Enabled:=false;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chet_Play_Music:=0;
  for i:= 0 to FileListBox1.Items.Count-1 do
  begin
    Mas_Play_Mid[i]:= FileListBox1.Items.Strings[i];
  end;
  MediaPlayer1.FileName:=Mas_Play_Mid[0];
  MediaPlayer1.Open;
  MediaPlayer1.play;
  play:=true;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
 if Play=true then
 begin
  if MediaPlayer1.Position>=mediaPlayer1.Length-10 then
  begin
    MediaPlayer1.Stop;
    Chet_Play_Music:=Chet_Play_Music+1;
    if Mas_play_mid[Chet_Play_Music]<>'' then
       MediaPlayer1.FileName:=Mas_play_mid[Chet_Play_Music]
    else
       Chet_Play_Music:=0;
    MediaPlayer1.play;
  end;
 end;
 Timer1.interval:=5;
end;

end.
