Changeset 48
- Timestamp:
- Aug 17, 2014, 11:58:58 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r47 r48 82 82 TMap = class 83 83 private 84 FSize: TPoint; 84 85 function GetSize: TPoint; virtual; 85 86 procedure SetSize(AValue: TPoint); virtual; … … 114 115 THexMap = class(TMap) 115 116 private 116 FSize: TPoint;117 function GetSize: TPoint; override;118 procedure SetSize(AValue: TPoint); override;119 117 function IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean; 120 118 function GetCellNeighbors2(Cell: TCell): TCellArray; … … 140 138 TSquareMap = class(TMap) 141 139 private 142 FSize: TPoint;143 function GetSize: TPoint; override;144 procedure SetSize(AValue: TPoint); override;145 140 function IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean; 146 function GetCellNeighbo urs2(Cell: TCell): TCellArray;141 function GetCellNeighbors2(Cell: TCell): TCellArray; 147 142 public 148 143 Cells: array of array of TCell; 144 procedure Generate; override; 149 145 function IsValidIndex(Index: TPoint): Boolean; override; 150 146 function PosToCell(Pos: TPoint; View: TView): TCell; override; … … 155 151 constructor Create; override; 156 152 destructor Destroy; override; 157 property Size: TPoint read FSize write SetSize;158 153 end; 159 154 … … 333 328 { TSquareMap } 334 329 335 function TSquareMap.GetSize: TPoint; 336 begin 337 Result := FSize; 338 end; 339 340 procedure TSquareMap.SetSize(AValue: TPoint); 330 procedure TSquareMap.Generate; 341 331 var 342 332 X, Y: Integer; 333 I: Integer; 343 334 NewCell: TCell; 344 C: Integer; 345 begin 346 if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin 347 // Free previous 348 for Y := 0 to FSize.Y - 1 do 349 for X := 0 to FSize.X - 1 do begin 350 TCell(Cells[Y, X]).Destroy; 351 end; 352 FSize := AValue; 353 // Allocate and init new 354 SetLength(Cells, FSize.Y, FSize.X); 355 for Y := 0 to FSize.Y - 1 do 356 for X := 0 to FSize.X - 1 do begin 357 NewCell := TCell.Create; 358 NewCell.Pos := Point(X, Y); 359 Cells[Y, X] := NewCell; 360 end; 335 NeighCells: TCellArray; 336 begin 337 inherited; 338 // Free previous 339 for Y := 0 to Length(Cells) - 1 do 340 for X := 0 to Length(Cells[Y]) - 1 do begin 341 TCell(Cells[Y, X]).Destroy; 342 end; 343 // Allocate and init new 344 SetLength(Cells, FSize.Y, FSize.X); 345 for Y := 0 to FSize.Y - 1 do 346 for X := 0 to FSize.X - 1 do begin 347 NewCell := TCell.Create; 348 NewCell.Pos := Point(X, Y); 349 Cells[Y, X] := NewCell; 350 end; 351 // Generate neightbours 352 for Y := 0 to FSize.Y - 1 do 353 for X := 0 to FSize.X - 1 do begin 354 NeighCells := GetCellNeighbors2(Cells[Y, X]); 355 for I := 0 to Length(NeighCells) - 1 do 356 Cells[Y, X].Neighbors.Add(NeighCells[I]); 361 357 end; 362 358 end; … … 430 426 end; 431 427 432 function TSquareMap.GetCellNeighbo urs2(Cell: TCell): TCellArray;428 function TSquareMap.GetCellNeighbors2(Cell: TCell): TCellArray; 433 429 var 434 430 X, Y: Integer; … … 564 560 function TMap.GetSize: TPoint; 565 561 begin 566 Result:= Point(0, 0);562 Result:= FSize; 567 563 end; 568 564 569 565 procedure TMap.SetSize(AValue: TPoint); 570 566 begin 571 567 if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin 568 FSize := AValue; 569 Generate; 570 end; 572 571 end; 573 572 … … 1451 1450 end; 1452 1451 1453 function THexMap.GetSize: TPoint;1454 begin1455 Result := FSize;1456 end;1457 1458 procedure THexMap.SetSize(AValue: TPoint);1459 begin1460 if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin1461 FSize := AValue;1462 Generate;1463 end;1464 end;1465 1466 1452 function THexMap.IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean; 1467 1453 var … … 1696 1682 NeighCells: TCellArray; 1697 1683 begin 1684 inherited; 1698 1685 // Free previous 1699 1686 for Y := 0 to Length(Cells) - 1 do … … 1721 1708 begin 1722 1709 inherited; 1710 FSize := Point(0, 0); 1723 1711 end; 1724 1712
Note:
See TracChangeset
for help on using the changeset viewer.