Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GridCell"/> class.
 /// </summary>
 public GridCell()
 {
     exploredCountries = new NamedObjectCollection <CountryBase>();
     InitializeUnitCollection();
     this.roadLayout  = GridCellItemDirection.None;
     this.riverLayout = GridCellItemDirection.None;
 }
Example #2
0
        // Adds a road to the cell.  This will look at the surrounding
        // cells to see which type of road should be placed (direction).
        private void SetRoad()
        {
            GridCell cell;

            this.HasRoad = true;
            Grid     grid            = GameRoot.Instance.Grid;
            GridCell topCell         = grid.GetCell(new Point(this.Coordinates.X, this.Coordinates.Y - 1));
            GridCell bottomCell      = grid.GetCell(new Point(this.Coordinates.X, this.Coordinates.Y + 1));
            GridCell leftCell        = grid.GetCell(new Point(this.Coordinates.X - 1, this.Coordinates.Y));
            GridCell rightCell       = grid.GetCell(new Point(this.Coordinates.X + 1, this.Coordinates.Y));
            GridCell bottomRightCell = grid.GetCell(new Point(this.Coordinates.X + 1, this.Coordinates.Y + 1));

            if (topCell != null)
            {
                cell = topCell;
                if (cell.HasRoad || cell.City != null)
                {
                    this.roadLayout = GridCellItemDirection.NorthSouth;
                }
            }

            if (bottomCell != null)
            {
                cell = bottomCell;
                if (cell.HasRoad || cell.City != null)
                {
                    this.roadLayout = GridCellItemDirection.NorthSouth;
                }
                else if (bottomRightCell != null)
                {
                    if (bottomRightCell.HasRoad || bottomRightCell.City != null)
                    {
                        this.roadLayout = GridCellItemDirection.SouthwestToNortheast;
                    }
                }
            }

            if (rightCell != null)
            {
                cell = rightCell;
                if (cell.HasRoad || cell.City != null)
                {
                    this.roadLayout =
                        this.roadLayout == GridCellItemDirection.None ?
                        GridCellItemDirection.EastWest : GridCellItemDirection.Bidirectional;
                }
            }

            if (leftCell != null)
            {
                cell = leftCell;
                if (cell.HasRoad || cell.City != null)
                {
                    this.roadLayout =
                        this.roadLayout == GridCellItemDirection.None ?
                        GridCellItemDirection.EastWest : GridCellItemDirection.Bidirectional;
                }
            }
        }