Changeset 202 for trunk/UGameServer.pas


Ignore:
Timestamp:
May 17, 2018, 5:41:47 PM (6 years ago)
Author:
chronos
Message:
  • Modified: AI player related code moved to UClientAI unit. It is now extension of TClient class to simulate regular human client.
  • Modified: More work on client-server architecture.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGameServer.pas

    r199 r202  
    66
    77uses
    8   Classes, SysUtils, UGame, DOM, XMLConf, fgl,
    9   UGameProtocol;
     8  Classes, SysUtils, UGame, DOM, XMLConf, fgl, UGameProtocol;
    109
    1110type
     
    1817    FOnReceiveCmd: TCommandEvent;
    1918    procedure ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream);
     19    procedure DoTurnEnd(Sender: TObject);
    2020  public
    2121    Game: TGame;
    2222    Protocol: TGameProtocolServer;
     23    Player: TPlayer;
    2324    procedure DoChange;
    2425    procedure SendCmd(Command: TCommand; DataOut, DataIn: TStream);
     26    procedure TurnStart;
    2527    property OnReceiveCmd: TCommandEvent read FOnReceiveCmd write
    2628      FOnReceiveCmd;
     
    2931  end;
    3032
     33  { TServerClients }
     34
    3135  TServerClients = class(TFPGObjectList<TServerClient>)
    3236    Game: TGame;
     37    function SearchByPlayer(Player: TPlayer): TServerClient;
    3338  end;
    3439
     
    5156    RemoteNetworkAddress: string;
    5257    RemoteNetworkPort: Word;
     58    function GetNewServerClient: TServerClient;
    5359    procedure LoadConfig(Config: TXmlConfig; Path: string);
    5460    procedure SaveConfig(Config: TXmlConfig; Path: string);
     
    6773implementation
    6874
     75{ TServerClients }
     76
     77function TServerClients.SearchByPlayer(Player: TPlayer): TServerClient;
     78var
     79  I: Integer;
     80begin
     81  I := 0;
     82  while (I < Count) and (Items[I].Player <> Player) do Inc(I);
     83  if I < Count then Result := Items[I]
     84    else Result := nil;
     85end;
     86
    6987{ TServerClient }
    7088
     
    7997end;
    8098
     99procedure TServerClient.TurnStart;
     100begin
     101  Protocol.TurnStart;
     102end;
     103
    81104constructor TServerClient.Create;
    82105begin
    83106  Protocol := TGameProtocolServer.Create;
     107  Protocol.OnTurnEnd := DoTurnEnd;
    84108end;
    85109
     
    94118  if Assigned(FOnReceiveCmd) then
    95119    FOnReceiveCmd(Command, DataOut, DataIn);
     120end;
     121
     122procedure TServerClient.DoTurnEnd(Sender: TObject);
     123begin
     124  if Game.Running then Game.NextPlayer;
    96125end;
    97126
     
    153182end;
    154183
    155 procedure TServer.DoChange;
     184procedure TServer.DoChange(Sender: TObject);
    156185var
    157186  Client: TServerClient;
     
    169198    //TODO View.Clear;
    170199  end;
     200end;
     201
     202function TServer.GetNewServerClient: TServerClient;
     203begin
     204  Result := TServerClient.Create;
     205  Clients.Add(Result);
    171206end;
    172207
Note: See TracChangeset for help on using the changeset viewer.