Changeset 203 for trunk/UGameClient.pas


Ignore:
Timestamp:
May 18, 2018, 12:54:37 AM (6 years ago)
Author:
chronos
Message:
  • Fixed: Player turn start/end signaling from server to clients.
  • Added: Save action to save game without opening save dialog.
  • Fixed: Move dialog was not opened after new game was created.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGameClient.pas

    r202 r203  
    66
    77uses
    8   Classes, SysUtils, UGame, Forms, fgl, UGameProtocol, UGameServer;
     8  Classes, SysUtils, UGame, Forms, fgl, UGameProtocol, UGameServer, UCommThread;
    99
    1010type
     
    2222    FOnReceive: TCommandEvent;
    2323    FOnMove: TMoveEvent;
     24    FOnTurnStart: TNotifyEvent;
     25    CommThread: TCommThread;
    2426    procedure SetActive(AValue: Boolean);
    2527    procedure SetControlPlayer(AValue: TPlayer);
     
    2830    procedure PlayerMove(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer;
    2931      Update: Boolean; var Confirm: Boolean);
     32    procedure SetOnMove(AValue: TMoveEvent);
    3033  protected
    3134    procedure ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream); virtual;
     
    4548    property Game: TGame read FGame write SetGame;
    4649    property Form: TForm read FForm write SetForm;
    47     property OnMove: TMoveEvent read FOnMove write FOnMove;
     50    property OnMove: TMoveEvent read FOnMove write SetOnMove;
    4851    property OnReceive: TCommandEvent read FOnReceive write FOnReceive;
    4952    property OnChange: TNotifyEvent read FOnChange write FOnChange;
     53    property OnTurnStart: TNotifyEvent read FOnTurnStart write FOnTurnStart;
    5054    property Active: Boolean read FActive write SetActive;
    5155  end;
     
    113117end;
    114118
     119procedure TClient.SetOnMove(AValue: TMoveEvent);
     120begin
     121  //if FOnMove = AValue then Exit;
     122  FOnMove := AValue;
     123end;
     124
    115125procedure TClient.ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream);
    116126begin
     
    120130procedure TClient.DoTurnStart(Sender: TObject);
    121131begin
    122 
     132  if Assigned(FOnTurnStart) then
     133    FOnTurnStart(Self);
    123134end;
    124135
     
    139150begin
    140151  if FActive = AValue then Exit;
     152  if FActive then begin
     153    case ConnectType of
     154      ctLocal: begin
     155        CommThread.Active := False;
     156        CommThread.Ext.Disconnect;
     157        CommThread.Pin.Disconnect;
     158      end;
     159    end;
     160  end;
    141161  FActive := AValue;
    142162  if FActive then begin
    143163    case ConnectType of
    144164      ctLocal: if LocalServer.Active then begin
     165        CommThread.Active := True;
     166        CommThread.Pin.Connect(Protocol.Pin);
    145167        ServerClient := LocalServer.GetNewServerClient;
    146168        ServerClient.Player := ControlPlayer;
    147         ServerClient.Protocol.Pin.Connect(Protocol.Pin);
     169        ServerClient.Protocol.Pin.Connect(CommThread.Ext);
    148170      end else raise Exception.Create('Local server is not active');
    149171      //ctNetwork: ;
     
    162184constructor TClient.Create;
    163185begin
     186  CommThread := TCommThread.Create(nil);
    164187  FControlPlayer := nil;
    165188  View := TView.Create;
     
    173196  FreeAndNil(View);
    174197  FreeAndNil(Protocol);
     198  FreeAndNil(CommThread);
    175199  inherited Destroy;
    176200end;
Note: See TracChangeset for help on using the changeset viewer.