1 | unit UCity;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Graphics, Generics.Collections, URegistry;
|
---|
7 |
|
---|
8 | type
|
---|
9 |
|
---|
10 | { TCity }
|
---|
11 |
|
---|
12 | TCity = class
|
---|
13 | SysName: string;
|
---|
14 | Name: string;
|
---|
15 | Population: Integer;
|
---|
16 | Locked: Boolean;
|
---|
17 | LineColors: array of TColor;
|
---|
18 | InitialLineCount: Integer;
|
---|
19 | PassengersCountToUnlock: Integer;
|
---|
20 | HighestServedPassengerCount: Integer;
|
---|
21 | HighestServedDaysCount: Integer;
|
---|
22 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
23 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
24 | constructor Create;
|
---|
25 | end;
|
---|
26 |
|
---|
27 | { TCities }
|
---|
28 |
|
---|
29 | TCities = class(TObjectList<TCity>)
|
---|
30 | function AddNew(SysName, Name: string; Population: Integer): TCity;
|
---|
31 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
32 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
33 | end;
|
---|
34 |
|
---|
35 | const
|
---|
36 | clDarkYellow = TColor($00dede);
|
---|
37 | clOrange = TColor($0080ff);
|
---|
38 | clBrown = TColor($003090);
|
---|
39 | clCyan = TColor($FFFF00);
|
---|
40 | clPink = TColor($ff69b4);
|
---|
41 |
|
---|
42 |
|
---|
43 | implementation
|
---|
44 |
|
---|
45 | { TCity }
|
---|
46 |
|
---|
47 | procedure TCity.LoadFromRegistry(Context: TRegistryContext);
|
---|
48 | begin
|
---|
49 | with TRegistryEx.Create do
|
---|
50 | try
|
---|
51 | CurrentContext := Context;
|
---|
52 | Locked := ReadBoolWithDefault('Locked', Locked);
|
---|
53 | HighestServedPassengerCount := ReadIntegerWithDefault('HighestServedPassengerCount', HighestServedPassengerCount);
|
---|
54 | HighestServedDaysCount := ReadIntegerWithDefault('HighestServedDaysCount', HighestServedDaysCount);
|
---|
55 | finally
|
---|
56 | Free;
|
---|
57 | end;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | procedure TCity.SaveToRegistry(Context: TRegistryContext);
|
---|
61 | begin
|
---|
62 | with TRegistryEx.Create do
|
---|
63 | try
|
---|
64 | CurrentContext := Context;
|
---|
65 | WriteBool('Locked', Locked);
|
---|
66 | WriteInteger('HighestServedPassengerCount', HighestServedPassengerCount);
|
---|
67 | WriteInteger('HighestServedDaysCount', HighestServedDaysCount);
|
---|
68 | finally
|
---|
69 | Free;
|
---|
70 | end;
|
---|
71 | end;
|
---|
72 |
|
---|
73 | constructor TCity.Create;
|
---|
74 | begin
|
---|
75 | PassengersCountToUnlock := 500;
|
---|
76 | InitialLineCount := 1;
|
---|
77 | LineColors := [clBlue, clRed, clDarkYellow, clGreen,
|
---|
78 | clPurple, clGray, clOrange, clBrown, clCyan];
|
---|
79 | end;
|
---|
80 |
|
---|
81 | { TCities }
|
---|
82 |
|
---|
83 | function TCities.AddNew(SysName, Name: string; Population: Integer): TCity;
|
---|
84 | begin
|
---|
85 | Result := TCity.Create;
|
---|
86 | Result.SysName := SysName;
|
---|
87 | Result.Name := Name;
|
---|
88 | Result.Population := Population;
|
---|
89 | Add(Result);
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TCities.LoadFromRegistry(Context: TRegistryContext);
|
---|
93 | var
|
---|
94 | City: TCity;
|
---|
95 | begin
|
---|
96 | for City in Self do begin
|
---|
97 | City.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + City.SysName));
|
---|
98 | end;
|
---|
99 | end;
|
---|
100 |
|
---|
101 | procedure TCities.SaveToRegistry(Context: TRegistryContext);
|
---|
102 | var
|
---|
103 | City: TCity;
|
---|
104 | begin
|
---|
105 | for City in Self do begin
|
---|
106 | City.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + City.SysName));
|
---|
107 | end;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | end.
|
---|
111 |
|
---|