Changeset 108 for trunk/Core.pas
- Timestamp:
- Dec 10, 2024, 12:06:43 AM (13 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Core.pas
r107 r108 5 5 uses 6 6 Classes, SysUtils, Theme, PersistentForm, ApplicationInfo, Translator, 7 RegistryEx, ScaleDPI, Game, ActnList, Forms, Controls, Dialogs ;7 RegistryEx, ScaleDPI, Game, ActnList, Forms, Controls, Dialogs, Score; 8 8 9 9 type … … 14 14 AAbout: TAction; 15 15 AComputer: TAction; 16 AScore: TAction; 16 17 ARestart: TAction; 17 18 AHistory: TAction; … … 34 35 procedure ANewExecute(Sender: TObject); 35 36 procedure ARestartExecute(Sender: TObject); 37 procedure AScoreExecute(Sender: TObject); 36 38 procedure ASettingsExecute(Sender: TObject); 37 39 procedure AUndoExecute(Sender: TObject); … … 46 48 procedure GameOver(Sender: TObject); 47 49 procedure GameOverSync; 50 procedure UpdateScores; 48 51 public 49 52 Game: TGame; 53 Scores: TScores; 50 54 procedure UpdateInterface; 51 55 procedure LoadConfig; … … 63 67 uses 64 68 FormMain, FormSettings, FormNew, FormHelp, FormComputer, FormAbout, FormEx, 65 FormHistory ;69 FormHistory, FormScore; 66 70 67 71 resourcestring … … 89 93 90 94 Randomize; 95 Scores := TScores.Create; 96 91 97 Game := TGame.Create; 92 98 Game.Board.Size := Point(4, 4); … … 182 188 FormNew: TFormNew; 183 189 begin 190 UpdateScores; 184 191 FormNew := TFormNew.Create(nil); 185 192 try … … 198 205 procedure TCore.ARestartExecute(Sender: TObject); 199 206 begin 207 UpdateScores; 200 208 Game.Restart; 201 209 UpdateInterface; … … 203 211 end; 204 212 213 procedure TCore.AScoreExecute(Sender: TObject); 214 var 215 FormScore: TFormScore; 216 begin 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; 226 end; 227 205 228 procedure TCore.DataModuleDestroy(Sender: TObject); 206 229 begin 230 UpdateScores; 207 231 SaveConfig; 208 232 FreeAndNil(Game); 233 FreeAndNil(Scores); 209 234 end; 210 235 … … 232 257 begin 233 258 MessageDlg(SWinCaption, Format(SWinMessage, [Game.GetTileSkinValue(Game.WinTileValue)]), mtInformation, [mbOk], 0); 259 UpdateScores; 234 260 end; 235 261 … … 242 268 begin 243 269 MessageDlg(SGameOverCaption, SGameOverMessage, mtInformation, [mbOK], 0); 270 UpdateScores; 271 end; 272 273 procedure TCore.UpdateScores; 274 var 275 Score: TScore; 276 begin 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); 244 284 end; 245 285 … … 258 298 259 299 procedure TCore.LoadConfig; 260 begin 261 with TRegistryEx.Create do 300 var 301 Reg: TRegistryEx; 302 RegContext: TRegistryContext; 303 begin 304 Reg := TRegistryEx.Create; 305 with Reg do 262 306 try 263 307 CurrentContext := ApplicationInfo1.GetRegistryContext; … … 267 311 else Translator1.Language := Translator1.Languages.SearchByCode(''); 268 312 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; 273 320 end; 274 321 275 322 procedure TCore.SaveConfig; 276 begin 277 with TRegistryEx.Create do 323 var 324 Reg: TRegistryEx; 325 RegContext: TRegistryContext; 326 begin 327 Reg := TRegistryEx.Create; 328 with Reg do 278 329 try 279 330 CurrentContext := ApplicationInfo1.GetRegistryContext; … … 283 334 else DeleteValue('LanguageCode'); 284 335 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; 289 343 end; 290 344
Note:
See TracChangeset
for help on using the changeset viewer.