Changeset 108 for trunk/Game.pas


Ignore:
Timestamp:
Dec 10, 2024, 12:06:43 AM (12 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/Game.pas

    r107 r108  
    2727  TGame = class
    2828  private
     29    FMoves: Integer;
    2930    FMoving: Boolean;
    3031    FUnmergeableTilesCount: Integer;
     
    4142    FSkin: TTileSkin;
    4243    FDisabledTilesCount: Integer;
     44    FUsedUndos: Integer;
    4345    function GetTileColor(Value: Integer): TColor;
    4446    procedure SetRecordHistory(AValue: Boolean);
     
    7274    BackgroundColor: TColor;
    7375    Value2Chance: Double;
     76    StartTime: TDateTime;
    7477    procedure Replay(History: THistory; Step: Integer);
    7578    function CanUndo: Boolean;
     
    8790    procedure MoveTile(SourceTile, TargetTile: TTile);
    8891    function IsValidPos(Pos: TPoint): Boolean;
    89     procedure SaveToRegistry(RegContext: TRegistryContext);
    90     procedure LoadFromRegistry(RegContext: TRegistryContext);
     92    procedure SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
     93    procedure LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
    9194    function GetTileSkinValue(Value: Integer): string;
    9295    function GetTileSkinScore(Value: Integer): Integer;
     
    9497    destructor Destroy; override;
    9598    property Score: Integer read FScore write SetScore;
     99    property Moves: Integer read FMoves;
     100    property UsedUndos: Integer read FUsedUndos;
    96101    property Running: Boolean read FRunning write FRunning;
    97     property OnChange: TNotifyEvent read FOnChange write FOnChange;
    98     property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
    99     property OnWin: TNotifyEvent read FOnWin write FOnWin;
    100     property OnGameOver: TNotifyEvent read FOnGameOver write FOnGameOver;
    101102    property Moving: Boolean read FMoving;
    102103    property RecordHistory: Boolean read FRecordHistory write SetRecordHistory;
     
    105106    property DisabledTilesCount: Integer read FDisabledTilesCount write FDisabledTilesCount;
    106107    property UnmergeableTilesCount: Integer read FUnmergeableTilesCount write FUnmergeableTilesCount;
     108    property OnChange: TNotifyEvent read FOnChange write FOnChange;
     109    property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
     110    property OnWin: TNotifyEvent read FOnWin write FOnWin;
     111    property OnGameOver: TNotifyEvent read FOnGameOver write FOnGameOver;
    107112  end;
    108113
     
    317322  Difficulty = 0.7;
    318323begin
     324  FUsedUndos := 0;
     325  FMoves := 0;
    319326  FCanUndo := False;
    320327  Board.Clear;
     
    359366  end;
    360367  InitialBoard.Assign(Board);
     368  StartTime := Now;
    361369  AnimateTiles;
    362370  DoChange;
     
    368376  Reset;
    369377  Board.Assign(InitialBoard);
     378  StartTime := Now;
    370379  AnimateTiles;
    371380  DoChange;
     
    531540  TileMoved: Boolean;
    532541begin
     542  Inc(FMoves);
    533543  if Animation then begin
    534544    MoveAllAnimate(Direction);
     
    664674    Board.Assign(FBoardUndo);
    665675    FCanUndo := False;
     676    Inc(FUsedUndos);
    666677    FRunning := CanMove;
    667678    if RecordHistory then History.Moves.Delete(History.Moves.Count - 1);
     
    10331044end;
    10341045
    1035 procedure TGame.SaveToRegistry(RegContext: TRegistryContext);
    1036 var
    1037   Reg: TRegistryEx;
    1038 begin
    1039   Reg := TRegistryEx.Create;
    1040   with Reg do
    1041   try
     1046procedure TGame.SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
     1047begin
     1048  with Reg do begin
    10421049    CurrentContext := RegContext;
    10431050
     
    10531060    WriteInteger('DisabledTilesCount', DisabledTilesCount);
    10541061    WriteInteger('UnmergeableTilesCount', UnmergeableTilesCount);
     1062    WriteInteger('Moves', FMoves);
     1063    WriteInteger('UsedUndos', FUsedUndos);
     1064    WriteDateTime('StartTime', StartTime);
    10551065    FBoardUndo.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    10561066    Board.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
    10571067    InitialBoard.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\InitialBoard'));
    10581068    History.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\History'));
    1059   finally
    1060     Free;
    1061   end;
    1062 end;
    1063 
    1064 procedure TGame.LoadFromRegistry(RegContext: TRegistryContext);
    1065 var
    1066   Reg: TRegistryEx;
    1067 begin
    1068   Reg := TRegistryEx.Create;
    1069   with Reg do
    1070   try
     1069  end;
     1070end;
     1071
     1072procedure TGame.LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext
     1073  );
     1074begin
     1075  with Reg do begin
    10711076    CurrentContext := RegContext;
    10721077    AnimationDuration := ReadIntegerWithDefault('AnimationDuration', 30);
     
    10811086    DisabledTilesCount := ReadIntegerWithDefault('DisabledTilesCount', DisabledTilesCount);
    10821087    UnmergeableTilesCount := ReadIntegerWithDefault('UnmergeableTilesCount', UnmergeableTilesCount);
     1088    FMoves := ReadIntegerWithDefault('Moves', FMoves);
     1089    FUsedUndos := ReadIntegerWithDefault('UsedUndos', FUsedUndos);
     1090    StartTime := ReadDateTimeWithDefault('StartTime', StartTime);
    10831091    FBoardUndo.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    10841092    Board.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
    10851093    InitialBoard.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\InitialBoard'));
    10861094    History.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\History'));
    1087   finally
    1088     Free;
    10891095  end;
    10901096  DoChange;
Note: See TracChangeset for help on using the changeset viewer.