Changeset 19 for trunk/UGame.pas
- Timestamp:
- Oct 5, 2019, 1:00:29 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r17 r19 7 7 uses 8 8 Classes, SysUtils, Dialogs, fgl, Graphics, Types, Forms, Math, DateUtils, 9 Controls ;9 Controls, URegistry; 10 10 11 11 type … … 39 39 function GetEmptyTilesCount: Integer; 40 40 procedure GetEmptyTiles(EmptyTiles: TTiles); 41 procedure SaveToRegistry(RegContext: TRegistryContext); 42 procedure LoadFromRegistry(RegContext: TRegistryContext); 41 43 destructor Destroy; override; 42 44 property Size: TPoint read FSize write SetSize; … … 72 74 procedure MoveTile(SourceTile, TargetTile: TTile); 73 75 function IsValidPos(Pos: TPoint): Boolean; 76 procedure SaveToRegistry(RegContext: TRegistryContext); 77 procedure LoadFromRegistry(RegContext: TRegistryContext); 74 78 constructor Create; 75 79 destructor Destroy; override; … … 131 135 if Tiles[Y, X].Value = 0 then 132 136 EmptyTiles.Add(Tiles[Y, X]); 137 end; 138 139 procedure TBoard.SaveToRegistry(RegContext: TRegistryContext); 140 var 141 X, Y: Integer; 142 Value: string; 143 begin 144 with TRegistryEx.Create do 145 try 146 CurrentContext := RegContext; 147 148 Value := ''; 149 for Y := 0 to Size.Y - 1 do begin 150 for X := 0 to Size.X - 1 do begin 151 Value := Value + IntToStr(Tiles[Y, X].Value); 152 if X < Size.X - 1 then Value := Value + ','; 153 end; 154 if Y < Size.Y - 1 then Value := Value + ';' 155 end; 156 WriteString('TileValues', Value); 157 finally 158 Free; 159 end; 160 end; 161 162 procedure TBoard.LoadFromRegistry(RegContext: TRegistryContext); 163 var 164 X, Y: Integer; 165 Items: TStringList; 166 Lines: TStringList; 167 Number: Integer; 168 begin 169 with TRegistryEx.Create do 170 try 171 CurrentContext := RegContext; 172 173 Items := TStringList.Create; 174 Items.Delimiter := ','; 175 Lines := TStringList.Create; 176 Lines.Delimiter := ';'; 177 Lines.DelimitedText := ReadStringWithDefault('TileValues', ''); 178 for Y := 0 to Lines.Count - 1 do begin 179 Items.DelimitedText := Lines[Y]; 180 for X := 0 to Items.Count - 1 do begin 181 if TryStrToInt(Items[X], Number) and (X < Size.X) and (Y < Size.Y) then 182 Tiles[Y, X].Value := Number; 183 end; 184 end; 185 finally 186 Free; 187 end; 133 188 end; 134 189 … … 497 552 end; 498 553 554 procedure TGame.SaveToRegistry(RegContext: TRegistryContext); 555 begin 556 with TRegistryEx.Create do 557 try 558 CurrentContext := RegContext; 559 560 WriteInteger('TopScore', TopScore); 561 WriteInteger('AnimationDuration', AnimationDuration); 562 WriteInteger('SizeX', Board.Size.X); 563 WriteInteger('SizeY', Board.Size.Y); 564 WriteInteger('Score', Score); 565 WriteBool('GameRunning', FRunning); 566 WriteBool('Won', Won); 567 finally 568 Free; 569 end; 570 Board.SaveToRegistry(RegContext); 571 end; 572 573 procedure TGame.LoadFromRegistry(RegContext: TRegistryContext); 574 begin 575 with TRegistryEx.Create do 576 try 577 CurrentContext := RegContext; 578 Board.Size := Point(ReadIntegerWithDefault('SizeX', 4), ReadIntegerWithDefault('SizeY', 4)); 579 AnimationDuration := ReadIntegerWithDefault('AnimationDuration', 30); 580 TopScore := ReadIntegerWithDefault('TopScore', 0); 581 Score := ReadIntegerWithDefault('Score', 0); 582 FRunning := ReadBoolWithDefault('GameRunning', False); 583 Won := ReadBoolWithDefault('Won', False); 584 finally 585 Free; 586 end; 587 Board.LoadFromRegistry(RegContext); 588 end; 589 499 590 constructor TGame.Create; 500 591 begin
Note:
See TracChangeset
for help on using the changeset viewer.