unit Wing_Menu;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Buttons;

type
  TForm2 = class(TForm)
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    Label1: TLabel;
    RadioGroup2: TRadioGroup;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    RadioGroup3: TRadioGroup;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Bevel1: TBevel;
    Label10: TLabel;
    Label11: TLabel;
    BitBtn1: TBitBtn;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  i,j:integer;
  Top1,PlusLabel:integer;

implementation

uses Wing;

{$R *.DFM}
procedure generator_monster;

procedure new_monster(tip:integer);
var
 x1,y1:integer;
 s,s1:string;
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;
   str(x1,s);
   str(y1,s1);
   Form1.Memo1.Lines[1]:=s+' '+s1;
   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 TForm2.Button1Click(Sender: TObject);
var
 razm:integer;
begin
 //My cod
  if RadioGroup2.ItemIndex=0 then
  begin
   game.date:=1;
   game.nalog:=6;
   game.money:=50;
  end;
  if RadioGroup2.ItemIndex=1 then
  begin
   game.date:=1;
   game.nalog:=8;
   game.money:=50;
  end;
  if RadioGroup2.ItemIndex=2 then
  begin
   game.date:=1;
   game.nalog:=10;
   game.money:=50;
  end;
 //End my cod
 razm:=(RadioGroup1.ItemIndex+1)*5;
 if razm>5 then
 begin
  Form1.ScrollBar1.Max:=razm-7;
  Form1.ScrollBar2.Max:=razm-9;
 end
 else
 begin
  Form1.ScrollBar1.Hide;
  Form1.ScrollBar2.Hide;
 end;
 {SetLength(game.geo,razm,razm);
 SetLength(game.map,razm,razm);}
 Form1.StringGrid1.ColCount:=razm;
 Form1.StringGrid1.RowCount:=razm;
 Form1.StringGrid2.ColCount:=razm;
 Form1.StringGrid2.RowCount:=razm;
 randomize;
 for i:=1 to razm do
 for j:=1 to razm do
 begin
  game.geo[i,j]:=(random(59) div 10)+1;
  game.vid[i,j]:=false;
 end;
 for i:=1 to 3 do
 for j:=1 to 3 do
 begin
  if (game.geo[i,j]=5)or(game.geo[i,j]=6)then game.geo[i,j]:=2;
  game.vid[i,j]:=true;
 end;
 game.map[2,2]:=1;
 Form1.StringGrid1.Cells[1,1]:='Q';
 game.razmer:=razm;
 game.pribl_obshaja:=1;
 game.day:=1;
 game.mes:=1;
 game.god:=1;
 game.hodil:=false;
 game.tehno_level:=1;
 game.level:=RadioGroup2.ItemIndex;
 game.aim:=RadioGroup3.ItemIndex+1;
 Generator_Monster;
 form2.visible:=false; // <-- Pravka
 Form1.ShowModal;
end;

procedure TForm2.Button2Click(Sender: TObject);
var
 f:file of rec;
begin
 if (OpenDialog1.Execute)and(OpenDialog1.FileName<>'') then
 begin
  AssignFile(f,OpenDialog1.FileName);
  reset(f);
  read(f,game);
  CloseFile(f);
  Form1.StringGrid1.LeftCol:=game.cols;
  Form1.StringGrid1.TopRow:=game.rows;
  Form1.StringGrid2.LeftCol:=game.cols;
  Form1.StringGrid2.TopRow:=game.rows;
  Form1.ScrollBar1.Position:=game.rows;
  Form1.ScrollBar2.Position:=game.cols;
  Form1.StringGrid1.ColCount:=game.razmer;
  Form1.StringGrid1.RowCount:=game.razmer;
  Form1.StringGrid2.ColCount:=game.razmer;
  Form1.StringGrid2.RowCount:=game.razmer;
  for i:=1 to game.razmer do
  for j:=1 to game.razmer do
  begin
   if game.map[i,j]>0 then
   case game.map[i,j] of
   1:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton1.Caption;
   2:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton2.Caption;
   3:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton3.Caption;
   4:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton4.Caption;
   5:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton5.Caption;
   6:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton6.Caption;
   7:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton7.Caption;
   8:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton8.Caption;
   9:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton9.Caption;
   10:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton10.Caption;
   11:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton11.Caption;
   12:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton12.Caption;
   13:Form1.StringGrid1.Cells[i-1,j-1]:=Form1.SpeedButton13.Caption;
   end;
  end;
  for i:=1 to game.razmer do
  for j:=1 to game.razmer do
  if (game.map[i,j]>0)and(game.map[i,j]<14)then
  obsh_lgota:=obsh_lgota+lgota[game.map[i,j]];
  if game.tehno_level>1 then Form1.SpeedButton2.Show;
  if game.tehno_level>2 then Form1.SpeedButton3.Show;
  if game.tehno_level>3 then Form1.SpeedButton4.Show;
  if game.tehno_level>4 then Form1.SpeedButton5.Show;
  if game.tehno_level>5 then Form1.SpeedButton6.Show;
  if game.tehno_level>6 then Form1.SpeedButton7.Show;
  if game.tehno_level>7 then Form1.SpeedButton8.Show;
  if game.tehno_level>8 then Form1.SpeedButton9.Show;
  if game.tehno_level>9 then Form1.SpeedButton10.Show;
  if game.tehno_level>10 then Form1.SpeedButton11.Show;
  if game.tehno_level>11 then Form1.SpeedButton12.Show;
  if game.tehno_level>12 then Form1.SpeedButton13.Show;
  Form1.ShowModal;
 end;
end;

procedure TForm2.BitBtn1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
  if Form2.Visible=true then
  begin
    if label1.left<-480 then PlusLabel:=-1;
    if label1.left>-1 then PlusLabel:=+1;

    Label1.left:=label1.left-PlusLabel;

    if label7.Top=78 then top1:=1;
    if label7.Top=48 then top1:=0;
    if top1=1 then
    begin
      label3.Top:=label3.Top+1;
      label4.Top:=label4.Top+1;

      label6.Top:=label6.Top-1;
      label7.Top:=label7.Top-1;
    end
    else
    begin
      label3.Top:=label3.Top-1;
      label4.Top:=label4.Top-1;

      label6.Top:=label6.Top+1;
      label7.Top:=label7.Top+1;
    end;
  end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  top1:=1; PlusLabel:=-1;
end;


procedure TForm2.FormActivate(Sender: TObject);
begin
if ParamCount <1 then
begin
  ShowMessage('Запуск программы невозможен! Вы запускаете ее не из менеджера "ЮСВ"!');
  Close;
end
else
begin
  if ParamStr(1)<>'Ponomarev&Azanov' then
  begin
    ShowMessage('Запуск программы невозможен! Вы запускаете ее не из менеджера "ЮСВ"!');
    close;
  end;
end;

end;

end.
