Example #1
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            HorizontalLine upline = new HorizontalLine(0, 78, 0, '+');

            upline.Draw();
            HorizontalLine downline = new HorizontalLine(0, 78, 24, '+');

            downline.Draw();
            VerticalLine leftline = new VerticalLine(0, 24, 0, '+');

            leftline.Draw();
            VerticalLine rightline = new VerticalLine(0, 24, 78, '+');

            rightline.Draw();

            Point p     = new Point(4, 5, '@');
            Snake snake = new Snake(p, 4, Directions.RIGHT);

            snake.Draw();


            snake.Move();
            Console.ReadLine();
        }
Example #2
0
 static void Main(string[] args)
 {
     // рисую рамочку по краям
     HorizontalLine line = new HorizontalLine(0,78,0,'%');
     HorizontalLine line2 = new HorizontalLine(0, 78, 24, '%');
     VerticalLine line3 = new VerticalLine(0, 24, 0, '%');
     VerticalLine line4 = new VerticalLine(0, 24, 78, '%');
     line.Draw();
     line2.Draw();
     line3.Draw();
     line4.Draw();
     //рисую змейку
     Point p = new Point(4, 5, '*');
     Snake snake = new Snake(p, 4, Direction.RIGHT   );
     snake.Draw();
     //moving
     while (true)
     {
         if (Console.KeyAvailable)
         {
             ConsoleKeyInfo key = Console.ReadKey();
             snake.HandleKey(key.Key);
         }
         Thread.Sleep(100);
         snake.Move();
     }
 }
Example #3
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            Console.CursorVisible = false;

            VerticalLine   leftLine   = new VerticalLine(0, 24, 0, '|');
            VerticalLine   rigthLine  = new VerticalLine(0, 23, 78, '|');
            HorizontalLine topLine    = new HorizontalLine(1, 77, 0, '-');
            HorizontalLine bottomLine = new HorizontalLine(1, 77, 23, '-');

            Console.ForegroundColor = ConsoleColor.Blue;
            leftLine.Draw();

            Console.ForegroundColor = ConsoleColor.Blue;
            rigthLine.Draw();

            Console.ForegroundColor = ConsoleColor.Green;
            topLine.Draw();

            Console.ForegroundColor = ConsoleColor.Green;
            bottomLine.Draw();

            Console.ResetColor();
            Point p = new Point(40, 12, '*');

            p.Draw();
            Console.ReadLine();
        }
Example #4
0
        static void Main(string[] args)
        {
            Point p1 = new Point(1, 2, '*');
            p1.Draw();

            Point p2 = new Point(4, 5, '#');
            p2.Draw();

            Console.SetBufferSize(80, 25);

            HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+');
            HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+');
            upLine.Draw();
            downLine.Draw();

            VerticalLine leftLine = new VerticalLine(0, 24, 0, '+');
            VerticalLine rightLine = new VerticalLine(78, 24, 0, '+');
            leftLine.Draw();
            rightLine.Draw();

            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 6, Direction.RIGHT);
            snake.Draw();

            while(true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
                Thread.Sleep(100);
                snake.Move();
            }
        }
Example #5
0
        private static void DrawField()
        {
            HorizontalLine lineTop = new HorizontalLine(2, 118, 0, '+');

            lineTop.Draw();
            HorizontalLine lineBottom = new HorizontalLine(2, 118, 29, '+');

            lineBottom.Draw();
            VerticalLine lineLeft = new VerticalLine(0, 29, 2, '+');

            lineLeft.Draw();
            VerticalLine lineRight = new VerticalLine(0, 29, 118, '+');

            lineRight.Draw();
        }
