unit uGame;
///////////////////////
// версия 0,6
///////////////////////
// гл. игровой модуль
///////////////////////

interface

uses uGeneralData,uGameTask,OMEGA;

procedure GameDraw;
procedure GameInit;
procedure GameProcess;

procedure NewGame;
procedure LoadGame;
procedure SaveGame;
procedure GameContinue;
procedure GoToMenu;

var Player:TPlayer;

    CmplxLvl:tCmplxLvl;

    gamestart,gamepause,trening,smalltask,EndTaskB:boolean;

    GameTasks:tGameTaskSequence;

    rezult,eror,speed:integer;

{    desktop_fon:PTexture;}

implementation

uses uGUI,uMenu,uEndTask,uGame1,uGame2,uGame3,uGame4,uGame5,uGame6;

procedure GameInit;
begin

endtaskb:=false;

{desktop_fon:=Tex_CreateZero(scrw-158,scrh,TEX_DEFAULT_2D);
Tex_BeginRenderIn(desktop_fon,false,false,true);
DrawWind(0,0,scrw-158,scrh);
Tex_EndRenderIn;}

case gscene of
 sInto:Game1Init;
 sTraining:Game2Init;
 sIntroduction:Game3Init;
 sComparison:Game4Init;
 sSearchElements:Game5Init;
 sFillingCards:Game6Init;
 sPlot:;
 sEncryption:;
 sDecoding:;
 sCoordination:;
 sEndTask:;
end;

gamepause:=false;

end;

procedure GameDraw;
var i1,i2:integer;
    str:pchar;
begin

if endtaskb then EndTaskDraw else
 case gscene of
  sInto:Game1Draw;
  sTraining:Game2Draw;
  sIntroduction:Game3Draw;
  sComparison:Game4Draw;
  sSearchElements:Game5Draw;
  sFillingCards:Game6Draw;
  sPlot:;
  sEncryption:;
  sDecoding:;
  sCoordination:;
  sEndTask:;
 end;

if gamepause then
begin
 for i1:=0 to scrw div 208 do
  for i2:=0 to scrh div 16 do
   res.Spr[res.FindSpr('pausefon')].Draw2(i1*208,i2*16,208,16,255,0,1);

 Str:=PChar('Пауза');
 i1:=trunc(Text_GetWidth(font,str,2,0)); //узнаём ширину текста
 text_draw(font,(scrw-i1) div 2,scrh div 2-20,str,2,0,255,$003B7D);
 Str:=PChar('(для выхода из паузы нажмите Ctr)');
 i1:=trunc(Text_GetWidth(font,str,1,0)); //узнаём ширину текста
 text_draw(font,(scrw-i1) div 2,scrh div 2+30,str,1,0,255,$003B7D);
end;

end;

procedure GameProcess;
begin

if key_Press(k_ctrl) then gamepause:=not gamepause;

if endtaskb then EndTaskProcess else
if not gamepause then
 case gscene of
  sInto:Game1Process;
  sTraining:Game2Process;
  sIntroduction:Game3Process;
  sComparison:Game4Process;
  sSearchElements:Game5Process;
  sFillingCards:Game6Process;
  sPlot:;
  sEncryption:;
  sDecoding:;
  sCoordination:;
  sEndTask:;
 end;

end;

procedure NewGame;
begin

gametasks.nowtask:=1;
gamestart:=false;
Player.Init('player',5000,5000,5000);
trening:=false;
scene:=sGame;
gscene:=sInto;
GameInit;


end;

procedure LoadGame;
var DF:textfile;
    t:integer;
begin

assignfile(DF,'player.txt');
reset(DF);
with player do begin
readln(DF,t);
gamestart:=t=1;
readln(DF,gametasks.nowtask);
readln(DF,Name);
readln(DF,Experience,MaxExp,ExpLvl);
readln(DF,Accuracy,MaxAcr,AcrLvl);
readln(DF,Speed,MaxSpd,SpdLvl);
end;
closefile(DF);

end;

procedure SaveGame;
var DF:textfile;
begin

assignfile(DF,'player.txt');
rewrite(DF);
if gamestart then writeln(DF,'1') else writeln(DF,'0');
writeln(DF,GameTasks.nowtask);
with player do begin
writeln(DF,name);
writeln(DF,Experience,' ',MaxExp,' ',ExpLvl);
writeln(DF,Accuracy,' ',MaxAcr,' ',AcrLvl);
writeln(DF,Speed,' ',MaxSpd,' ',AcrLvl);
end;
closefile(DF);

end;

procedure GameContinue;
begin

trening:=false;

if gamestart then
begin
 scene:=sGame;
 GameTasks.ContinueTask;
 GameInit;
end          else
begin
 scene:=sGame;
 gamestart:=true;
 GameTasks.ContinueTask;
 GameInit;
end;

end;

procedure GoToMenu;
begin

scene:=sMenu;
MenuPanelInit;

end;

end.
