Changeset 108 for trunk/Game.pas
- Timestamp:
- Dec 10, 2024, 12:06:43 AM (12 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Game.pas
r107 r108 27 27 TGame = class 28 28 private 29 FMoves: Integer; 29 30 FMoving: Boolean; 30 31 FUnmergeableTilesCount: Integer; … … 41 42 FSkin: TTileSkin; 42 43 FDisabledTilesCount: Integer; 44 FUsedUndos: Integer; 43 45 function GetTileColor(Value: Integer): TColor; 44 46 procedure SetRecordHistory(AValue: Boolean); … … 72 74 BackgroundColor: TColor; 73 75 Value2Chance: Double; 76 StartTime: TDateTime; 74 77 procedure Replay(History: THistory; Step: Integer); 75 78 function CanUndo: Boolean; … … 87 90 procedure MoveTile(SourceTile, TargetTile: TTile); 88 91 function IsValidPos(Pos: TPoint): Boolean; 89 procedure SaveToRegistry(Reg Context: TRegistryContext);90 procedure LoadFromRegistry(Reg Context: TRegistryContext);92 procedure SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext); 93 procedure LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext); 91 94 function GetTileSkinValue(Value: Integer): string; 92 95 function GetTileSkinScore(Value: Integer): Integer; … … 94 97 destructor Destroy; override; 95 98 property Score: Integer read FScore write SetScore; 99 property Moves: Integer read FMoves; 100 property UsedUndos: Integer read FUsedUndos; 96 101 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;101 102 property Moving: Boolean read FMoving; 102 103 property RecordHistory: Boolean read FRecordHistory write SetRecordHistory; … … 105 106 property DisabledTilesCount: Integer read FDisabledTilesCount write FDisabledTilesCount; 106 107 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; 107 112 end; 108 113 … … 317 322 Difficulty = 0.7; 318 323 begin 324 FUsedUndos := 0; 325 FMoves := 0; 319 326 FCanUndo := False; 320 327 Board.Clear; … … 359 366 end; 360 367 InitialBoard.Assign(Board); 368 StartTime := Now; 361 369 AnimateTiles; 362 370 DoChange; … … 368 376 Reset; 369 377 Board.Assign(InitialBoard); 378 StartTime := Now; 370 379 AnimateTiles; 371 380 DoChange; … … 531 540 TileMoved: Boolean; 532 541 begin 542 Inc(FMoves); 533 543 if Animation then begin 534 544 MoveAllAnimate(Direction); … … 664 674 Board.Assign(FBoardUndo); 665 675 FCanUndo := False; 676 Inc(FUsedUndos); 666 677 FRunning := CanMove; 667 678 if RecordHistory then History.Moves.Delete(History.Moves.Count - 1); … … 1033 1044 end; 1034 1045 1035 procedure TGame.SaveToRegistry(RegContext: TRegistryContext); 1036 var 1037 Reg: TRegistryEx; 1038 begin 1039 Reg := TRegistryEx.Create; 1040 with Reg do 1041 try 1046 procedure TGame.SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext); 1047 begin 1048 with Reg do begin 1042 1049 CurrentContext := RegContext; 1043 1050 … … 1053 1060 WriteInteger('DisabledTilesCount', DisabledTilesCount); 1054 1061 WriteInteger('UnmergeableTilesCount', UnmergeableTilesCount); 1062 WriteInteger('Moves', FMoves); 1063 WriteInteger('UsedUndos', FUsedUndos); 1064 WriteDateTime('StartTime', StartTime); 1055 1065 FBoardUndo.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo')); 1056 1066 Board.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board')); 1057 1067 InitialBoard.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\InitialBoard')); 1058 1068 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; 1070 end; 1071 1072 procedure TGame.LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext 1073 ); 1074 begin 1075 with Reg do begin 1071 1076 CurrentContext := RegContext; 1072 1077 AnimationDuration := ReadIntegerWithDefault('AnimationDuration', 30); … … 1081 1086 DisabledTilesCount := ReadIntegerWithDefault('DisabledTilesCount', DisabledTilesCount); 1082 1087 UnmergeableTilesCount := ReadIntegerWithDefault('UnmergeableTilesCount', UnmergeableTilesCount); 1088 FMoves := ReadIntegerWithDefault('Moves', FMoves); 1089 FUsedUndos := ReadIntegerWithDefault('UsedUndos', FUsedUndos); 1090 StartTime := ReadDateTimeWithDefault('StartTime', StartTime); 1083 1091 FBoardUndo.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo')); 1084 1092 Board.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board')); 1085 1093 InitialBoard.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\InitialBoard')); 1086 1094 History.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\History')); 1087 finally1088 Free;1089 1095 end; 1090 1096 DoChange;
Note:
See TracChangeset
for help on using the changeset viewer.