| 1 | unit Score;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, Generics.Collections, RegistryEx, ListViewSort;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 |
|
|---|
| 10 | { TScore }
|
|---|
| 11 |
|
|---|
| 12 | TScore = class
|
|---|
| 13 | StartTime: TDateTime;
|
|---|
| 14 | Duration: TDateTime;
|
|---|
| 15 | Score: Integer;
|
|---|
| 16 | Moves: Integer;
|
|---|
| 17 | UsedUndos: Integer;
|
|---|
| 18 | BoardSize: string;
|
|---|
| 19 | DisabledTiles: Integer;
|
|---|
| 20 | UnmergeableTiles: Integer;
|
|---|
| 21 | BiggestTile: Integer;
|
|---|
| 22 | procedure SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
|
|---|
| 23 | procedure LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
|
|---|
| 24 | end;
|
|---|
| 25 |
|
|---|
| 26 | { TScores }
|
|---|
| 27 |
|
|---|
| 28 | TScores = class(TObjectList<TScore>)
|
|---|
| 29 | function SearchByTime(StartTime: TDateTime): TScore;
|
|---|
| 30 | function AddNew: TScore;
|
|---|
| 31 | procedure SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
|
|---|
| 32 | procedure LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
|
|---|
| 33 | procedure AssignToList(List: TObjects);
|
|---|
| 34 | end;
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | implementation
|
|---|
| 38 |
|
|---|
| 39 | { TScore }
|
|---|
| 40 |
|
|---|
| 41 | procedure TScore.SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
|
|---|
| 42 | begin
|
|---|
| 43 | with Reg do begin
|
|---|
| 44 | CurrentContext := RegContext;
|
|---|
| 45 | WriteDateTime('StartTime', StartTime);
|
|---|
| 46 | WriteDateTime('Duration', Duration);
|
|---|
| 47 | WriteInteger('Score', Score);
|
|---|
| 48 | WriteInteger('Moves', Moves);
|
|---|
| 49 | WriteInteger('UsedUndos', UsedUndos);
|
|---|
| 50 | WriteString('BoardSize', BoardSize);
|
|---|
| 51 | WriteInteger('DisabledTiles', DisabledTiles);
|
|---|
| 52 | WriteInteger('UnmergeableTiles', UnmergeableTiles);
|
|---|
| 53 | WriteInteger('BiggestTile', BiggestTile);
|
|---|
| 54 | end;
|
|---|
| 55 | end;
|
|---|
| 56 |
|
|---|
| 57 | procedure TScore.LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext
|
|---|
| 58 | );
|
|---|
| 59 | begin
|
|---|
| 60 | with Reg do begin
|
|---|
| 61 | CurrentContext := RegContext;
|
|---|
| 62 | StartTime := ReadDateTimeWithDefault('StartTime', StartTime);
|
|---|
| 63 | Duration := ReadDateTimeWithDefault('Duration', Duration);
|
|---|
| 64 | Score := ReadIntegerWithDefault('Score', Score);
|
|---|
| 65 | Moves := ReadIntegerWithDefault('Moves', Moves);
|
|---|
| 66 | UsedUndos := ReadIntegerWithDefault('UsedUndos', UsedUndos);
|
|---|
| 67 | BoardSize := ReadStringWithDefault('BoardSize', BoardSize);
|
|---|
| 68 | DisabledTiles := ReadIntegerWithDefault('DisabledTiles', DisabledTiles);
|
|---|
| 69 | UnmergeableTiles := ReadIntegerWithDefault('UnmergeableTiles', UnmergeableTiles);
|
|---|
| 70 | BiggestTile := ReadIntegerWithDefault('BiggestTile', BiggestTile);
|
|---|
| 71 | end;
|
|---|
| 72 | end;
|
|---|
| 73 |
|
|---|
| 74 | { TScores }
|
|---|
| 75 |
|
|---|
| 76 | function TScores.SearchByTime(StartTime: TDateTime): TScore;
|
|---|
| 77 | var
|
|---|
| 78 | I: Integer;
|
|---|
| 79 | begin
|
|---|
| 80 | I := 0;
|
|---|
| 81 | while (I < Count) and (Items[I].StartTime <> StartTime) do Inc(I);
|
|---|
| 82 | if I < Count then Result := Items[I]
|
|---|
| 83 | else Result := nil;
|
|---|
| 84 | end;
|
|---|
| 85 |
|
|---|
| 86 | function TScores.AddNew: TScore;
|
|---|
| 87 | begin
|
|---|
| 88 | Result := TScore.Create;
|
|---|
| 89 | Add(Result);
|
|---|
| 90 | end;
|
|---|
| 91 |
|
|---|
| 92 | procedure TScores.SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext
|
|---|
| 93 | );
|
|---|
| 94 | var
|
|---|
| 95 | I: Integer;
|
|---|
| 96 | begin
|
|---|
| 97 | with Reg do begin
|
|---|
| 98 | CurrentContext := RegContext;
|
|---|
| 99 |
|
|---|
| 100 | WriteInteger('Count', Count);
|
|---|
| 101 | for I := 0 to Count - 1 do
|
|---|
| 102 | Items[I].SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Score' + IntToStr(I)));
|
|---|
| 103 | end;
|
|---|
| 104 | end;
|
|---|
| 105 |
|
|---|
| 106 | procedure TScores.LoadFromRegistry(Reg: TRegistryEx;
|
|---|
| 107 | RegContext: TRegistryContext);
|
|---|
| 108 | var
|
|---|
| 109 | I: Integer;
|
|---|
| 110 | C: Integer;
|
|---|
| 111 | NewScore: TScore;
|
|---|
| 112 | begin
|
|---|
| 113 | with Reg do begin
|
|---|
| 114 | CurrentContext := RegContext;
|
|---|
| 115 |
|
|---|
| 116 | C := ReadIntegerWithDefault('Count', 0);
|
|---|
| 117 | for I := 0 to C - 1 do begin
|
|---|
| 118 | NewScore := AddNew;
|
|---|
| 119 | NewScore.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Score' + IntToStr(I)));
|
|---|
| 120 | end;
|
|---|
| 121 | end;
|
|---|
| 122 | end;
|
|---|
| 123 |
|
|---|
| 124 | procedure TScores.AssignToList(List: TObjects);
|
|---|
| 125 | var
|
|---|
| 126 | I: Integer;
|
|---|
| 127 | begin
|
|---|
| 128 | while List.Count > Count do List.Delete(List.Count - 1);
|
|---|
| 129 | for I := 0 to List.Count - 1 do List[I] := Items[I];
|
|---|
| 130 | while List.Count < Count do List.Add(Items[List.Count]);
|
|---|
| 131 | end;
|
|---|
| 132 |
|
|---|
| 133 | end.
|
|---|
| 134 |
|
|---|