Changeset 108 for trunk/Core.pas


Ignore:
Timestamp:
Dec 10, 2024, 12:06:43 AM (13 days ago)
Author:
chronos
Message:
  • Added: Tools - Score menu action to show history of previously played games with score information.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Core.pas

    r107 r108  
    55uses
    66  Classes, SysUtils, Theme, PersistentForm, ApplicationInfo, Translator,
    7   RegistryEx, ScaleDPI, Game, ActnList, Forms, Controls, Dialogs;
     7  RegistryEx, ScaleDPI, Game, ActnList, Forms, Controls, Dialogs, Score;
    88
    99type
     
    1414    AAbout: TAction;
    1515    AComputer: TAction;
     16    AScore: TAction;
    1617    ARestart: TAction;
    1718    AHistory: TAction;
     
    3435    procedure ANewExecute(Sender: TObject);
    3536    procedure ARestartExecute(Sender: TObject);
     37    procedure AScoreExecute(Sender: TObject);
    3638    procedure ASettingsExecute(Sender: TObject);
    3739    procedure AUndoExecute(Sender: TObject);
     
    4648    procedure GameOver(Sender: TObject);
    4749    procedure GameOverSync;
     50    procedure UpdateScores;
    4851  public
    4952    Game: TGame;
     53    Scores: TScores;
    5054    procedure UpdateInterface;
    5155    procedure LoadConfig;
     
    6367uses
    6468  FormMain, FormSettings, FormNew, FormHelp, FormComputer, FormAbout, FormEx,
    65   FormHistory;
     69  FormHistory, FormScore;
    6670
    6771resourcestring
     
    8993
    9094  Randomize;
     95  Scores := TScores.Create;
     96
    9197  Game := TGame.Create;
    9298  Game.Board.Size := Point(4, 4);
     
    182188  FormNew: TFormNew;
    183189begin
     190  UpdateScores;
    184191  FormNew := TFormNew.Create(nil);
    185192  try
     
    198205procedure TCore.ARestartExecute(Sender: TObject);
    199206begin
     207  UpdateScores;
    200208  Game.Restart;
    201209  UpdateInterface;
     
    203211end;
    204212
     213procedure TCore.AScoreExecute(Sender: TObject);
     214var
     215  FormScore: TFormScore;
     216begin
     217  UpdateScores;
     218  FormScore := TFormScore.Create(nil);
     219  try
     220    FormScore.Scores := Scores;
     221    if FormScore.ShowModal = mrOk then begin
     222    end;
     223  finally
     224    FreeAndNil(FormScore);
     225  end;
     226end;
     227
    205228procedure TCore.DataModuleDestroy(Sender: TObject);
    206229begin
     230  UpdateScores;
    207231  SaveConfig;
    208232  FreeAndNil(Game);
     233  FreeAndNil(Scores);
    209234end;
    210235
     
    232257begin
    233258  MessageDlg(SWinCaption, Format(SWinMessage, [Game.GetTileSkinValue(Game.WinTileValue)]), mtInformation, [mbOk], 0);
     259  UpdateScores;
    234260end;
    235261
     
    242268begin
    243269  MessageDlg(SGameOverCaption, SGameOverMessage, mtInformation, [mbOK], 0);
     270  UpdateScores;
     271end;
     272
     273procedure TCore.UpdateScores;
     274var
     275  Score: TScore;
     276begin
     277  Score := Scores.SearchByTime(Game.StartTime);
     278  if not Assigned(Score) then Score := Scores.AddNew;
     279  Score.StartTime := Game.StartTime;
     280  Score.Score := Game.Score;
     281  Score.Moves := Game.Moves;
     282  Score.UsedUndos := Game.UsedUndos;
     283  Score.BoardSize := IntToStr(Game.Board.Size.X) + 'x' + IntToStr(Game.Board.Size.Y);
    244284end;
    245285
     
    258298
    259299procedure TCore.LoadConfig;
    260 begin
    261   with TRegistryEx.Create do
     300var
     301  Reg: TRegistryEx;
     302  RegContext: TRegistryContext;
     303begin
     304  Reg := TRegistryEx.Create;
     305  with Reg do
    262306  try
    263307    CurrentContext := ApplicationInfo1.GetRegistryContext;
     
    267311      else Translator1.Language := Translator1.Languages.SearchByCode('');
    268312    ThemeManager1.Theme := ThemeManager1.Themes.FindByName(ReadStringWithDefault('Theme', 'System'));
    269   finally
    270     Free;
    271   end;
    272   Game.LoadFromRegistry(ApplicationInfo1.GetRegistryContext);
     313
     314    RegContext := ApplicationInfo1.GetRegistryContext;
     315    Game.LoadFromRegistry(Reg, RegContext);
     316    Scores.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Scores'));
     317  finally
     318    Reg.Free;
     319  end;
    273320end;
    274321
    275322procedure TCore.SaveConfig;
    276 begin
    277   with TRegistryEx.Create do
     323var
     324  Reg: TRegistryEx;
     325  RegContext: TRegistryContext;
     326begin
     327  Reg := TRegistryEx.Create;
     328  with Reg do
    278329  try
    279330    CurrentContext := ApplicationInfo1.GetRegistryContext;
     
    283334      else DeleteValue('LanguageCode');
    284335    WriteString('Theme', ThemeManager1.Theme.Name);
    285   finally
    286     Free;
    287   end;
    288   Game.SaveToRegistry(ApplicationInfo1.GetRegistryContext);
     336
     337    RegContext := ApplicationInfo1.GetRegistryContext;
     338    Game.SaveToRegistry(Reg, RegContext);
     339    Scores.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Scores'));
     340  finally
     341    Reg.Free;
     342  end;
    289343end;
    290344
Note: See TracChangeset for help on using the changeset viewer.