Changeset 15


Ignore:
Timestamp:
Feb 19, 2014, 11:13:36 PM (11 years ago)
Author:
chronos
Message:
  • Added: Size of map can be adjusted in New game dialog.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFormMain.pas

    r13 r15  
    102102begin
    103103  FormMove.SpinEditOnce.Value := CountOnce;
     104  FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower;
    104105  FormMove.SpinEditRepeat.Value := CountRepeat;
     106  FormMove.SpinEditRepeat.MaxValue := Game.Map.MaxPower;
    105107  if FormMove.ShowModal = mrOk then begin
    106108    CountOnce := FormMove.SpinEditOnce.Value;
  • trunk/UFormNew.lfm

    r6 r15  
    3030    Height = 24
    3131    Top = 168
    32     Width = 194
     32    Width = 175
    3333    Caption = 'Inaccessible places'
    3434    TabOrder = 2
     
    3939    Top = 8
    4040    Width = 594
    41     Columns = <>
     41    Columns = <   
     42      item
     43        Caption = 'Name'
     44        Width = 200
     45      end   
     46      item
     47        Caption = 'Type'
     48        Width = 377
     49      end>
    4250    TabOrder = 3
     51    ViewStyle = vsReport
    4352  end
    4453  object ButtonPlayerAdd: TButton
     
    5867    TabOrder = 5
    5968  end
     69  object Label1: TLabel
     70    Left = 16
     71    Height = 22
     72    Top = 206
     73    Width = 75
     74    Caption = 'Map size:'
     75    ParentColor = False
     76  end
     77  object SpinEditMapSizeX: TSpinEdit
     78    Left = 136
     79    Height = 32
     80    Top = 200
     81    Width = 98
     82    MinValue = 2
     83    TabOrder = 6
     84    Value = 2
     85  end
     86  object SpinEditMapSizeY: TSpinEdit
     87    Left = 256
     88    Height = 32
     89    Top = 200
     90    Width = 90
     91    MinValue = 2
     92    TabOrder = 7
     93    Value = 2
     94  end
     95  object Label2: TLabel
     96    Left = 240
     97    Height = 22
     98    Top = 208
     99    Width = 9
     100    Caption = 'x'
     101    ParentColor = False
     102  end
    60103end
  • trunk/UFormNew.pas

    r6 r15  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, UGame;
     9  ComCtrls, Spin, UGame;
    1010
    1111type
     
    1919    ButtonPlayerRemove: TButton;
    2020    CheckBoxVoid: TCheckBox;
     21    Label1: TLabel;
     22    Label2: TLabel;
    2123    ListView1: TListView;
     24    SpinEditMapSizeX: TSpinEdit;
     25    SpinEditMapSizeY: TSpinEdit;
    2226  private
    2327    { private declarations }
     
    3741
    3842procedure TFormNew.Load(Game: TGame);
     43var
     44  I: Integer;
     45  NewItem: TListItem;
    3946begin
    4047  CheckBoxVoid.Checked := Game.VoidEnabled;
     48  ListView1.Items.Clear;
     49  for I := 0 to Game.Players.Count - 1 do
     50  with TPlayer(Game.Players[I]) do begin
     51    NewItem := ListView1.Items.Add;
     52    NewItem.Caption := Name;
     53    NewItem.SubItems.Add(PlayerModeText[Mode]);
     54  end;
     55  SpinEditMapSizeX.Value := Game.Map.Size.X;
     56  SpinEditMapSizeY.Value := Game.Map.Size.Y;
    4157end;
    4258
     
    4460begin
    4561  Game.VoidEnabled := CheckBoxVoid.Checked;
     62  Game.Map.Size := Point(SpinEditMapSizeX.Value, SpinEditMapSizeY.Value);
    4663end;
    4764
  • trunk/UGame.pas

    r14 r15  
    3030    MovesTo: TObjectList;
    3131    function GetColor: TColor;
     32    function GetAvialPower: Integer;
    3233    constructor Create;
    3334    destructor Destroy; override;
     
    112113  end;
    113114
     115const
     116  PlayerModeText: array[TPlayerMode] of string = ('Human', 'Computer');
     117
    114118
    115119implementation
     
    166170  if Assigned(Player) then Result := Player.Color
    167171    else Result := clGray;
     172end;
     173
     174function TCell.GetAvialPower: Integer;
     175var
     176  I: Integer;
     177begin
     178  Result := Power;
     179  for I := 0 to MovesFrom.Count - 1 do
     180    Result := Result - TMove(MovesFrom[I]).CountOnce;
     181  if Result < 0 then Result := 0;
    168182end;
    169183
     
    249263  for I := Moves.Count - 1 downto 0 do
    250264  if (TMove(Moves[I]).CellFrom.Player = Player) and
    251     (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then
     265    (TMove(Moves[I]).CountOnce = 0) and (TMove(Moves[I]).CountRepeat = 0) then begin
     266    TMove(Moves[I]).CellFrom.MovesFrom.Remove(TMove(Moves[I]));
     267    TMove(Moves[I]).CellTo.MovesTo.Remove(TMove(Moves[I]));
    252268    Moves.Delete(I);
     269  end;
    253270end;
    254271
     
    276293      else begin
    277294        TMove(Moves[I]).CountOnce := CountOnce;
    278          TMove(Moves[I]).CountOnce := CountOnce;
     295        TMove(Moves[I]).CountOnce := CountOnce;
    279296      end;
    280297  end else begin
     
    286303      NewMove.CountOnce := CountOnce;
    287304      NewMove.CountRepeat := CountRepeat;
     305      CellFrom.MovesFrom.Add(NewMove);
     306      CellTo.MovesTo.Add(NewMove);
    288307    end;
    289308  end;
     
    317336  Map := THexMap.Create;
    318337  Map.Game := Self;
     338  Map.Size := Point(20, 20);
    319339  Moves := TObjectList.Create;
    320340end;
     
    335355  StartCell: TCell;
    336356begin
    337   Map.Size := Point(20, 20);
     357  Moves.Clear;
     358  Map.ClearCellMoves;
    338359  for Y := 0 to Map.Size.Y - 1 do
    339360  for X := 0 to Map.Size.X - 1 do
     
    346367  with TPlayer(Players[I]) do begin
    347368    SelectedCell := nil;
    348     StartCell := Map.Cells[Random(Map.Size.Y), Random(Map.Size.X)];
    349     StartCell.Terrain := ttNormal;
    350     StartCell.Player := TPlayer(Players[I]);
     369    if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin
     370      StartCell := Map.Cells[Random(Map.Size.Y), Random(Map.Size.X)];
     371      StartCell.Terrain := ttNormal;
     372      StartCell.Player := TPlayer(Players[I]);
     373    end;
    351374  end;
    352375  CurrentPlayer := TPlayer(Players[0]);
     
    379402    for Y := 0 to FSize.Y - 1 do
    380403    for X := 0 to FSize.X - 1 do begin
    381       Cells[Y, X].Destroy;
     404      TCell(Cells[Y, X]).Destroy;
    382405    end;
    383406    FSize := AValue;
    384407    // Allocate and init new
    385     SetLength(Cells, FSize.X, FSize.Y);
     408    SetLength(Cells, FSize.Y, FSize.X);
    386409    for Y := 0 to FSize.Y - 1 do
    387410    for X := 0 to FSize.X - 1 do begin
     
    499522          Pen.Color := clBlack;
    500523          PaintHexagon(X * CellSize.X - Frac(Rect.Left / CellSize.X) * CellSize.X,
    501             Y * CellSize.Y - Frac(Rect.Top / CellSize.Y) * CellSize.Y, IntToStr(Cell.Power));
     524            Y * CellSize.Y - Frac(Rect.Top / CellSize.Y) * CellSize.Y, IntToStr(Cell.GetAvialPower));
    502525          // Draw arrows
    503526          Pen.Color := clCream;
  • trunk/xtactics.lpi

    r13 r15  
    5656        <IsPartOfProject Value="True"/>
    5757        <ComponentName Value="FormNew"/>
     58        <HasResources Value="True"/>
    5859        <ResourceBaseClass Value="Form"/>
    5960        <UnitName Value="UFormNew"/>
Note: See TracChangeset for help on using the changeset viewer.