Changeset 18 for trunk


Ignore:
Timestamp:
Feb 26, 2014, 9:45:23 PM (11 years ago)
Author:
chronos
Message:
  • Add: Player start units setting.
  • Add: Allow add and remove players in new game dialog.
  • Fixed: Do not allow move from to same cell.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFormMain.pas

    r17 r18  
    200200begin
    201201  if (Abs(StartMousePoint.X - X) < 5) and (Abs(StartMousePoint.Y - Y) < 5) then begin
    202     if Game.CurrentPlayer.Mode = pmHuman then begin
     202    if Game.Running and (Game.CurrentPlayer.Mode = pmHuman) then begin
    203203      Game.CurrentPlayer.SelectCell(Point(X, Y));
    204204      Redraw;
  • trunk/UFormNew.lfm

    r15 r18  
    11object FormNew: TFormNew
    2   Left = 593
     2  Left = 706
    33  Height = 516
    4   Top = 245
     4  Top = 455
    55  Width = 716
    66  Caption = 'New game'
    77  ClientHeight = 516
    88  ClientWidth = 716
     9  OnCreate = FormCreate
     10  OnDestroy = FormDestroy
     11  OnShow = FormShow
    912  LCLVersion = '1.3'
    1013  object ButtonOk: TButton
     
    4649      item
    4750        Caption = 'Type'
    48         Width = 377
     51        Width = 100
     52      end   
     53      item
     54        Caption = 'Color'
     55        Width = 100
     56      end   
     57      item
     58        Caption = 'Start units'
     59        Width = 177
    4960      end>
     61    OwnerData = True
     62    ReadOnly = True
     63    RowSelect = True
    5064    TabOrder = 3
    5165    ViewStyle = vsReport
     66    OnData = ListView1Data
     67    OnSelectItem = ListView1SelectItem
    5268  end
    5369  object ButtonPlayerAdd: TButton
     
    5773    Width = 83
    5874    Caption = 'Add'
     75    OnClick = ButtonPlayerAddClick
    5976    TabOrder = 4
    6077  end
     
    6582    Width = 83
    6683    Caption = 'Remove'
     84    OnClick = ButtonPlayerRemoveClick
    6785    TabOrder = 5
    6886  end
  • trunk/UFormNew.pas

    r15 r18  
    2424    SpinEditMapSizeX: TSpinEdit;
    2525    SpinEditMapSizeY: TSpinEdit;
     26    procedure ButtonPlayerAddClick(Sender: TObject);
     27    procedure ButtonPlayerRemoveClick(Sender: TObject);
     28    procedure FormCreate(Sender: TObject);
     29    procedure FormDestroy(Sender: TObject);
     30    procedure FormShow(Sender: TObject);
     31    procedure ListView1Data(Sender: TObject; Item: TListItem);
     32    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
     33      Selected: Boolean);
    2634  private
    27     { private declarations }
     35    Players: TPlayers;
    2836  public
     37    procedure ReloadView;
    2938    procedure Load(Game: TGame);
    3039    procedure Save(Game: TGame);
     
    4049{ TFormNew }
    4150
     51procedure TFormNew.ListView1Data(Sender: TObject; Item: TListItem);
     52begin
     53  if (Item.Index >= 0) and (Item.Index < Players.Count) then
     54  with TPlayer(Players[Item.Index]) do begin
     55    Item.Caption := Name;
     56    Item.Data := Players[Item.Index];
     57    Item.SubItems.Add(PlayerModeText[Mode]);
     58    Item.SubItems.Add(IntToStr(Color));
     59    Item.SubItems.Add(IntToStr(StartUnits));
     60  end;
     61end;
     62
     63procedure TFormNew.ListView1SelectItem(Sender: TObject; Item: TListItem;
     64  Selected: Boolean);
     65begin
     66  ReloadView;
     67end;
     68
     69procedure TFormNew.ReloadView;
     70begin
     71  ListView1.Items.Count := Players.Count;
     72  ListView1.Refresh;
     73  ButtonPlayerRemove.Enabled := Assigned(ListView1.Selected);
     74end;
     75
     76procedure TFormNew.FormShow(Sender: TObject);
     77begin
     78  ReloadView;
     79end;
     80
     81procedure TFormNew.FormCreate(Sender: TObject);
     82begin
     83  Players := TPlayers.Create;
     84end;
     85
     86procedure TFormNew.ButtonPlayerRemoveClick(Sender: TObject);
     87begin
     88  if Assigned(ListView1.Selected) then
     89    Players.Remove(ListView1.Selected.Data);
     90  ReloadView;
     91end;
     92
     93procedure TFormNew.ButtonPlayerAddClick(Sender: TObject);
     94var
     95  NewPlayer: TPlayer;
     96begin
     97  NewPlayer := TPlayer.Create;
     98  NewPlayer.Name := 'Player x';
     99  NewPlayer.Color := clYellow;
     100  Players.Add(NewPlayer);
     101  ReloadView;
     102end;
     103
     104procedure TFormNew.FormDestroy(Sender: TObject);
     105begin
     106  Players.Free;
     107end;
     108
    42109procedure TFormNew.Load(Game: TGame);
    43110var
     
    46113begin
    47114  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]);
     115  for I := 0 to Players.Count - 1 do
     116    TPlayer(Players[I]).Free;
     117  Players.Count := Game.Players.Count;
     118  for I := 0 to Game.Players.Count - 1 do begin
     119    Players[I] := TPlayer.Create;
     120    TPlayer(Players[I]).Assign(TPlayer(Game.Players[I]));
    54121  end;
    55122  SpinEditMapSizeX.Value := Game.Map.Size.X;
  • trunk/UGame.pas

    r17 r18  
    77uses
    88  Classes, SysUtils, ExtCtrls, Graphics, Contnrs;
     9
     10const
     11  DefaultPlayerStartUnits = 5;
    912
    1013type
     
    8083    TotalUnits: Integer;
    8184    TotalCells: Integer;
     85    StartUnits: Integer;
    8286    procedure ComputerTurn;
    8387    procedure SelectCell(Pos: TPoint);
    8488    procedure Paint(PaintBox: TPaintBox);
    8589    constructor Create;
     90    procedure Assign(Source: TPlayer);
     91  end;
     92
     93  TPlayers = class(TObjectList)
     94
    8695  end;
    8796
     
    105114    procedure SetMove(CellFrom, CellTo: TCell);
    106115  public
    107     Players: TObjectList; // TList<TPlayer>
     116    Players: TPlayers;
    108117    Map: THexMap;
    109118    VoidEnabled: Boolean;
     
    171180    not ((DX = -1) and (DY = -1)) and
    172181    not ((DX = 1) and (DY = 1))));
     182  Result := Result and not (Cell1 = Cell2);
    173183end;
    174184
     
    240250  ViewZoom := 1;
    241251  SelectedCell := nil;
     252  StartUnits := DefaultPlayerStartUnits;
     253end;
     254
     255procedure TPlayer.Assign(Source: TPlayer);
     256begin
     257  Name := Source.Name;
     258  Color := Source.Color;
     259  Mode := Source.Mode;
     260  Game := Source.Game;
     261  TotalCells := Source.TotalCells;
     262  TotalUnits := Source.TotalUnits;
     263  StartUnits := Source.StartUnits;
     264  SelectedCell := Source.SelectedCell;
     265  ViewZoom := Source.ViewZoom;
    242266end;
    243267
     
    365389  Randomize;
    366390
    367   Players := TObjectList.Create;
     391  Players := TPlayers.Create;
    368392  Player := TPlayer.Create;
    369393  Player.Name := 'Player 1';
     
    419443      StartCell.Terrain := ttNormal;
    420444      StartCell.Player := TPlayer(Players[I]);
     445      StartCell.Power := TPlayer(Players[I]).StartUnits;
    421446    end;
    422447  end;
Note: See TracChangeset for help on using the changeset viewer.