コード例 #1
0
ファイル: Map.cs プロジェクト: AV2606/Snake_game
        /// <summary>
        /// Returns the <see cref="Land"/> which Located next to <paramref name="from"/> in the <paramref name="direction"/>
        /// </summary>
        /// <param name="from">The land to look from.</param>
        /// <param name="direction">The direction to look at.</param>
        /// <returns></returns>
        public Land GetNextTo(Land from, Directions direction)
        {
            var loc = GetLocation(from);

            try
            {
                if (direction == Directions.Right)
                {
                    return(FromLocation(loc.X + 1, loc.Y));
                }
                if (direction == Directions.Down)
                {
                    return(FromLocation(loc.X, loc.Y + 1));
                }
                if (direction == Directions.Left)
                {
                    return(FromLocation(loc.X - 1, loc.Y));
                }
                return(FromLocation(loc.X, loc.Y - 1));
            }
            catch (IndexOutOfRangeException e)
            {
                if (direction == Directions.Right)
                {
                    return(FromLocation(0, loc.Y));
                }
                if (direction == Directions.Down)
                {
                    return(FromLocation(loc.X, 0));
                }
                if (direction == Directions.Left)
                {
                    return(FromLocation(this.Width - 1, loc.Y));
                }
                return(FromLocation(loc.X, this.Height - 1));
            }
        }
コード例 #2
0
 public AlreadyOccupiedLandException(string message, Land land) : base(message)
 {
     FiredMe = land;
 }