Exemple #1
0
        public static void Move()
        {
            PointConsole tempPoint = BodyPoints.First();

            if (Direct == Direction.Up)
            {
                tempPoint = new PointConsole(tempPoint.X, tempPoint.Y - 1);
            }
            if (Direct == Direction.Down)
            {
                tempPoint = new PointConsole(tempPoint.X, tempPoint.Y + 1);
            }
            if (Direct == Direction.Left)
            {
                tempPoint = new PointConsole(tempPoint.X - 1, tempPoint.Y);
            }
            if (Direct == Direction.Right)
            {
                tempPoint = new PointConsole(tempPoint.X + 1, tempPoint.Y);
            }

            BodyPoints.Insert(0, tempPoint);
            new PointConsole(BodyPoints.Last().X, BodyPoints.Last().Y).DrawPoint(' ');
            BodyPoints.Remove(BodyPoints.Last());
            DrawSnake();
        }
Exemple #2
0
        static void BornBody()
        {
            BodyPoints = new List <PointConsole>();
            PointConsole centr = new PointConsole(Console.WindowWidth / 2, Console.WindowHeight / 2);

            for (int i = 0; i < 5; i++)
            {
                BodyPoints.Add(new PointConsole(centr.X, centr.Y + i));
            }
        }
Exemple #3
0
        public static void GeneratePosEat()
        {
            Random rnd = new Random();

            _Position = new PointConsole(rnd.Next(1, Console.WindowWidth - 2), rnd.Next(1, Console.WindowHeight - 2));

            if (Snake.BodyPoints.Exists(x => x.Y == _Position.Y && x.X == _Position.X))
            {
                GeneratePosEat();
            }
            else
            {
                Console.Beep();
                Draw();
            }
        }