Пример #1
0
        // constructor
        public Snake(Color color, Game b, int s, string name)
        {
            Speed = s;
            Name  = name;

            bases = b;
            Position.Add(new Point(bases.R.Next(bases.Width), bases.R.Next(bases.Height)));

            Size = bases.Scale;
            chooseStartingDirection(bases.Width, bases.Height);
            Color = new SolidBrush(color);
        }
Пример #2
0
        public static void FindPath(ConsoleKey key)
        {
            if (directionSwitcher.ContainsKey(key))
            {
                directionSwitcher.TryGetValue(key, out direction);
            }

            Position nextPosition       = head.Add(direction);
            string   nextPositionSymbol = Field[nextPosition.y, nextPosition.x];

            if (nextPositionSymbol == GetFieldObjectSymbol(FieldObject.FOOD))
            {
                Eat(nextPosition);
            }
            else if (nextPositionSymbol == GetFieldObjectSymbol(FieldObject.EMPTY))
            {
                Move(nextPosition);
            }
            else
            {
                EndGame();
            }
        }