Changeset 213 for trunk/UGameServer.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/UGameServer.pas

    r211 r213  
    66
    77uses
    8   Classes, SysUtils, UGame, DOM, XMLConf, fgl, UGameProtocol;
     8  Classes, SysUtils, UGame, DOM, XMLConf, fgl, UGameProtocol, UCommFrame;
    99
    1010type
     
    1515  TServerClient = class
    1616  private
    17     FOnReceiveCmd: TCommandEvent;
    18     procedure ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream);
    1917    procedure DoTurnEnd(Sender: TObject);
     18    procedure DoSurrender(Sender: TObject);
    2019  public
    2120    Game: TGame;
    2221    Protocol: TGameProtocolServer;
    2322    Player: TPlayer;
     23    CommFrame: TCommFrame;
    2424    procedure DoChange;
    25     procedure SendCmd(Command: TCommand; DataOut, DataIn: TStream);
    2625    procedure TurnStart;
    2726    procedure GameEnd;
    28     property OnReceiveCmd: TCommandEvent read FOnReceiveCmd write
    29       FOnReceiveCmd;
     27    procedure NextPlayer;
    3028    constructor Create;
    3129    destructor Destroy; override;
     
    6260    procedure InitClients;
    6361    procedure GameEnd;
     62    procedure NextPlayer;
    6463    procedure Clear;
    6564    constructor Create;
     
    9493end;
    9594
    96 procedure TServerClient.SendCmd(Command: TCommand; DataOut, DataIn: TStream);
    97 begin
    98 
    99 end;
    100 
    10195procedure TServerClient.TurnStart;
    10296begin
     
    109103end;
    110104
     105procedure TServerClient.NextPlayer;
     106begin
     107  Protocol.NextPlayer;
     108end;
     109
    111110constructor TServerClient.Create;
    112111begin
     112  CommFrame := TCommFrame.Create(nil);
    113113  Protocol := TGameProtocolServer.Create;
    114114  Protocol.OnTurnEnd := DoTurnEnd;
     115  Protocol.OnSurrender := DoSurrender;
     116  Protocol.Pin.Connect(CommFrame.FrameDataPin);
    115117end;
    116118
     
    118120begin
    119121  Protocol.Free;
     122  CommFrame.Free;
    120123  inherited Destroy;
    121124end;
    122125
    123 procedure TServerClient.ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream);
    124 begin
    125   if Assigned(FOnReceiveCmd) then
    126     FOnReceiveCmd(Command, DataOut, DataIn);
    127 end;
    128 
    129126procedure TServerClient.DoTurnEnd(Sender: TObject);
    130127begin
     128  if Game.Running then Game.NextPlayer;
     129end;
     130
     131procedure TServerClient.DoSurrender(Sender: TObject);
     132begin
     133  Player.Surrender;
    131134  if Game.Running then Game.NextPlayer;
    132135end;
     
    249252end;
    250253
     254procedure TServer.NextPlayer;
     255var
     256  I: Integer;
     257begin
     258  for I := 0 to Clients.Count - 1 do
     259    Clients[I].NextPlayer;
     260end;
     261
    251262procedure TServer.Clear;
    252263begin
Note: See TracChangeset for help on using the changeset viewer.