Example #6
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(80, 25);
            Console.SetWindowSize(80, 25);

            HorisontalLine upline    = new HorisontalLine(0, 78, 0, '+');
            VerticalLine   rigthline = new VerticalLine(0, 0, 24, '+');
            HorisontalLine downline  = new HorisontalLine(0, 78, 24, '+');
            VerticalLine   leftline  = new VerticalLine(78, 0, 24, '+');

            upline.Draw();
            rigthline.Draw();
            downline.Draw();
            leftline.Draw();

            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 3, Direction.RIGTH);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '#');
            Point       food        = foodCreator.CreateFood();

            food.Drow();

            while (true)
            {
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Drow();
                }
                else
                {
                    snake.Move();
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.directionOfMovement(key.Key);
                }
                Thread.Sleep(300);
                snake.Move();
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            HorizontalLine top = new HorizontalLine(1, 78, 1, '+');
            top.Draw();
            HorizontalLine bottom = new HorizontalLine(1, 78, 24, '+');
            bottom.Draw();
            VerticalLine left = new VerticalLine(1, 1, 24, '+');
            left.Draw();
            VerticalLine right = new VerticalLine(78, 1, 24, '+');
            right.Draw();

            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 6, Direction.RIGHT);
            snake.Draw();

            for (int i = 0; i < 10; i++)
            {
                snake.Move();
                Thread.Sleep(300);
            }

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key == ConsoleKey.LeftArrow)
                        snake.direction = Direction.LEFT;
                    else if (key.Key == ConsoleKey.RightArrow)
                        snake.direction = Direction.RIGHT;
                    else if (key.Key == ConsoleKey.UpArrow)
                        snake.direction = Direction.UP;
                    else if (key.Key == ConsoleKey.DownArrow)
                        snake.direction = Direction.DOWN;
                    else if (key.Key == ConsoleKey.Escape)
                        break;

                }
                Thread.Sleep(100);
                snake.Move();

            }
        }
Example #8
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            HorizontalLine upLine = new HorizontalLine(0,78,0,'+');
            HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+');
            VerticalLine leftLine = new VerticalLine(0, 24, 0, '+');
            VerticalLine rightLine = new VerticalLine(0, 24, 78, '+');

            upLine.Draw();
            downLine.Draw();
            leftLine.Draw();
            rightLine.Draw();

            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point food = foodCreator.CreateFood();
            food.Draw();

            while (true)
            {
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                //if (Console.KeyAvailable)
                //{
                //    ConsoleKeyInfo key = Console.ReadKey();
                //    snake.HandleKey(key.Key);
                //}
                Thread.Sleep(300);
                //snake.Move();
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);

            HorizontalLine topLine    = new HorizontalLine(0, 78, 0, '-');
            HorizontalLine bottomLine = new HorizontalLine(0, 78, 24, '-');

            VerticalLine leftLine  = new VerticalLine(0, 24, 0, '|');
            VerticalLine rightLine = new VerticalLine(0, 24, 78, '|');

            topLine.Draw();
            bottomLine.Draw();
            leftLine.Draw();
            rightLine.Draw();

            Point p = new Point(2, 3, '*');

            Snake snake = new Snake(p, 5, Direction.RIGHT);

            snake.Draw();

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();

                    snake.HandleKey(key.Key);
                }

                Thread.Sleep(100);
                snake.Move();
            }

            Console.ReadLine();
        }
Example #10
0
        static void Main(string[] args)
        {
            //Установим размер окна консоли
            Console.SetWindowSize(105, 30);

            //Ограждение игрового поля
            HorizontalLine horizontalLine = new HorizontalLine(0, 100, 0, '*');

            horizontalLine.Draw();

            HorizontalLine horizontalLine2 = new HorizontalLine(0, 100, 24, '*');

            horizontalLine2.Draw();


            VerticalLine verticalLine = new VerticalLine(0, 24, 0, '*');

            verticalLine.Draw();

            VerticalLine verticalLine2 = new VerticalLine(0, 24, 100, '*');

            verticalLine2.Draw();

            //Cоздаём змею
            //точка её хвоста
            Point tail = new Point(2, 2, 'x');
            //змея длиной 3, ползёт вправо
            Snake snake = new Snake(tail, 10, Direction.right);

            snake.Draw();

            Food food = new Food(100, 24, 'o');

            food.MakeFood(ref snake.coordinats);

            //движение и управление змейкой
            while (true)
            {
                //Проверяем не закончилась ли игра если змея столкнулась с самой собой или оградой поля
                if (snake.Collision())
                {
                    break;
                }

                //Проверяем съела ли змея фрукт, если да генерим новый
                if (snake.Eat(food))
                {
                    food.MakeFood(ref snake.coordinats);
                    snake.Draw();
                }

                //Смотрим нажатия клавиш пользователем
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    //Вызываем метод управления направлением змеи из класса Snake
                    snake.SnakeControl(key.Key);
                }
                //Движение змеи
                snake.Move();
                Thread.Sleep(300);
            }
        }