Changeset 394 for tags/1.4.0/Player.pas


Ignore:
Timestamp:
Jan 6, 2025, 12:00:42 AM (4 days ago)
Author:
chronos
Message:

Merged revision(s) 386-393 from trunk:

  • Fixed: Previous auto save game was not correctly restored if no game was loaded yet.
  • Modified: Use new higher resolution application image in about dialog.
  • Modified: Do not zoom all on new game start and game load from file.
  • Modified: Allow to resize new game, settings and game system forms to be smaller with scroll box area.
  • Modified: Added vector logo and generated raster logo with resolution 256x256.
  • Modified: Improved controls layout.
  • Fixed: Add new players with different colors.
  • Fixed: Apply theme to chart background.
  • Fixed: Themed background in New game form rules win conditions.
Location:
tags/1.4.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tags/1.4.0

  • tags/1.4.0/Player.pas

    r349 r394  
    137137  public
    138138    Game: TObject; //TGame;
     139    function GetPlayerByColor(Color: TColor): TPlayer;
     140    function GetUnusedColor: TColor;
    139141    procedure Assign(Source: TItemList<TPlayer>); override;
    140142    procedure New(Name: string; Color: TColor; Mode: TPlayerMode);
     
    206208  SDefensive = 'Defensive';
    207209
     210const
     211  PlayerColors: array[0..11] of TColor = (clBlue, clRed, clGreen, clYellow,
     212    clFuchsia, clAqua, clOlive, clMaroon, clNavy, clPurple, clTeal, clGray);
     213
    208214function ComparePointer(constref Item1, Item2: Integer): Integer;
    209215begin
     
    502508end;
    503509
     510function TPlayers.GetPlayerByColor(Color: TColor): TPlayer;
     511var
     512  I: Integer;
     513begin
     514  I := 0;
     515  while (I < Count) do begin
     516    if Assigned(Items[I]) and (Items[I].Color = Color) then Break;
     517    Inc(I);
     518  end;
     519  if I < Count then Result := Items[I]
     520    else Result := nil;
     521end;
     522
     523function TPlayers.GetUnusedColor: TColor;
     524var
     525  I: Integer;
     526begin
     527  Result := clBlack;
     528  for I := 0 to Length(PlayerColors) - 1 do
     529    if not Assigned(GetPlayerByColor(PlayerColors[I])) then begin
     530      Result := PlayerColors[I];
     531      Exit;
     532    end;
     533end;
     534
    504535procedure TPlayers.Assign(Source: TItemList<TPlayer>);
    505536var
     
    526557  Result := inherited;
    527558  Result.Game := Game;
     559  Result.Color := GetUnusedColor;
    528560end;
    529561
Note: See TracChangeset for help on using the changeset viewer.