Changeset 18
- Timestamp:
- Feb 26, 2014, 9:45:23 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UFormMain.pas
r17 r18 200 200 begin 201 201 if (Abs(StartMousePoint.X - X) < 5) and (Abs(StartMousePoint.Y - Y) < 5) then begin 202 if Game. CurrentPlayer.Mode = pmHumanthen begin202 if Game.Running and (Game.CurrentPlayer.Mode = pmHuman) then begin 203 203 Game.CurrentPlayer.SelectCell(Point(X, Y)); 204 204 Redraw; -
trunk/UFormNew.lfm
r15 r18 1 1 object FormNew: TFormNew 2 Left = 5932 Left = 706 3 3 Height = 516 4 Top = 2454 Top = 455 5 5 Width = 716 6 6 Caption = 'New game' 7 7 ClientHeight = 516 8 8 ClientWidth = 716 9 OnCreate = FormCreate 10 OnDestroy = FormDestroy 11 OnShow = FormShow 9 12 LCLVersion = '1.3' 10 13 object ButtonOk: TButton … … 46 49 item 47 50 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 49 60 end> 61 OwnerData = True 62 ReadOnly = True 63 RowSelect = True 50 64 TabOrder = 3 51 65 ViewStyle = vsReport 66 OnData = ListView1Data 67 OnSelectItem = ListView1SelectItem 52 68 end 53 69 object ButtonPlayerAdd: TButton … … 57 73 Width = 83 58 74 Caption = 'Add' 75 OnClick = ButtonPlayerAddClick 59 76 TabOrder = 4 60 77 end … … 65 82 Width = 83 66 83 Caption = 'Remove' 84 OnClick = ButtonPlayerRemoveClick 67 85 TabOrder = 5 68 86 end -
trunk/UFormNew.pas
r15 r18 24 24 SpinEditMapSizeX: TSpinEdit; 25 25 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); 26 34 private 27 { private declarations }35 Players: TPlayers; 28 36 public 37 procedure ReloadView; 29 38 procedure Load(Game: TGame); 30 39 procedure Save(Game: TGame); … … 40 49 { TFormNew } 41 50 51 procedure TFormNew.ListView1Data(Sender: TObject; Item: TListItem); 52 begin 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; 61 end; 62 63 procedure TFormNew.ListView1SelectItem(Sender: TObject; Item: TListItem; 64 Selected: Boolean); 65 begin 66 ReloadView; 67 end; 68 69 procedure TFormNew.ReloadView; 70 begin 71 ListView1.Items.Count := Players.Count; 72 ListView1.Refresh; 73 ButtonPlayerRemove.Enabled := Assigned(ListView1.Selected); 74 end; 75 76 procedure TFormNew.FormShow(Sender: TObject); 77 begin 78 ReloadView; 79 end; 80 81 procedure TFormNew.FormCreate(Sender: TObject); 82 begin 83 Players := TPlayers.Create; 84 end; 85 86 procedure TFormNew.ButtonPlayerRemoveClick(Sender: TObject); 87 begin 88 if Assigned(ListView1.Selected) then 89 Players.Remove(ListView1.Selected.Data); 90 ReloadView; 91 end; 92 93 procedure TFormNew.ButtonPlayerAddClick(Sender: TObject); 94 var 95 NewPlayer: TPlayer; 96 begin 97 NewPlayer := TPlayer.Create; 98 NewPlayer.Name := 'Player x'; 99 NewPlayer.Color := clYellow; 100 Players.Add(NewPlayer); 101 ReloadView; 102 end; 103 104 procedure TFormNew.FormDestroy(Sender: TObject); 105 begin 106 Players.Free; 107 end; 108 42 109 procedure TFormNew.Load(Game: TGame); 43 110 var … … 46 113 begin 47 114 CheckBoxVoid.Checked := Game.VoidEnabled; 48 ListView1.Items.Clear;49 for I := 0 to Game.Players.Count - 1 do50 with TPlayer(Game.Players[I]) do begin51 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])); 54 121 end; 55 122 SpinEditMapSizeX.Value := Game.Map.Size.X; -
trunk/UGame.pas
r17 r18 7 7 uses 8 8 Classes, SysUtils, ExtCtrls, Graphics, Contnrs; 9 10 const 11 DefaultPlayerStartUnits = 5; 9 12 10 13 type … … 80 83 TotalUnits: Integer; 81 84 TotalCells: Integer; 85 StartUnits: Integer; 82 86 procedure ComputerTurn; 83 87 procedure SelectCell(Pos: TPoint); 84 88 procedure Paint(PaintBox: TPaintBox); 85 89 constructor Create; 90 procedure Assign(Source: TPlayer); 91 end; 92 93 TPlayers = class(TObjectList) 94 86 95 end; 87 96 … … 105 114 procedure SetMove(CellFrom, CellTo: TCell); 106 115 public 107 Players: T ObjectList; // TList<TPlayer>116 Players: TPlayers; 108 117 Map: THexMap; 109 118 VoidEnabled: Boolean; … … 171 180 not ((DX = -1) and (DY = -1)) and 172 181 not ((DX = 1) and (DY = 1)))); 182 Result := Result and not (Cell1 = Cell2); 173 183 end; 174 184 … … 240 250 ViewZoom := 1; 241 251 SelectedCell := nil; 252 StartUnits := DefaultPlayerStartUnits; 253 end; 254 255 procedure TPlayer.Assign(Source: TPlayer); 256 begin 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; 242 266 end; 243 267 … … 365 389 Randomize; 366 390 367 Players := T ObjectList.Create;391 Players := TPlayers.Create; 368 392 Player := TPlayer.Create; 369 393 Player.Name := 'Player 1'; … … 419 443 StartCell.Terrain := ttNormal; 420 444 StartCell.Player := TPlayer(Players[I]); 445 StartCell.Power := TPlayer(Players[I]).StartUnits; 421 446 end; 422 447 end;
Note:
See TracChangeset
for help on using the changeset viewer.