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/UGameProtocol.pas

    r203 r213  
    66
    77uses
    8   Classes, SysUtils, UGame, UVarBlockSerializer, UCommPin, SpecializedList;
     8  Classes, SysUtils, UGame, UVarBlockSerializer, UCommPin, SpecializedList,
     9  UCommFrame;
    910
    1011type
    11   TCommand = (cmdTextMessage, cmdTurnStart, cmdTurnEnd, cmdGameStart, cmdGameEnd);
     12  TCommand = (cmdTextMessage, cmdTurnStart, cmdTurnEnd, cmdGameStart, cmdGameEnd,
     13    cmdSurrender, cmdNextPlayer);
    1214  TCommandEvent = procedure (Command: TCommand; DataIn, DataOut: TStream);
    1315
     
    2224    FOnGameEnd: TNotifyEvent;
    2325    FOnGameStart: TNotifyEvent;
     26    FOnNextPlayer: TNotifyEvent;
    2427    FOnTurnStart: TNotifyEvent;
    2528    procedure Receive(Sender: TCommPin; Stream: TListByte);
     
    2831    Pin: TCommPin;
    2932    procedure TurnEnd;
     33    procedure Surrender;
    3034    procedure SendMessage(Text: string);
    3135    constructor Create;
    3236    destructor Destroy; override;
    33     property OnGameStart: TNotifyEvent read FOnGameStart
    34       write FOnGameStart;
    35     property OnGameEnd: TNotifyEvent read FOnGameEnd
    36       write FOnGameEnd;
    37     property OnTurnStart: TNotifyEvent read FOnTurnStart
    38       write FOnTurnStart;
     37    property OnGameStart: TNotifyEvent read FOnGameStart write FOnGameStart;
     38    property OnGameEnd: TNotifyEvent read FOnGameEnd write FOnGameEnd;
     39    property OnTurnStart: TNotifyEvent read FOnTurnStart write FOnTurnStart;
     40    property OnNextPlayer: TNotifyEvent read FOnNextPlayer write FOnNextPlayer;
    3941  end;
    4042
     
    4648  private
    4749    FOnSendMessage: TSendMessageEvent;
     50    FOnSurrender: TNotifyEvent;
    4851    FOnTurnEnd: TNotifyEvent;
     52    CommFrame: TCommFrame;
    4953    procedure Receive(Sender: TCommPin; Stream: TListByte);
    5054    procedure SendCmd(Command: TCommand);
     
    5660    procedure GameEnd;
    5761    procedure TurnStart;
     62    procedure NextPlayer;
    5863    property OnSendMessage: TSendMessageEvent read FOnSendMessage
    5964      write FOnSendMessage;
    60     property OnTurnEnd: TNotifyEvent read FOnTurnEnd
    61       write FOnTurnEnd;
     65    property OnTurnEnd: TNotifyEvent read FOnTurnEnd write FOnTurnEnd;
     66    property OnSurrender: TNotifyEvent read FOnSurrender write FOnSurrender;
    6267  end;
    6368
     
    8287    if Command = Integer(cmdTurnEnd) then begin
    8388      if Assigned(FOnTurnEnd) then FOnTurnEnd(Self);
     89    end else
     90    if Command = Integer(cmdSurrender) then begin
     91      if Assigned(FOnSurrender) then FOnSurrender(Self);
    8492    end;
    8593  finally
     
    133141end;
    134142
     143procedure TGameProtocolServer.NextPlayer;
     144begin
     145  SendCmd(cmdNextPlayer);
     146end;
     147
    135148{ TGameProtocol }
    136149
     
    153166    if Command = Integer(cmdTurnStart) then begin
    154167      if Assigned(FOnTurnStart) then FOnTurnStart(Self);
     168    end else
     169    if Command = Integer(cmdNextPlayer) then begin
     170      if Assigned(FOnNextPlayer) then FOnNextPlayer(Self);
    155171    end;
    156172  finally
     
    180196begin
    181197  SendCmd(cmdTurnEnd);
     198end;
     199
     200procedure TGameProtocolClient.Surrender;
     201begin
     202  SendCmd(cmdSurrender);
    182203end;
    183204
Note: See TracChangeset for help on using the changeset viewer.