Пример #1
0
        public bool TryGetCell(int x, int y, out RoadTile roadTile)
        {
            if (IsValidLocation(x, y))
            {
                roadTile = GetCell(x, y);
                return(roadTile != null);
            }

            roadTile = null;
            return(false);
        }
Пример #2
0
        public bool TryGetCell(int x, int y, Direction direction, out RoadTile roadTile)
        {
            switch (direction)
            {
            case Direction.North: return(TryGetCell(x, y - 1, out roadTile));

            case Direction.South: return(TryGetCell(x, y + 1, out roadTile));

            case Direction.East: return(TryGetCell(x + 1, y, out roadTile));

            case Direction.West: return(TryGetCell(x - 1, y, out roadTile));
            }

            roadTile = null;
            return(false);
        }
Пример #3
0
 public void SetCell(int x, int y, RoadTile tile)
 {
     tiles[y, x] = tile;
 }
Пример #4
0
        private bool ValidateCellPlacement(int newX, int newY, Block block, RoadTile potentialCell)
        {
            if (potentialCell.Id == 7 && block.ExistsWithinRadius(newX, newY, _inputs.FourWayRadius, 7))
            {
                return(false);
            }

            if (block.TryGetCell(newX, newY, Direction.North, out var northCell))
            {
                if (northCell.ExitSouth && !potentialCell.ExitNorth)
                {
                    return(false);
                }

                if (potentialCell.ExitNorth && !northCell.ExitSouth)
                {
                    return(false);
                }
            }

            if (block.TryGetCell(newX, newY, Direction.South, out var southCell))
            {
                if (southCell.ExitNorth && !potentialCell.ExitSouth)
                {
                    return(false);
                }

                if (potentialCell.ExitSouth && !southCell.ExitNorth)
                {
                    return(false);
                }
            }

            if (block.TryGetCell(newX, newY, Direction.East, out var eastCell))
            {
                if (eastCell.ExitWest && !potentialCell.ExitEast)
                {
                    return(false);
                }

                if (potentialCell.ExitEast && !eastCell.ExitWest)
                {
                    return(false);
                }
            }

            if (block.TryGetCell(newX, newY, Direction.West, out var westCell))
            {
                if (westCell.ExitEast && !potentialCell.ExitWest)
                {
                    return(false);
                }

                if (potentialCell.ExitWest && !westCell.ExitEast)
                {
                    return(false);
                }
            }

            return(true);
        }