예제 #1
0
        /// <summary>
        /// Try to move the object on the board
        /// See <see cref="IBoardFunctions"/>
        /// <seealso cref="MyRandom"/>
        /// </summary>
        /// <param name="obj">The object trying to move</param>
        public virtual void TryToMove()
        {
            int x, y;

            do
            {
                if (rnd == null)
                {
                    x = MyRandom.Next(Math.Max(0, X - Agility), Math.Min(info.Length, X + 1 + Agility));
                    y = MyRandom.Next(Math.Max(0, Y - Agility), Math.Min(info.Hight, Y + 1 + Agility));
                }
                else
                {
                    x = rnd.Next(Math.Max(0, X - Agility), Math.Min(info.Hight, X + 1 + Agility));
                    y = rnd.Next(Math.Max(0, Y - Agility), Math.Min(info.Hight, Y + 1 + Agility));
                }
            } while (x == X && y == Y);

            int localX = X;
            int localY = Y;

            bool result = BoardFunctions.TryToMove(X, Y, x, y);

            if (result)
            {
                ProducerConsumer.Produce(String.Format("object number {0} moved from ({1},{2}) to ({3},{4})", Id, localX, localY, x, y));
            }
        }