unit GameModeManager;

interface

type
  TCustomGameMode = class
    procedure OnDraw; virtual; abstract;
    procedure OnKeyDown(Key: Word); virtual; abstract;
    procedure OnKeyUp(Key: Word); virtual; abstract;
    procedure OnProcess(Delta: Double); virtual;
  end;

  TGameModeManager = class sealed
  private
    FActiveGameMode: TCustomGameMode;
    FGameModeGame: TCustomGameMode;
  public
    constructor Create;

    procedure OnKeyDown(Key: Word);
    procedure OnKeyUp(Key: Word);
    procedure OnProcess(Delta: Double);
    property ActiveGameMode: TCustomGameMode read FActiveGameMode write FActiveGameMode;
  end;

implementation

uses
  GameModeGame;

procedure TCustomGameMode.OnProcess(Delta: Double);
begin

end;

constructor TGameModeManager.Create;
begin
  FGameModeGame := TGameModeGame.Create;
  ActiveGameMode := FGameModeGame;
end;

procedure TGameModeManager.OnKeyDown(Key: Word);
begin
  if Assigned(ActiveGameMode) then
    ActiveGameMode.OnKeyDown(Key);
end;

procedure TGameModeManager.OnKeyUp(Key: Word);
begin
  if Assigned(ActiveGameMode) then
    ActiveGameMode.OnKeyUp(Key);
end;

procedure TGameModeManager.OnProcess(Delta: Double);
begin
  if not Assigned(ActiveGameMode) then
    Exit;

  ActiveGameMode.OnProcess(Delta);
  ActiveGameMode.OnDraw;
end;

end.
