source: trunk/City.pas

Last change on this file was 143, checked in by chronos, 11 months ago

Removed U prefix from all units.

File size: 2.9 KB
Line 
1unit City;
2
3interface
4
5uses
6 Classes, SysUtils, Graphics, Generics.Collections, RegistryEx;
7
8type
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 SearchBySysName(SysName: string): TCity;
31 function AddNew(SysName, Name: string; Population: Integer): TCity;
32 procedure LoadFromRegistry(Context: TRegistryContext);
33 procedure SaveToRegistry(Context: TRegistryContext);
34 end;
35
36const
37 clDarkYellow = TColor($00dede);
38 clOrange = TColor($0080ff);
39 clBrown = TColor($003090);
40 clCyan = TColor($FFFF00);
41 clPink = TColor($ff69b4);
42
43
44implementation
45
46{ TCity }
47
48procedure TCity.LoadFromRegistry(Context: TRegistryContext);
49begin
50 with TRegistryEx.Create do
51 try
52 CurrentContext := Context;
53 Locked := ReadBoolWithDefault('Locked', Locked);
54 HighestServedPassengerCount := ReadIntegerWithDefault('HighestServedPassengerCount', HighestServedPassengerCount);
55 HighestServedDaysCount := ReadIntegerWithDefault('HighestServedDaysCount', HighestServedDaysCount);
56 finally
57 Free;
58 end;
59end;
60
61procedure TCity.SaveToRegistry(Context: TRegistryContext);
62begin
63 with TRegistryEx.Create do
64 try
65 CurrentContext := Context;
66 WriteBool('Locked', Locked);
67 WriteInteger('HighestServedPassengerCount', HighestServedPassengerCount);
68 WriteInteger('HighestServedDaysCount', HighestServedDaysCount);
69 finally
70 Free;
71 end;
72end;
73
74constructor TCity.Create;
75begin
76 PassengersCountToUnlock := 500;
77 InitialLineCount := 1;
78 LineColors := [clBlue, clRed, clDarkYellow, clGreen,
79 clPurple, clGray, clOrange, clBrown, clCyan];
80end;
81
82{ TCities }
83
84function TCities.SearchBySysName(SysName: string): TCity;
85var
86 I: Integer;
87begin
88 I := 0;
89 while (I < Count) and (Items[I].SysName <> SysName) do Inc(I);
90 if I < Count then Result := Items[I]
91 else Result := nil;
92end;
93
94function TCities.AddNew(SysName, Name: string; Population: Integer): TCity;
95begin
96 Result := TCity.Create;
97 Result.SysName := SysName;
98 Result.Name := Name;
99 Result.Population := Population;
100 Add(Result);
101end;
102
103procedure TCities.LoadFromRegistry(Context: TRegistryContext);
104var
105 City: TCity;
106begin
107 for City in Self do begin
108 City.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + City.SysName));
109 end;
110end;
111
112procedure TCities.SaveToRegistry(Context: TRegistryContext);
113var
114 City: TCity;
115begin
116 for City in Self do begin
117 City.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + City.SysName));
118 end;
119end;
120
121end.
122
Note: See TracBrowser for help on using the repository browser.