Changeset 10 for trunk/UCore.pas


Ignore:
Timestamp:
Oct 4, 2019, 11:05:35 PM (5 years ago)
Author:
chronos
Message:
  • Added: Show Top score and remember it after application restart.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r8 r10  
    66
    77uses
    8   Classes, SysUtils, UTheme, UPersistentForm, UApplicationInfo, UTranslator;
     8  Classes, SysUtils, UTheme, UPersistentForm, UApplicationInfo, UTranslator,
     9  URegistry, UGame;
    910
    1011type
     
    1718    ThemeManager1: TThemeManager;
    1819    Translator1: TTranslator;
     20    procedure DataModuleCreate(Sender: TObject);
     21    procedure DataModuleDestroy(Sender: TObject);
    1922  private
    20 
     23    procedure GameChange(Sender: TObject);
    2124  public
    22 
     25    Game: TGame;
     26    procedure LoadConfig;
     27    procedure SaveConfig;
    2328  end;
    2429
     
    3035{$R *.lfm}
    3136
     37uses
     38  UFormMain;
     39
     40{ TCore }
     41
     42procedure TCore.DataModuleCreate(Sender: TObject);
     43begin
     44  Randomize;
     45  Game := TGame.Create;
     46  Game.Size := Point(4, 4);
     47  Game.OnChange := GameChange;
     48  LoadConfig;
     49end;
     50
     51procedure TCore.DataModuleDestroy(Sender: TObject);
     52begin
     53  SaveConfig;
     54  FreeAndNil(Game);
     55end;
     56
     57procedure TCore.GameChange(Sender: TObject);
     58begin
     59  FormMain.Repaint;
     60end;
     61
     62procedure TCore.LoadConfig;
     63begin
     64  with TRegistryEx.Create do
     65  try
     66    CurrentContext := ApplicationInfo1.GetRegistryContext;
     67
     68    Game.TopScore := ReadIntegerWithDefault('TopScore', 0);
     69  finally
     70    Free;
     71  end;
     72end;
     73
     74procedure TCore.SaveConfig;
     75begin
     76  with TRegistryEx.Create do
     77  try
     78    CurrentContext := ApplicationInfo1.GetRegistryContext;
     79
     80    WriteInteger('TopScore', Game.TopScore);
     81  finally
     82    Free;
     83  end;
     84end;
     85
    3286end.
    3387
Note: See TracChangeset for help on using the changeset viewer.