Changeset 100 for trunk/UCity.pas


Ignore:
Timestamp:
Sep 28, 2022, 7:14:22 PM (20 months ago)
Author:
chronos
Message:
  • Added: New game mode carrier where user needs to play existing cities and gradually unlock them by reaching exprected transported number of passengers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCity.pas

    r93 r100  
    44
    55uses
    6   Classes, SysUtils, Generics.Collections;
     6  Classes, SysUtils, Graphics, Generics.Collections, URegistry;
    77
    88type
     9
     10  { TCity }
     11
    912  TCity = class
     13    SysName: string;
    1014    Name: string;
     15    Population: Integer;
    1116    Locked: Boolean;
     17    LineColors: array of TColor;
     18    InitialLineCount: Integer;
    1219    PassengersCountToUnlock: Integer;
     20    HighestServedPassengerCount: Integer;
     21    HighestServedDaysCount: Integer;
     22    procedure LoadFromRegistry(Context: TRegistryContext);
     23    procedure SaveToRegistry(Context: TRegistryContext);
     24    constructor Create;
    1325  end;
    1426
     
    1628
    1729  TCities = class(TObjectList<TCity>)
    18     function AddNew(Name: string): TCity;
     30    function AddNew(SysName, Name: string; Population: Integer): TCity;
     31    procedure LoadFromRegistry(Context: TRegistryContext);
     32    procedure SaveToRegistry(Context: TRegistryContext);
    1933  end;
     34
     35const
     36  clDarkYellow = TColor($00dede);
     37  clOrange = TColor($0080ff);
     38  clBrown = TColor($003090);
     39  clCyan = TColor($FFFF00);
     40  clPink = TColor($ff69b4);
    2041
    2142
    2243implementation
    2344
     45{ TCity }
     46
     47procedure TCity.LoadFromRegistry(Context: TRegistryContext);
     48begin
     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;
     58end;
     59
     60procedure TCity.SaveToRegistry(Context: TRegistryContext);
     61begin
     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;
     71end;
     72
     73constructor TCity.Create;
     74begin
     75  PassengersCountToUnlock := 500;
     76  InitialLineCount := 1;
     77  LineColors := [clBlue, clRed, clDarkYellow, clGreen,
     78     clPurple, clGray, clOrange, clBrown, clCyan];
     79end;
     80
    2481{ TCities }
    2582
    26 function TCities.AddNew(Name: string): TCity;
     83function TCities.AddNew(SysName, Name: string; Population: Integer): TCity;
    2784begin
    2885  Result := TCity.Create;
     86  Result.SysName := SysName;
    2987  Result.Name := Name;
     88  Result.Population := Population;
    3089  Add(Result);
     90end;
     91
     92procedure TCities.LoadFromRegistry(Context: TRegistryContext);
     93var
     94  City: TCity;
     95begin
     96  for City in Self do begin
     97    City.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '/' + City.SysName));
     98  end;
     99end;
     100
     101procedure TCities.SaveToRegistry(Context: TRegistryContext);
     102var
     103  City: TCity;
     104begin
     105  for City in Self do begin
     106    City.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '/' + City.SysName));
     107  end;
    31108end;
    32109
Note: See TracChangeset for help on using the changeset viewer.