0

我是一个初学者的德尔福用户。我有这个 while 循环,而不是只有一个玩家 (player1),我想有很多玩家,写成 Player[i]。我已经编辑了我的课程,它可以让我添加 [I]

   while i < FMyPlayers.TeamCount do
    begin
       buttonSelected := MessageDlg('Placeing Unit: '+FMyPlayers.Player[i].Values['name']+'.',mtError, mbOKCancel, 0);
          if buttonSelected = mrCancel then exit;
       imageyouwant.LoadFromFile(thisdir+'\char\'+FMyPlayers.Player[i].Values['picon']);
       Hexmap1.ImageAHex(ImageYouWant , bsSolid, position);
       FMyPlayers.Player[i].Add('pos='+inttostr(position.x)+inttostr(position.Y));
       FMyPlayers.PlaceUnit := false;
    end;

但是现在在我的课堂上我得到了错误

      property Player: array[1..20] of TStringList read P;

我的 MYPlayer 类如下

TPlayers = class
Private
  p : array[1..20] of TStringList;
  FPlaceUnit: Boolean;
  FTeamCount: Integer;
Public
  property Player: array[1..20] of TStringList read P;
  property PlaceUnit : Boolean read FPlaceUnit write FPlaceUnit;
  procedure AddPlayer (PlayerNo : integer; player : String);
  property TeamCount : Integer read FTeamCount write FTeamCount;

 constructor Create;   virtual;
End;
4

1 回答 1

1

不是一个真正的答案,而是扩展 Warren P 的建议。看起来您的课程没有从头开始正确设计。

uses Generics.Collections;


TPlayer = class
 // add player related properties & routines here
end;

TGame = class
 protected  
   // all fields go here
   FPlayers : TObjectList<TPlayer>;

 public

   function AddPlayer(settings : TStringList) : TPlayer; 

   property Player[index:Integer]:TPlayer read GetPlayer;
end;
于 2012-05-26T11:38:10.907 回答