Changeset 75 for trunk/UGame.pas
- Timestamp:
- Oct 4, 2014, 11:33:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r74 r75 7 7 uses 8 8 Classes, SysUtils, ExtCtrls, Graphics, Contnrs, XMLConf, XMLRead, XMLWrite, 9 DOM, Math, FileUtil, UXMLUtils ;9 DOM, Math, FileUtil, UXMLUtils, Dialogs; 10 10 11 11 const … … 91 91 end; 92 92 93 TMapShape = (msRectangle, msImage); 94 93 95 { TMap } 94 96 … … 107 109 DefaultCellSize: TPoint; 108 110 Cells: TObjectList; // TList<TCell> 111 Shape: TMapShape; 112 Image: TImage; 113 function IsOutsideShape(Coord: TPoint): Boolean; virtual; 109 114 function IsCellsNeighbor(Cell1, Cell2: TCell): Boolean; virtual; 110 115 function IsValidIndex(Index: TPoint): Boolean; virtual; … … 266 271 FOnWin: TWinEvent; 267 272 FRunning: Boolean; 273 LoadedImageFileName: string; 268 274 procedure Attack(var AttackPower, DefendPower: Integer); 269 275 procedure MoveAll(Player: TPlayer); … … 277 283 Players: TPlayers; 278 284 Map: TMap; 285 MapImageFileName: string; 279 286 VoidEnabled: Boolean; 280 287 VoidPercentage: Integer; … … 596 603 end; 597 604 605 function TMap.IsOutsideShape(Coord: TPoint): Boolean; 606 var 607 Rect: TRect; 608 Color: TColor; 609 Pos: TPoint; 610 begin 611 case Shape of 612 msRectangle: Result := False; 613 msImage: begin 614 Rect := GetPixelRect; 615 with Image.Picture.Bitmap do begin 616 Pos := Point(Trunc(Coord.X / (Rect.Right - Rect.Left) * Width), 617 Trunc(Coord.Y / (Rect.Bottom - Rect.Top) * Height)); 618 Color := Canvas.Pixels[Pos.X, Pos.Y]; 619 end; 620 Result := Color <> clWhite; 621 end; 622 else Result := False; 623 end; 624 end; 625 598 626 procedure TMap.DrawArrow(Canvas: TCanvas; View: TView; Pos: TPoint; 599 627 Angle: Double; Text: string); … … 655 683 Size := Source.Size; 656 684 DefaultCellSize := Source.DefaultCellSize; 685 Shape := Source.Shape; 657 686 //FSize := Source.Size; 658 687 … … 683 712 DefaultCellSize.Y := ReadInteger(Node, 'DefaultCellSizeY', 1); 684 713 MaxPower := ReadInteger(Node, 'MaxPower', 99); 714 Shape := TMapShape(ReadInteger(Node, 'Shape', Integer(msRectangle))); 685 715 end; 686 716 … … 694 724 WriteInteger(Node, 'DefaultCellSizeY', DefaultCellSize.Y); 695 725 WriteInteger(Node, 'MaxPower', MaxPower); 726 WriteInteger(Node, 'Shape', Integer(Shape)); 696 727 NewNode := Node.OwnerDocument.CreateElement('Cells'); 697 728 Node.AppendChild(NewNode); … … 828 859 Cells := TObjectList.create; 829 860 Size := Point(0, 0); 861 Image := TImage.Create(nil); 830 862 end; 831 863 832 864 destructor TMap.Destroy; 833 865 begin 866 Image.Free; 834 867 Size := Point(0, 0); 835 868 FreeAndNil(Cells); … … 1691 1724 with Config do begin 1692 1725 SetValue(Path + '/GridType', Integer(MapType)); 1726 SetValue(Path + '/MapImage', MapImageFileName); 1693 1727 SetValue(Path + '/SymetricMap', SymetricMap); 1694 1728 SetValue(Path + '/VoidEnabled', VoidEnabled); … … 1696 1730 SetValue(Path + '/MapSizeX', Map.Size.X); 1697 1731 SetValue(Path + '/MapSizeY', Map.Size.Y); 1732 SetValue(Path + '/MapShape', Integer(Map.Shape)); 1698 1733 SetValue(Path + '/CityEnabled', CityEnabled); 1699 1734 SetValue(Path + '/CityPercentage', CityPercentage); … … 1710 1745 with Config do begin 1711 1746 MapType := TMapType(GetValue(Path + '/GridType', Integer(mtHexagon))); 1747 MapImageFileName := GetValue(Path + '/MapImage', MapImageFileName); 1712 1748 SymetricMap := GetValue(Path + '/SymetricMap', False); 1713 1749 VoidEnabled := GetValue(Path + '/VoidEnabled', True); … … 1715 1751 Map.Size := Point(GetValue(Path + '/MapSizeX', 10), 1716 1752 GetValue(Path + '/MapSizeY', 10)); 1753 Map.Shape := TMapShape(GetValue(Path + '/MapShape', 0)); 1717 1754 CityEnabled := GetValue(Path + '/CityEnabled', False); 1718 1755 CityPercentage := GetValue(Path + '/CityPercentage', 10); … … 1911 1948 Players := TPlayers.Create; 1912 1949 1950 MapImageFileName := 'Images/Maps/WorldMap.png'; 1951 1913 1952 Randomize; 1914 1953 … … 1952 1991 TurnCounter := 1; 1953 1992 Moves.Clear; 1993 if (Map.Shape = msImage) and FileExists(MapImageFileName) and 1994 (LoadedImageFileName <> MapImageFileName) then begin 1995 LoadedImageFileName := MapImageFileName; 1996 Map.Image.Picture.LoadFromFile(MapImageFileName); 1997 end; 1954 1998 AllCells := Map.GetAllCells; 1955 1999 for C := 0 to Length(AllCells) - 1 do 1956 2000 with AllCells[C] do begin 1957 if VoidEnabled and (Random < VoidPercentage / 100) then Terrain := ttVoid 2001 if (VoidEnabled and (Random < VoidPercentage / 100)) or 2002 (Map.IsOutsideShape(PosPx)) then Terrain := ttVoid 1958 2003 else begin 1959 2004 if CityEnabled and (Random < CityPercentage / 100) then Terrain := ttCity … … 1980 2025 StartCell := nil; 1981 2026 Counter := 0; 1982 while not Assigned(StartCell) or Assigned(StartCell.Player) do begin 2027 while not Assigned(StartCell) or Assigned(StartCell.Player) or 2028 (StartCell.Terrain = ttVoid) do begin 1983 2029 StartCell := AllCells[Random(Length(AllCells))]; 1984 2030 Inc(Counter);
Note:
See TracChangeset
for help on using the changeset viewer.