Changeset 202 for trunk/UGameClient.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/UGameClient.pas

    r185 r202  
    66
    77uses
    8   Classes, SysUtils, UGame, Forms, fgl, UGameProtocol;
     8  Classes, SysUtils, UGame, Forms, fgl, UGameProtocol, UGameServer;
    99
    1010type
     11  TClientConnectType = (ctLocal, ctNetwork);
     12
    1113  { TClient }
    1214
    1315  TClient = class
    1416  private
     17    FActive: Boolean;
    1518    FForm: TForm;
    1619    FGame: TGame;
     
    1922    FOnReceive: TCommandEvent;
    2023    FOnMove: TMoveEvent;
     24    procedure SetActive(AValue: Boolean);
    2125    procedure SetControlPlayer(AValue: TPlayer);
    2226    procedure SetForm(AValue: TForm);
     
    2428    procedure PlayerMove(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer;
    2529      Update: Boolean; var Confirm: Boolean);
    26     procedure ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream);
     30  protected
     31    procedure ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream); virtual;
     32    procedure DoTurnStart(Sender: TObject); virtual;
    2733  public
    2834    Name: string;
    2935    View: TView;
     36    LocalServer: TServer;
     37    RemoteAddress: string;
     38    RemotePort: Word;
     39    ConnectType: TClientConnectType;
    3040    Protocol: TGameProtocolClient;
    3141    procedure DoChange;
     
    3848    property OnReceive: TCommandEvent read FOnReceive write FOnReceive;
    3949    property OnChange: TNotifyEvent read FOnChange write FOnChange;
     50    property Active: Boolean read FActive write SetActive;
    4051  end;
    4152
     
    107118end;
    108119
     120procedure TClient.DoTurnStart(Sender: TObject);
     121begin
     122
     123end;
     124
    109125procedure TClient.SetControlPlayer(AValue: TPlayer);
    110126begin
     
    115131  if Assigned(FControlPlayer) then begin
    116132     FControlPlayer.OnMove := PlayerMove;
     133  end;
     134end;
     135
     136procedure TClient.SetActive(AValue: Boolean);
     137var
     138  ServerClient: TServerClient;
     139begin
     140  if FActive = AValue then Exit;
     141  FActive := AValue;
     142  if FActive then begin
     143    case ConnectType of
     144      ctLocal: if LocalServer.Active then begin
     145        ServerClient := LocalServer.GetNewServerClient;
     146        ServerClient.Player := ControlPlayer;
     147        ServerClient.Protocol.Pin.Connect(Protocol.Pin);
     148      end else raise Exception.Create('Local server is not active');
     149      //ctNetwork: ;
     150    end;
     151  end else begin
     152    Protocol.Pin.Disconnect;
    117153  end;
    118154end;
     
    129165  View := TView.Create;
    130166  Protocol := TGameProtocolClient.Create;
     167  Protocol.OnTurnStart := DoTurnStart;
    131168end;
    132169
Note: See TracChangeset for help on using the changeset viewer.