Changeset 202 for trunk/UGameServer.pas
- Timestamp:
- May 17, 2018, 5:41:47 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGameServer.pas
r199 r202 6 6 7 7 uses 8 Classes, SysUtils, UGame, DOM, XMLConf, fgl, 9 UGameProtocol; 8 Classes, SysUtils, UGame, DOM, XMLConf, fgl, UGameProtocol; 10 9 11 10 type … … 18 17 FOnReceiveCmd: TCommandEvent; 19 18 procedure ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream); 19 procedure DoTurnEnd(Sender: TObject); 20 20 public 21 21 Game: TGame; 22 22 Protocol: TGameProtocolServer; 23 Player: TPlayer; 23 24 procedure DoChange; 24 25 procedure SendCmd(Command: TCommand; DataOut, DataIn: TStream); 26 procedure TurnStart; 25 27 property OnReceiveCmd: TCommandEvent read FOnReceiveCmd write 26 28 FOnReceiveCmd; … … 29 31 end; 30 32 33 { TServerClients } 34 31 35 TServerClients = class(TFPGObjectList<TServerClient>) 32 36 Game: TGame; 37 function SearchByPlayer(Player: TPlayer): TServerClient; 33 38 end; 34 39 … … 51 56 RemoteNetworkAddress: string; 52 57 RemoteNetworkPort: Word; 58 function GetNewServerClient: TServerClient; 53 59 procedure LoadConfig(Config: TXmlConfig; Path: string); 54 60 procedure SaveConfig(Config: TXmlConfig; Path: string); … … 67 73 implementation 68 74 75 { TServerClients } 76 77 function TServerClients.SearchByPlayer(Player: TPlayer): TServerClient; 78 var 79 I: Integer; 80 begin 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; 85 end; 86 69 87 { TServerClient } 70 88 … … 79 97 end; 80 98 99 procedure TServerClient.TurnStart; 100 begin 101 Protocol.TurnStart; 102 end; 103 81 104 constructor TServerClient.Create; 82 105 begin 83 106 Protocol := TGameProtocolServer.Create; 107 Protocol.OnTurnEnd := DoTurnEnd; 84 108 end; 85 109 … … 94 118 if Assigned(FOnReceiveCmd) then 95 119 FOnReceiveCmd(Command, DataOut, DataIn); 120 end; 121 122 procedure TServerClient.DoTurnEnd(Sender: TObject); 123 begin 124 if Game.Running then Game.NextPlayer; 96 125 end; 97 126 … … 153 182 end; 154 183 155 procedure TServer.DoChange ;184 procedure TServer.DoChange(Sender: TObject); 156 185 var 157 186 Client: TServerClient; … … 169 198 //TODO View.Clear; 170 199 end; 200 end; 201 202 function TServer.GetNewServerClient: TServerClient; 203 begin 204 Result := TServerClient.Create; 205 Clients.Add(Result); 171 206 end; 172 207
Note:
See TracChangeset
for help on using the changeset viewer.