Changeset 213 for trunk/UGameClient.pas


Ignore:
Timestamp:
May 24, 2018, 9:25:17 PM (6 years ago)
Author:
chronos
Message:
  • Added: Button with action to surrender the game.
  • Fixed: Added framing comm component for correct separation of network messages.
  • Added: New game protocol command NextPlayer. GUI client will redraw map on this event to see how other players/AI fight each other.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGameClient.pas

    r211 r213  
    66
    77uses
    8   Classes, SysUtils, UGame, Forms, fgl, UGameProtocol, UGameServer, UCommThread;
     8  Classes, SysUtils, UGame, Forms, fgl, UGameProtocol, UGameServer, UCommThread,
     9  UThreading, UCommFrame;
    910
    1011type
     
    2223    FOnDestroy: TNotifyEvent;
    2324    FOnGameEnd: TNotifyEvent;
     25    FOnNextPlayer: TNotifyEvent;
    2426    FOnReceive: TCommandEvent;
    2527    FOnMove: TMoveEvent;
    2628    FOnTurnStart: TNotifyEvent;
    2729    CommThread: TCommThread;
     30    CommFrame: TCommFrame;
    2831    procedure SetActive(AValue: Boolean);
    2932    procedure SetControlPlayer(AValue: TPlayer);
     
    3538  protected
    3639    procedure ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream); virtual;
    37     procedure DoTurnStart(Sender: TObject); virtual;
    38     procedure DoGameEnd(Sender: TObject);
     40    procedure DoTurnStartHandler(Sender: TObject); virtual;
     41    procedure DoTurnStart; virtual;
     42    procedure DoGameEndHandler(Sender: TObject);
     43    procedure DoGameEnd;
     44    procedure DoNextPlayerHandler(Sender: TObject);
     45    procedure DoNextPlayer;
    3946  public
    4047    Name: string;
     
    5158    property Game: TGame read FGame write SetGame;
    5259    property Form: TForm read FForm write SetForm;
     60    property Active: Boolean read FActive write SetActive;
    5361    property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
    5462    property OnMove: TMoveEvent read FOnMove write SetOnMove;
     
    5765    property OnTurnStart: TNotifyEvent read FOnTurnStart write FOnTurnStart;
    5866    property OnGameEnd: TNotifyEvent read FOnGameEnd write FOnGameEnd;
    59     property Active: Boolean read FActive write SetActive;
     67    property OnNextPlayer: TNotifyEvent read FOnNextPlayer write FOnNextPlayer;
    6068  end;
    6169
     
    133141end;
    134142
    135 procedure TClient.DoTurnStart(Sender: TObject);
     143procedure TClient.DoTurnStartHandler(Sender: TObject);
     144begin
     145  Synchronize(DoTurnStart);
     146end;
     147
     148procedure TClient.DoTurnStart;
    136149begin
    137150  if Assigned(FOnTurnStart) then
     
    139152end;
    140153
    141 procedure TClient.DoGameEnd(Sender: TObject);
    142 begin
    143   if Assigned(FOnGameEnd) then
    144     FOnGameEnd(Self);
     154procedure TClient.DoGameEndHandler(Sender: TObject);
     155begin
     156  Synchronize(DoGameEnd);
     157end;
     158
     159procedure TClient.DoGameEnd;
     160begin
     161  if Assigned(FOnGameEnd) then FOnGameEnd(Self);
     162end;
     163
     164procedure TClient.DoNextPlayerHandler(Sender: TObject);
     165begin
     166  Synchronize(DoNextPlayer);
     167end;
     168
     169procedure TClient.DoNextPlayer;
     170begin
     171  if Assigned(FOnNextPlayer) then FOnNextPlayer(Self);
    145172end;
    146173
     
    174201    case ConnectType of
    175202      ctLocal: if LocalServer.Active then begin
     203        CommFrame.FrameDataPin.Connect(Protocol.Pin);
     204        CommFrame.RawDataPin.Connect(CommThread.Pin);
    176205        CommThread.Active := True;
    177         CommThread.Pin.Connect(Protocol.Pin);
     206        CommFrame.Active := True;
    178207        ServerClient := LocalServer.GetNewServerClient;
    179208        ServerClient.Player := ControlPlayer;
    180         ServerClient.Protocol.Pin.Connect(CommThread.Ext);
     209        ServerClient.CommFrame.RawDataPin.Connect(CommThread.Ext);
    181210      end else raise Exception.Create('Local server is not active');
    182211      //ctNetwork: ;
     
    196225begin
    197226  CommThread := TCommThread.Create(nil);
     227  CommFrame := TCommFrame.Create(nil);
    198228  FControlPlayer := nil;
    199229  View := TView.Create;
    200230  Protocol := TGameProtocolClient.Create;
    201   Protocol.OnTurnStart := DoTurnStart;
    202   Protocol.OnGameEnd := DoGameEnd;
     231  Protocol.OnTurnStart := DoTurnStartHandler;
     232  Protocol.OnGameEnd := DoGameEndHandler;
     233  Protocol.OnNextPlayer := DoNextPlayerHandler;
    203234end;
    204235
     
    210241  FreeAndNil(Protocol);
    211242  FreeAndNil(CommThread);
     243  FreeAndNil(CommFrame);
    212244  inherited Destroy;
    213245end;
Note: See TracChangeset for help on using the changeset viewer.