Changeset 180 for trunk/UGame.pas


Ignore:
Timestamp:
Feb 8, 2018, 5:32:31 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Client related interface moved from FormMain to FormClient. This code change will later allow to implement network client-server gameplay.
  • Added: Allow to open other spectator client windows.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r179 r180  
    66
    77uses
    8   Classes, SysUtils, ExtCtrls, Graphics, XMLConf, XMLRead, XMLWrite,
     8  Classes, SysUtils, ExtCtrls, Graphics, XMLConf, XMLRead, XMLWrite, Forms,
    99  DOM, Math, LazFileUtils, UXMLUtils, Dialogs, Types, LCLType, LCLIntf, fgl,
    1010  UGeometry, UGameSocket;
     
    421421    FGame: TGame;
    422422    FControlPlayer: TPlayer;
     423    FOnChange: TNotifyEvent;
    423424    FOnReceive: TReceiveEvent;
    424425    procedure SetControlPlayer(AValue: TPlayer);
    425426    procedure SetGame(AValue: TGame);
     427    procedure DoChange;
    426428  public
     429    Form: TForm;
    427430    Name: string;
    428431    View: TView;
     
    434437    property Game: TGame read FGame write SetGame;
    435438    property OnReceive: TReceiveEvent read FOnReceive write FOnReceive;
     439    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    436440  end;
    437441
     
    440444  TClients = class(TFPGObjectList<TClient>)
    441445    Game: TGame;
    442     procedure New(Name: string);
     446    function New(Name: string): TClient;
    443447    constructor Create(FreeObjects: Boolean = True);
    444448  end;
     
    534538    procedure SetGame(AValue: TGame);
    535539    procedure SetServerMode(AValue: TServerMode);
     540    procedure DoChange;
    536541  public
    537542    Clients: TClients;
     
    565570resourcestring
    566571  SPlayer = 'Player';
     572  SSpectator = 'Spectator';
    567573
    568574
     
    650656{ TClients }
    651657
    652 procedure TClients.New(Name: string);
    653 var
    654   NewClient: TClient;
    655 begin
    656   NewClient := TClient.Create;
    657   NewClient.Game := Game;
    658   NewClient.Name := Name;
    659   Add(NewClient);
     658function TClients.New(Name: string): TClient;
     659begin
     660  Result := TClient.Create;
     661  Result.Game := Game;
     662  Result.Name := Name;
     663  Add(Result);
    660664end;
    661665
     
    673677  FGame := AValue;
    674678  View.Game := AValue;
     679end;
     680
     681procedure TClient.DoChange;
     682begin
     683  if Assigned(FOnChange) then
     684    FOnChange(Self);
    675685end;
    676686
     
    32013211end;
    32023212
     3213procedure TServer.DoChange;
     3214var
     3215  Client: TClient;
     3216begin
     3217  for Client in Clients do
     3218    Client.DoChange;
     3219end;
     3220
    32033221procedure TServer.LoadConfig(Config: TXmlConfig; Path: string);
    32043222begin
     
    32293247begin
    32303248  Clients.Clear;
    3231   Clients.New('Spectator');
     3249  Clients.New(SSpectator);
    32323250
    32333251  for Player in Game.Players do
    32343252  with Player do
    32353253  if Mode = pmHuman then begin
    3236     Clients.New(Player.Name);
    3237     Player.Client := TClient(Clients.Last);
     3254    Player.Client := Clients.New(Player.Name);
    32383255  end;
    32393256
     
    35863603  // For computers take view from previous human
    35873604  //if CurrentPlayer.Mode = pmComputer then CurrentPlayer.View.Assign(PrevPlayer.View);
     3605  Server.DoChange;
    35883606end;
    35893607
Note: See TracChangeset for help on using the changeset viewer.