Beispiel #1
0
        /// <summary>
        /// Сдвинуть змейку по направлению
        /// </summary>
        public void Move()
        {
            // Первый (ведущий) блок змейки
            DrawableChar head = Blocks[0];

            if (addBlockQueue > 0)
            {
                // Вместо добавления нового блока, просто
                // не удалять старый.
                addBlockQueue -= 1;
            }
            else
            {
                Blocks.RemoveAt(Blocks.Count - 1);
            }

            /*
             * Для смещения последий блок перемещается в начало, перед текущим
             * ведущим.
             */

            Point newBlockLocation = head.Location; // Координаты нового ведущего блока

            newBlockLocation = GetPosFollowingDirection(newBlockLocation, this.Direction);
            actualDirection  = this.Direction; // зафиксировать в каком направлении фактически двигается змейка

            DrawableChar blockToAdd = new DrawableChar(SnakeChar, newBlockLocation);

            Blocks.Insert(0, blockToAdd);
        }
Beispiel #2
0
        /// <summary>
        /// Добавить символ в очередь на отрисовку.
        /// </summary>
        public void Create(char c, int x, int y)
        {
            var p  = new Point(x, y);
            var dc = new DrawableChar(c, new Point(x, y));

            if (!drawQueue.TryAdd(p, dc))
            {
                // Перезаписать значение если есть символ на этих координатах
                drawQueue[p] = dc;
            }
        }
Beispiel #3
0
 private IDrawable[] GetContent()
 {
     IDrawable[] r = new IDrawable[length];
     for (int i = 0; i < length; i++)
     {
         Point location = new Point(startLocation.X + i, startLocation.Y);
         char  c;
         if (Text.Length - 1 >= i)
         {
             // Добавить символ из строки
             c = Text[i];
         }
         else
         {
             /*
              * Если строка закончилась заполнить оставшееся
              * место пробелами
              */
             c = ' ';
         }
         r[i] = new DrawableChar(c, location);
     }
     return(r);
 }