program conRPG;

{$mode objfpc}{$H+}
{$codepage UTF8}

uses
   uUI, uWorld, uVar, SysUtils, crt, inifiles, uCombat;

procedure Process();
var key : string;
begin
  key := UpperCase(entry);
  if key = '' then Exit;      // ничего не ввели - выходим

  if key = 'EXIT' then _exit := true;

  if not inCombat then
     Process_World(key)
  else
     Process_Combat(key);

  if _exit then gameStatus := gsExit;
end;

begin
  NodesFile := TIniFile.Create('_nodes.ini');
  AnswersFile := TIniFile.Create('_answers.ini');

  loadNodesFromFile();
  loadAnswersFromFile();

  while not _exit do
  begin
    ClrScr;

    textcolor(yellow);
    Writeln('[ Список команд: exit - выход из игры ]');

    textcolor(white);
    writeln('debug. Last input : ', entry);

    Process;
    Read_Dialog_Variants();

    case gameStatus of
      gsGame:
        begin
          Draw_Interface();
          Draw_Dialog_Message();
          Draw_Dialog_Variant();
          TextColor(LightMagenta);
          Draw_Cmd() ;
        end;
      gsCombat:
        begin
          Draw_Interface();
          Draw_Combat_Message();
          Draw_Combat_Variant();
          TextColor(LightMagenta);
          Draw_Cmd() ;
        end;
      gsExit:
        begin
          Draw_Exit();
          TextColor(RED);
          Write('PRESS ANY KEY TO QUIT');
          Readln(entry);
        end;
    end;
  end;

  nodesFile.Free;
  answersFile.Free;
end.

