close Warning: Can't synchronize with repository "(default)" (No changeset 184 in the repository). Look in the Trac log for more information.

Changeset 183


Ignore:
Timestamp:
Feb 9, 2018, 10:33:18 AM (6 years ago)
Author:
chronos
Message:
  • Modified: Units move handling was moved from Core to FormClient as it is game client related functionality.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormClient.pas

    r180 r183  
    7676    procedure SetClient(AValue: TClient);
    7777    procedure DoClientChange(Sender: TObject);
     78    procedure DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
     79      CountRepeat: Integer; Update: Boolean; var Confirm: Boolean);
    7880  public
    7981    property Client: TClient read FClient write SetClient;
     
    9092
    9193uses
    92   UCore;
     94  UCore, UFormMove;
    9395
    9496resourcestring
     
    98100
    99101{ TFormClient }
     102
     103procedure TFormClient.DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
     104  CountRepeat: Integer; Update: Boolean; var Confirm: Boolean);
     105var
     106  I: Integer;
     107  FormMove: TFormMove;
     108begin
     109  FormMove := TFormMove.Create(nil);
     110  try
     111    if Update then FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower + CountOnce
     112      else FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower;
     113    FormMove.SpinEditOnce.Value := CountOnce;
     114    FormMove.TrackBarOnce.Max := FormMove.SpinEditOnce.MaxValue;
     115    FormMove.TrackBarOnce.Position := FormMove.SpinEditOnce.Value;
     116    FormMove.SpinEditRepeat.MaxValue := Client.Game.Map.MaxPower;
     117    FormMove.SpinEditRepeat.Value := CountRepeat;
     118    FormMove.TrackBarRepeat.Max := FormMove.SpinEditRepeat.MaxValue;
     119    FormMove.TrackBarRepeat.Position := FormMove.SpinEditRepeat.Value;
     120    FormMove.DefendCount := CellTo.Power;
     121    // Attack count from other surrounding cells without current move if already exists
     122    FormMove.AttackCount := 0;
     123    for I := 0 to CellTo.MovesTo.Count - 1 do
     124    if TUnitMove(CellTo.MovesTo[I]).CellFrom <> CellFrom then
     125      FormMove.AttackCount := FormMove.AttackCount + TUnitMove(CellTo.MovesTo[I]).CountOnce;
     126    FormMove.ShowWinProbability := CellTo.Player <> CellFrom.Player;
     127
     128    if FormMove.ShowModal = mrOk then begin
     129      CountOnce := FormMove.SpinEditOnce.Value;
     130      CountRepeat := FormMove.SpinEditRepeat.Value;
     131      Confirm := True;
     132    end else Confirm := False;
     133  finally
     134    FormMove.Free;
     135  end;
     136end;
    100137
    101138procedure TFormClient.PaintBox1Paint(Sender: TObject);
     
    165202begin
    166203  if FClient = AValue then Exit;
     204  if Assigned(FClient) then FClient.Form := nil;
    167205  FClient := AValue;
    168   if Assigned(FClient) then
     206  if Assigned(FClient) then begin
     207    FClient.Form := Self;
    169208    FClient.OnChange := DoClientChange;
     209    FClient.OnMove := DoOnMove;
     210  end;
    170211  Redraw;
    171212end;
     
    298339procedure TFormClient.FormDestroy(Sender: TObject);
    299340begin
     341  Client := nil;
    300342  TempBitmap.Free;
    301343end;
  • trunk/Forms/UFormNew.pas

    r179 r183  
    319319procedure TFormNew.APlayerModifyExecute(Sender: TObject);
    320320begin
    321   if Assigned(ListViewPlayers.Selected) then begin
    322     FormPlayer.Load(TPlayer(ListViewPlayers.Selected.Data));
    323     if FormPlayer.ShowModal = mrOk then begin
    324       FormPlayer.Save(TPlayer(ListViewPlayers.Selected.Data));
    325       ReloadView;
     321  FormPlayer := TFormPlayer.Create(nil);
     322  try
     323    if Assigned(ListViewPlayers.Selected) then begin
     324      FormPlayer.Load(TPlayer(ListViewPlayers.Selected.Data));
     325       if FormPlayer.ShowModal = mrOk then begin
     326         FormPlayer.Save(TPlayer(ListViewPlayers.Selected.Data));
     327         ReloadView;
     328      end;
    326329    end;
     330  finally
     331    FormPlayer.Free;
    327332  end;
    328333end;
  • trunk/Forms/UFormPlayer.lfm

    r134 r183  
    99  Constraints.MinHeight = 344
    1010  Constraints.MinWidth = 522
     11  DesignTimePPI = 120
     12  OnClose = FormClose
    1113  OnShow = FormShow
    1214  Position = poMainFormCenter
    13   LCLVersion = '1.6.4.0'
     15  LCLVersion = '1.8.0.6'
    1416  object Label1: TLabel
    1517    Left = 24
    16     Height = 24
     18    Height = 20
    1719    Top = 27
    18     Width = 56
     20    Width = 43
    1921    Caption = 'Name:'
    2022    ParentColor = False
     
    2224  object EditName: TEdit
    2325    Left = 168
    24     Height = 34
     26    Height = 28
    2527    Top = 27
    2628    Width = 339
     
    5153  object ComboBoxMode: TComboBox
    5254    Left = 168
    53     Height = 34
     55    Height = 28
    5456    Top = 72
    5557    Width = 339
    5658    Anchors = [akTop, akLeft, akRight]
    57     ItemHeight = 0
     59    ItemHeight = 20
    5860    ItemIndex = 0
    5961    Items.Strings = (
     
    6870  object Label2: TLabel
    6971    Left = 24
    70     Height = 24
     72    Height = 20
    7173    Top = 72
    72     Width = 53
     74    Width = 42
    7375    Caption = 'Mode:'
    7476    ParentColor = False
     
    7678  object Label3: TLabel
    7779    Left = 24
    78     Height = 24
     80    Height = 20
    7981    Top = 128
    80     Width = 50
     82    Width = 39
    8183    Caption = 'Color:'
    8284    ParentColor = False
     
    8486  object ColorBox1: TColorBox
    8587    Left = 168
    86     Height = 38
     88    Height = 26
    8789    Top = 120
    8890    Width = 339
     
    9496  object Label4: TLabel
    9597    Left = 24
    96     Height = 24
     98    Height = 20
    9799    Top = 168
    98     Width = 98
     100    Width = 74
    99101    Caption = 'Agressivity:'
    100102    ParentColor = False
     
    102104  object ComboBoxAgressivity: TComboBox
    103105    Left = 168
    104     Height = 34
     106    Height = 28
    105107    Top = 168
    106108    Width = 339
    107109    Anchors = [akTop, akLeft, akRight]
    108     ItemHeight = 0
     110    ItemHeight = 20
    109111    Items.Strings = (
    110112      'Low'
     
    118120  object CheckBoxDefensive: TCheckBox
    119121    Left = 24
    120     Height = 28
     122    Height = 24
    121123    Top = 208
    122     Width = 107
     124    Width = 89
    123125    Caption = 'Defensive'
    124126    TabOrder = 6
     
    126128  object Label5: TLabel
    127129    Left = 24
    128     Height = 24
     130    Height = 20
    129131    Top = 248
    130     Width = 94
     132    Width = 69
    131133    Caption = 'Start units:'
    132134    ParentColor = False
     
    134136  object SpinEditStartUnits: TSpinEdit
    135137    Left = 224
    136     Height = 34
     138    Height = 28
    137139    Top = 240
    138140    Width = 112
  • trunk/Forms/UFormPlayer.pas

    r134 r183  
    2828    SpinEditStartUnits: TSpinEdit;
    2929    procedure ComboBoxModeChange(Sender: TObject);
     30    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    3031    procedure FormShow(Sender: TObject);
    3132  private
     
    4546{$R *.lfm}
    4647
     48uses
     49  UCore;
     50
    4751resourcestring
    4852  SHuman = 'Human';
     
    5963end;
    6064
     65procedure TFormPlayer.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     66begin
     67  Core.PersistentForm.Save(Self);
     68end;
     69
    6170procedure TFormPlayer.FormShow(Sender: TObject);
    6271begin
     72  Core.PersistentForm.Load(Self);
     73  Translate;
    6374  UpdateInterface;
    6475end;
     
    6879  LastIndex: Integer;
    6980begin
     81  Core.CoolTranslator1.TranslateComponentRecursive(Self);
    7082  with ComboBoxMode do begin
    7183    LastIndex := ItemIndex;
  • trunk/Languages/xtactics.cs.po

    r182 r183  
    475475
    476476#: tformnew.tabsheetmode.caption
     477msgctxt "tformnew.tabsheetmode.caption"
    477478msgid "Mode"
    478479msgstr "Režim"
     
    536537
    537538#: tformplayersstats.listview1.columns[1].caption
     539msgctxt "tformplayersstats.listview1.columns[1].caption"
    538540msgid "Mode"
    539541msgstr "Režim"
     
    700702
    701703#: uformhelp.scontent
    702 msgid "xTactics is a risk based strategic game. Main focus of the game is to offer player various possibilities to configure game conditions. Map for game is generated randomly for each play. Game is multiplayer so single player can play with other human opponents or with many computer opponents.\n"
     704msgid ""
     705"xTactics is a risk based strategic game. Main focus of the game is to offer player various possibilities to configure game conditions. Map for game is generated randomly for each play. Game is multiplayer so single player can play with other human opponents or with many computer opponents.\n"
    703706"\n"
    704707"Each cell has defined number of units which can be instructed to attack enemy or neutral adjacent cells. Units can also defend against enemy attach from adjacent cells. You can move units inside your territory. \n"
     
    706709"\n"
    707710"Resolution of attack of units is determined by rule similar to one which is used in Risk game. Battle consist of several fights. Each fight attacker can use up to 3 units and defender up to 2 units. Number of units for each side determine number of dices. Both sides roll their dices and order them in descending order. Each side takes one dice with highest value. One who has dice with higher value wins. In case of tie, defender wins. Loser lose its unit and another pair of dices is evaluated. This process is calculated automatically and for each planned attack win probability is displayed.\n"
    708 ""
    709 msgstr "xTactics je strategická hra založena na hře Risk. Hlavní zaměření hry je nabídnout hráči různé možnosti k nastavení podmínek hry. Mapa hry je generována náhodně pro každou hru. Hra je pro více hráčů takže jeden hráč může hrát s dalšími lidskými protivníky nebo s mnoha počítačovými protivníky.\n"
     711msgstr ""
     712"xTactics je strategická hra založena na hře Risk. Hlavní zaměření hry je nabídnout hráči různé možnosti k nastavení podmínek hry. Mapa hry je generována náhodně pro každou hru. Hra je pro více hráčů takže jeden hráč může hrát s dalšími lidskými protivníky nebo s mnoha počítačovými protivníky.\n"
    710713"\n"
    711714"Každá buňka má určitý počet jednotek, které mohou být použity k útoku na přilehlé nepřátelské nebo neutrální buňky. Jednotky se mohou bránit proti nepřátelském útoku z přilehlých buněk. Můžete přesouvat jednotky uvnitř území.\n"
     
    713716"\n"
    714717"Vyhodnocení útoku jednotek je určen pravidlem podobným tomu, které je použito u hry Risk. Bitva se skládá z několika bojů. Každá boj útočník může použít do 3 jednotek a obránce do 2 jednotek. Počet jednotek pro každou stranu určuje počet kostek. Obě strany házejí jejich kostkami a seřadí je v sestupném pořadí. Každá strana bere jednu kostku s nejvyšší hodnotou. Ten, který má kostku s vyšší hodnotou vyhrává. V případě remízy, vyhrává obránce. Prohrávající ztrácí své jednotky a další pár kostek je vyhodnocen. Tento proces je vypočítáván automaticky a pro každý plánovaný útok je zobrazena odhadovaná pravděpodobnost.\n"
    715 ""
    716718
    717719#: uformmain.sturn
  • trunk/Languages/xtactics.po

    r182 r183  
    460460
    461461#: tformnew.tabsheetmode.caption
     462msgctxt "tformnew.tabsheetmode.caption"
    462463msgid "Mode"
    463464msgstr ""
     
    521522
    522523#: tformplayersstats.listview1.columns[1].caption
     524msgctxt "tformplayersstats.listview1.columns[1].caption"
    523525msgid "Mode"
    524526msgstr ""
  • trunk/UCore.pas

    r182 r183  
    6767    procedure DoPlayerChange(Sender: TObject);
    6868    procedure DoMoveUpdated(UnitMove: TUnitMove);
    69     procedure DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
    70       CountRepeat: Integer; Update: Boolean; var Confirm: Boolean);
    7169    procedure DoOnWin(Player: TPlayer);
    7270    procedure Delay(Time: Integer);
     
    106104
    107105uses
    108   UFormMove, UFormMain, UFormNew, UFormSettings, UFormAbout, UFormPlayer,
     106  UFormMove, UFormMain, UFormNew, UFormSettings, UFormAbout,
    109107  UFormHelp, UFormCharts, UFormUnitMoves, UFormPlayersStats;
    110108
     
    123121
    124122{ TCore }
    125 
    126 procedure TCore.DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
    127   CountRepeat: Integer; Update: Boolean; var Confirm: Boolean);
    128 var
    129   I: Integer;
    130 begin
    131   if Update then FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower + CountOnce
    132     else FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower;
    133   FormMove.SpinEditOnce.Value := CountOnce;
    134   FormMove.TrackBarOnce.Max := FormMove.SpinEditOnce.MaxValue;
    135   FormMove.TrackBarOnce.Position := FormMove.SpinEditOnce.Value;
    136   FormMove.SpinEditRepeat.MaxValue := Game.Map.MaxPower;
    137   FormMove.SpinEditRepeat.Value := CountRepeat;
    138   FormMove.TrackBarRepeat.Max := FormMove.SpinEditRepeat.MaxValue;
    139   FormMove.TrackBarRepeat.Position := FormMove.SpinEditRepeat.Value;
    140   FormMove.DefendCount := CellTo.Power;
    141   // Attack count from other surrounding cells without current move if already exists
    142   FormMove.AttackCount := 0;
    143   for I := 0 to CellTo.MovesTo.Count - 1 do
    144   if TUnitMove(CellTo.MovesTo[I]).CellFrom <> CellFrom then
    145     FormMove.AttackCount := FormMove.AttackCount + TUnitMove(CellTo.MovesTo[I]).CountOnce;
    146   FormMove.ShowWinProbability := CellTo.Player <> CellFrom.Player;
    147 
    148   if FormMove.ShowModal = mrOk then begin
    149     CountOnce := FormMove.SpinEditOnce.Value;
    150     CountRepeat := FormMove.SpinEditRepeat.Value;
    151     Confirm := True;
    152   end else Confirm := False;
    153 end;
    154123
    155124procedure TCore.DoOnWin(Player: TPlayer);
     
    401370begin
    402371  UGame.InitStrings;
    403   FormPlayer.Translate;
    404372end;
    405373
     
    408376  Server := TServer.Create;
    409377  Game := TGame.Create;
    410   Game.OnMove := DoOnMove;
    411378  Game.OnMoveUpdated := DoMoveUpdated;
    412379  Game.OnWin := DoOnWin;
     
    485452  Form.AZoomAll.Execute;
    486453  Form.Show;
     454  FormClients.Add(Form);
    487455end;
    488456
  • trunk/UGame.pas

    r180 r183  
    415415  end;
    416416
     417  TMoveEvent = procedure(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer;
     418    Update: Boolean; var Confirm: Boolean) of object;
     419
    417420  { TClient }
    418421
    419422  TClient = class
    420423  private
     424    FForm: TForm;
    421425    FGame: TGame;
    422426    FControlPlayer: TPlayer;
    423427    FOnChange: TNotifyEvent;
    424428    FOnReceive: TReceiveEvent;
     429    FOnMove: TMoveEvent;
    425430    procedure SetControlPlayer(AValue: TPlayer);
     431    procedure SetForm(AValue: TForm);
    426432    procedure SetGame(AValue: TGame);
    427433    procedure DoChange;
    428434  public
    429     Form: TForm;
    430435    Name: string;
    431436    View: TView;
     
    436441    property ControlPlayer: TPlayer read FControlPlayer write SetControlPlayer;
    437442    property Game: TGame read FGame write SetGame;
     443    property Form: TForm read FForm write SetForm;
     444    property OnMove: TMoveEvent read FOnMove write FOnMove;
    438445    property OnReceive: TReceiveEvent read FOnReceive write FOnReceive;
    439446    property OnChange: TNotifyEvent read FOnChange write FOnChange;
     
    450457  { TGame }
    451458
    452   TMoveEvent = procedure(CellFrom, CellTo: TCell; var CountOnce, CountRepeat: Integer;
    453     Update: Boolean; var Confirm: Boolean) of object;
    454459  TMoveUpdatedEvent = procedure(UnitMove: TUnitMove) of object;
    455460
     
    464469  private
    465470    FMapType: TMapType;
    466     FOnMove: TMoveEvent;
    467471    FOnMoveUpdated: TMoveUpdatedEvent;
    468472    FOnNewTurn: TNotifyEvent;
     
    519523    property MapType: TMapType read FMapType write SetMapType;
    520524  published
    521     property OnMove: TMoveEvent read FOnMove write FOnMove;
    522525    property OnMoveUpdated: TMoveUpdatedEvent read FOnMoveUpdated write FOnMoveUpdated;
    523526    property OnWin: TWinEvent read FOnWin write FOnWin;
     
    697700  if Assigned(FControlPlayer) then
    698701     FControlPlayer.FClient := Self;
     702end;
     703
     704procedure TClient.SetForm(AValue: TForm);
     705begin
     706  if FForm = AValue then Exit;
     707  FForm := AValue;
    699708end;
    700709
     
    29212930    CountRepeat := Result.CountRepeat;
    29222931    if (Mode = pmHuman) and Confirmation and
    2923       Assigned(Game.FOnMove) then Game.FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True, Confirm);
     2932      Assigned(Client) and Assigned(Client.FOnMove) then
     2933        Client.FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True, Confirm);
    29242934  end else begin
    29252935    CountOnce := Power;
    29262936    CountRepeat := 0;
    29272937    if (Mode = pmHuman) and Confirmation and
    2928       Assigned(Game.FOnMove) then Game.FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, False, Confirm);
     2938      Assigned(Client) and Assigned(Client.FOnMove) then
     2939        Client.FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, False, Confirm);
    29292940  end;
    29302941  if Confirm then begin
  • trunk/xtactics.lpr

    r181 r183  
    3333  Application.CreateForm(TCore, Core);
    3434  Application.CreateForm(TFormMain, FormMain);
    35   Application.CreateForm(TFormMove, FormMove);
    36   Application.CreateForm(TFormPlayer, FormPlayer);
    3735  Application.Run;
    3836end.
Note: See TracChangeset for help on using the changeset viewer.