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/Forms/UFormClient.pas

    r211 r213  
    1919
    2020  TFormClient = class(TForm)
     21    ASurrender: TAction;
    2122    AGameEndTurn: TAction;
    2223    AStatusBarVisible: TAction;
     
    3334    Timer1: TTimer;
    3435    ToolBar1: TToolBar;
     36    ToolButton1: TToolButton;
    3537    ToolButton2: TToolButton;
    3638    ToolButton6: TToolButton;
     
    4042    procedure AGameEndTurnExecute(Sender: TObject);
    4143    procedure AStatusBarVisibleExecute(Sender: TObject);
     44    procedure ASurrenderExecute(Sender: TObject);
    4245    procedure AToolBarBigIconsExecute(Sender: TObject);
    4346    procedure AToolBarVisibleExecute(Sender: TObject);
     
    8083    procedure DoClientChange(Sender: TObject);
    8184    procedure DoGameEnd(Sender: TObject);
     85    procedure DoNextPlayer(Sender: TObject);
    8286    procedure DoTurnStart(Sender: TObject);
    8387    procedure DoMove(CellFrom, CellTo: TCell; var CountOnce,
     
    103107resourcestring
    104108  STurn = 'turn';
     109  SSurrender = 'Surrender';
     110  SSurrenderQuestion = 'Do you want to surrender current game?';
    105111
    106112{$R *.lfm}
     
    233239    FClient.OnDestroy := DoClientDestroy;
    234240    FClient.OnGameEnd := DoGameEnd;
     241    FClient.OnNextPlayer := DoNextPlayer;
    235242    FClient.View.DestRect := TRect.CreateBounds(TPoint.Create(0, 0), TPoint.Create(PaintBox1.Width, PaintBox1.Height));
    236243  end;
     
    248255end;
    249256
     257procedure TFormClient.DoNextPlayer(Sender: TObject);
     258begin
     259  Redraw;
     260end;
     261
    250262procedure TFormClient.DoTurnStart(Sender: TObject);
    251263begin
    252264  TurnActive := True;
    253   Synchronize(UpdateInterface);
    254   Synchronize(Redraw);
     265  UpdateInterface;
     266  Redraw;
    255267end;
    256268
     
    290302  ToolBar1.Visible := AToolBarVisible.Checked;
    291303  StatusBar1.Visible := AStatusBarVisible.Checked;
    292   AGameEndTurn.Enabled := TurnActive;
     304  AGameEndTurn.Enabled := Assigned(Client.ControlPlayer) and
     305    Client.ControlPlayer.IsAlive and TurnActive;
     306  ASurrender.Enabled := Assigned(Client.ControlPlayer) and
     307    Client.ControlPlayer.IsAlive;
    293308end;
    294309
     
    339354  AStatusBarVisible.Checked := not AStatusBarVisible.Checked;
    340355  UpdateInterface;
     356end;
     357
     358procedure TFormClient.ASurrenderExecute(Sender: TObject);
     359begin
     360  if MessageDlg(SSurrender, SSurrenderQuestion, mtConfirmation, mbYesNo, 0) =
     361    mrYes then begin
     362      Client.Protocol.Surrender;
     363      UpdateInterface;
     364    end;
    341365end;
    342366
Note: See TracChangeset for help on using the changeset viewer.