Changeset 213 for trunk/UGameClient.pas
- Timestamp:
- May 24, 2018, 9:25:17 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGameClient.pas
r211 r213 6 6 7 7 uses 8 Classes, SysUtils, UGame, Forms, fgl, UGameProtocol, UGameServer, UCommThread; 8 Classes, SysUtils, UGame, Forms, fgl, UGameProtocol, UGameServer, UCommThread, 9 UThreading, UCommFrame; 9 10 10 11 type … … 22 23 FOnDestroy: TNotifyEvent; 23 24 FOnGameEnd: TNotifyEvent; 25 FOnNextPlayer: TNotifyEvent; 24 26 FOnReceive: TCommandEvent; 25 27 FOnMove: TMoveEvent; 26 28 FOnTurnStart: TNotifyEvent; 27 29 CommThread: TCommThread; 30 CommFrame: TCommFrame; 28 31 procedure SetActive(AValue: Boolean); 29 32 procedure SetControlPlayer(AValue: TPlayer); … … 35 38 protected 36 39 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; 39 46 public 40 47 Name: string; … … 51 58 property Game: TGame read FGame write SetGame; 52 59 property Form: TForm read FForm write SetForm; 60 property Active: Boolean read FActive write SetActive; 53 61 property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy; 54 62 property OnMove: TMoveEvent read FOnMove write SetOnMove; … … 57 65 property OnTurnStart: TNotifyEvent read FOnTurnStart write FOnTurnStart; 58 66 property OnGameEnd: TNotifyEvent read FOnGameEnd write FOnGameEnd; 59 property Active: Boolean read FActive write SetActive;67 property OnNextPlayer: TNotifyEvent read FOnNextPlayer write FOnNextPlayer; 60 68 end; 61 69 … … 133 141 end; 134 142 135 procedure TClient.DoTurnStart(Sender: TObject); 143 procedure TClient.DoTurnStartHandler(Sender: TObject); 144 begin 145 Synchronize(DoTurnStart); 146 end; 147 148 procedure TClient.DoTurnStart; 136 149 begin 137 150 if Assigned(FOnTurnStart) then … … 139 152 end; 140 153 141 procedure TClient.DoGameEnd(Sender: TObject); 142 begin 143 if Assigned(FOnGameEnd) then 144 FOnGameEnd(Self); 154 procedure TClient.DoGameEndHandler(Sender: TObject); 155 begin 156 Synchronize(DoGameEnd); 157 end; 158 159 procedure TClient.DoGameEnd; 160 begin 161 if Assigned(FOnGameEnd) then FOnGameEnd(Self); 162 end; 163 164 procedure TClient.DoNextPlayerHandler(Sender: TObject); 165 begin 166 Synchronize(DoNextPlayer); 167 end; 168 169 procedure TClient.DoNextPlayer; 170 begin 171 if Assigned(FOnNextPlayer) then FOnNextPlayer(Self); 145 172 end; 146 173 … … 174 201 case ConnectType of 175 202 ctLocal: if LocalServer.Active then begin 203 CommFrame.FrameDataPin.Connect(Protocol.Pin); 204 CommFrame.RawDataPin.Connect(CommThread.Pin); 176 205 CommThread.Active := True; 177 Comm Thread.Pin.Connect(Protocol.Pin);206 CommFrame.Active := True; 178 207 ServerClient := LocalServer.GetNewServerClient; 179 208 ServerClient.Player := ControlPlayer; 180 ServerClient. Protocol.Pin.Connect(CommThread.Ext);209 ServerClient.CommFrame.RawDataPin.Connect(CommThread.Ext); 181 210 end else raise Exception.Create('Local server is not active'); 182 211 //ctNetwork: ; … … 196 225 begin 197 226 CommThread := TCommThread.Create(nil); 227 CommFrame := TCommFrame.Create(nil); 198 228 FControlPlayer := nil; 199 229 View := TView.Create; 200 230 Protocol := TGameProtocolClient.Create; 201 Protocol.OnTurnStart := DoTurnStart; 202 Protocol.OnGameEnd := DoGameEnd; 231 Protocol.OnTurnStart := DoTurnStartHandler; 232 Protocol.OnGameEnd := DoGameEndHandler; 233 Protocol.OnNextPlayer := DoNextPlayerHandler; 203 234 end; 204 235 … … 210 241 FreeAndNil(Protocol); 211 242 FreeAndNil(CommThread); 243 FreeAndNil(CommFrame); 212 244 inherited Destroy; 213 245 end;
Note:
See TracChangeset
for help on using the changeset viewer.