コード例 #1
0
ファイル: MapBlock.cs プロジェクト: Cajova-Houba/kiv-net-game
        /// <summary>
        /// Returns all accessible neighbours of this map block.
        /// Neighbour is acessible if there's no wall/locked gate between this block and the neighbour.
        /// </summary>
        /// <returns>Neighbour blocks.</returns>
        public List <MapBlock> AccessibleNeighbours()
        {
            Direction[]     allDirections = DirectionMethods.GetAllDirections();
            List <MapBlock> neighbours    = new List <MapBlock>();

            foreach (Direction dir in allDirections)
            {
                MapBlock neighbour = NextOpenBlock(dir);
                if (neighbour != null)
                {
                    neighbours.Add(neighbour);
                }
            }

            return(neighbours);
        }
コード例 #2
0
ファイル: MapBlock.cs プロジェクト: Cajova-Houba/kiv-net-game
        /// <summary>
        /// Returns the block thich lies next to this block in given direction and is accessible (entrance is OPEN).
        /// If such block doesn't exist null is returned.
        ///
        /// Uses parent map to determine next block and if the parent map is null, null is returned.
        /// </summary>
        /// <param name="direction">Direction of next block.</param>
        /// <returns>Adjacent, accessible block or null.</returns>
        public MapBlock NextOpenBlock(Direction direction)
        {
            MapBlock nextOpenBlock = NextBlock(direction);

            if (nextOpenBlock == null)
            {
                return(null);
            }
            else
            {
                if (EntranceInDirection(direction).IsOpen() && nextOpenBlock.EntranceInDirection(direction.OppositeDirection()).IsOpen())
                {
                    return(nextOpenBlock);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Returns direction from one block to another. Uses only block's coordinates to calculate the direction.
 /// Returns NO_DIRECTION if the blocks have same coordinates.
 /// Works best for adjacent blocks.
 /// </summary>
 /// <param name="from">Start block<./param>
 /// <param name="to">Target block.</param>
 /// <returns>Direction between two blocks.</returns>
 public static Direction GetDirection(MapBlock from, MapBlock to)
 {
     if (from.X < to.X)
     {
         return(Direction.EAST);
     }
     else if (from.X > to.X)
     {
         return(Direction.WEST);
     }
     else if (from.Y < to.Y)
     {
         return(Direction.SOUTH);
     }
     else if (from.Y > to.Y)
     {
         return(Direction.NORTH);
     }
     else
     {
         return(Direction.NO_DIRECTION);
     }
 }