Example #1
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 #2
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 #3
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 #4
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 #5
0
        static void Main(string[] args)
        {
            //Console.SetBufferSize(999, 25);

            // Draw frame

            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.Drow();
            downLine.Drow();
            leftLine.Drow();
            rightLine.Drow();

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

            while (true)
            {
                if(Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
                System.Threading.Thread.Sleep(100);
                snake.Move();
            }

            Console.ReadLine();
        }
Example #6
0
        public Walls(int mapWeight, int mapHeight)
        {
            wallList = new List <Figure>();
            HorizontalLine upLine    = new HorizontalLine(0, mapWeight - 2, 0, '+');
            HorizontalLine downLine  = new HorizontalLine(0, mapWeight - 2, mapHeight - 1, '+');
            VerticalLine   leftLine  = new VerticalLine(0, mapHeight - 1, 0, '+');
            VerticalLine   rightLine = new VerticalLine(0, mapHeight - 1, mapWeight - 2, '+');

            wallList.Add(upLine);
            wallList.Add(downLine);
            wallList.Add(leftLine);
            wallList.Add(rightLine);
        }
Example #7
0
        public Walls(int mapWidth, int mapHeigh)
        {
            wallList = new List <Figure>();

            HorizontalLine lineUP    = new HorizontalLine(0, mapWidth - 2, 0, '+');
            HorizontalLine lineDOWN  = new HorizontalLine(0, mapWidth - 2, mapHeigh - 1, '+');
            VerticalLine   lineLEFT  = new VerticalLine(0, 0, mapHeigh - 1, '+');
            VerticalLine   lineRIGHT = new VerticalLine(mapWidth - 2, 0, mapHeigh - 1, '+');

            wallList.Add(lineUP);
            wallList.Add(lineDOWN);
            wallList.Add(lineLEFT);
            wallList.Add(lineRIGHT);
        }
Example #8
0
        public Wall(int mapWeight, int mapHeight)
        {
            WallList = new List <Figure>();

            HorizontalLine upline    = new HorizontalLine(0, mapWeight, 0, '+');
            HorizontalLine downline  = new HorizontalLine(0, mapWeight, mapHeight, '+');
            VerticalLine   leftline  = new VerticalLine(0, 0, mapHeight, '+');
            VerticalLine   rightline = new VerticalLine(mapWeight, 0, mapHeight, '+');

            WallList.Add(upline);
            WallList.Add(downline);
            WallList.Add(leftline);
            WallList.Add(rightline);
        }
Example #9
0
File: Walls.cs Project: StShu/snake
        public Walls(int mapWidth, int mapHeight)
        {
            wallList = new List <Figura>();

            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, '+');

            wallList.Add(upLine);
            wallList.Add(downLine);
            wallList.Add(leftLine);
            wallList.Add(rightLine);
        }
Example #10
0
        public Walls(int mapWidth, int mapHeight)
        {
            wallList = new List<Figure>();

            //Отрисовка рамки
            HorizontalLine upLine = new HorizontalLine( 0, mapWidth - 2, 0, '+');
            HorizontalLine downLine = new HorizontalLine(0, mapWidth - 2, mapHeight - 1, '+');
            VerticalLine leftLine = new VerticalLine(0, 0, mapHeight - 1, '+');
            VerticalLine rightLine = new VerticalLine(mapWidth - 2, 0, mapHeight - 1, '+');

            wallList.Add(upLine);
            wallList.Add(downLine);
            wallList.Add(leftLine);
            wallList.Add(rightLine);
        }
Example #11
0
        public Walls(int mapWidth, int mapHeight)
        {
            wallList = new List <Figure>();

            // Отрисовка рамочки
            HorizontalLine upLine    = new HorizontalLine(0, mapWidth - 2, 0, '*');
            HorizontalLine downLine  = new HorizontalLine(0, mapWidth - 2, mapHeight - 1, '+');
            VerticalLine   leftLine  = new VerticalLine(0, mapHeight - 1, 0, '+');
            VerticalLine   rightLine = new VerticalLine(0, mapHeight - 1, mapWidth - 2, '+');

            wallList.Add(upLine);
            wallList.Add(downLine);
            wallList.Add(rightLine);
            wallList.Add(leftLine);
        }
Example #12
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 #13
0
        public Walls(int mapWidth, int mapHeight)
        {
            wallList = new List <Figure>();

            //Отрисовка рамочки
            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, '+');

            wallList.Add(upline);
            wallList.Add(downline);
            wallList.Add(leftLine);
            wallList.Add(rightLine);
        }
Example #14
0
        static void Main(string[] args)
        {
            HorizontalLine upline = new HorizontalLine(0, 75, 0, '+');

            upline.Drow();
            HorizontalLine downline = new HorizontalLine(0, 75, 20, '+');

            downline.Drow();
            VerticalLine leftline = new VerticalLine(0, 20, 0, '+');

            leftline.Drow();
            VerticalLine rightline = new VerticalLine(0, 20, 75, '+');

            rightline.Drow();
        }
Example #15
0
        //Конструктор класса
        public Walls(int mapWidth, int mapHeight)
        {
            wallList = new List <Figure>(); //присваиваю значение переменной

            // Отрисовка рамочки
            HorizontalLine upline    = new HorizontalLine(0, mapWidth - 2, 0, '+');
            HorizontalLine downline  = new HorizontalLine(0, mapWidth - 2, mapHeight - 1, '+');
            VerticalLine   leftline  = new VerticalLine(0, mapHeight - 1, 0, '+');
            VerticalLine   rightline = new VerticalLine(0, mapHeight - 1, mapWidth - 2, '+');

            wallList.Add(upline);
            wallList.Add(downline);
            wallList.Add(leftline);
            wallList.Add(rightline);
        }
Example #16
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(400, 100);

            HorisontalLine Upline    = new HorisontalLine(0, 78, 0, '+');
            HorisontalLine Downline  = new HorisontalLine(0, 78, 24, '+');
            VerticalLine   Leftline  = new VerticalLine(0, 24, 0, '+');
            VerticalLine   Rightline = new VerticalLine(0, 24, 78, '+');

            Upline.Drow();
            Downline.Drow();
            Leftline.Drow();
            Rightline.Drow();

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

            p1.Draw();
            Point p2 = new Point(2, 3, '#');

            p2.Draw();
            HorizontalLine line = new HorizontalLine(5, 10, 3, '*');

            line.Drow();
            VerticalLine line2 = new VerticalLine(0, 5, 9, '#');

            line2.Drow();
            Console.ReadLine();
        }
Example #18
0
        public Walls(int mapWidth, int mapHeight)
        {
            wallList = new List <Figure>();


            // Отрисовка рамочки

            HorizontalLine UpLine    = new HorizontalLine(0, mapWidth - 2, 0, '+');
            HorizontalLine DownLine  = new HorizontalLine(0, mapWidth - 2, mapHeight - 1, '+');
            VerticalLine   RightLine = new VerticalLine(0, mapHeight - 1, 0, '+');
            VerticalLine   LeftLine  = new VerticalLine(0, mapHeight - 1, mapWidth - 2, '+');

            wallList.Add(UpLine);
            wallList.Add(DownLine);
            wallList.Add(LeftLine);
            wallList.Add(RightLine);
        }
Example #19
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 #20
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 #21
0
        static void Main(string[] args)
        {

            //Console.SetBufferSize(100, 45);

            //отрисовка рамочки
            HorizontallLine upLine = new HorizontallLine(0, 78, 0, '+');
            HorizontallLine downLine = new HorizontallLine(0, 78, 24, '+');
            VerticalLine lefLine = new VerticalLine(0, 24, 0, '+');
            VerticalLine rightLine = new VerticalLine(0, 24, 78, '+');
            upLine.DrowHorLine();
            downLine.DrowHorLine();
            lefLine.DrowVertLine();
            rightLine.DrowVertLine();


            Console.ReadLine();
        }
Example #22
0
        public static void Main(string[] args)
        {
            // Отрисовка рамочки
            HorizontalLine upLine    = new HorizontalLine(0, 150, 0, '+');
            HorizontalLine downLine  = new HorizontalLine(0, 150, 15, '+');
            VerticalLine   leftLine  = new VerticalLine(0, 15, 0, '+');
            VerticalLine   rightLine = new VerticalLine(0, 15, 150, '+');
//            upLine.Draw();
//            downLine.Draw();
//            leftLine.Draw();
//            rightLine.Draw();

            // Отрисовка точек
            Point p     = new Point(5, 4, '*');
            Snake snake = new Snake(p, 3, 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();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Example #23
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 #24
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 28);

            // Отрисовка линий
            HorizontalLine upLine    = new HorizontalLine(0, Console.BufferWidth - 1, 0, '+');
            HorizontalLine downLine  = new HorizontalLine(0, Console.BufferWidth - 1, Console.BufferHeight - 1, '+');
            VerticalLine   leftLine  = new VerticalLine(0, Console.BufferHeight - 1, 0, '+');
            VerticalLine   rightLine = new VerticalLine(0, Console.BufferHeight - 1, Console.BufferWidth - 1, '+');

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

            //Отрисовка Точек
            Point p1 = new Point(5, 6, '*');

            p1.Draw();
        }
Example #25
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(150, 95);

            HorizontalLine lineUp = new HorizontalLine(0, 78, 0, '+');

            lineUp.Drow();
            HorizontalLine LineDown = new HorizontalLine(0, 78, 24, '+');

            LineDown.Drow();
            VerticalLine LeftLine = new VerticalLine(0, 0, 24, '+');

            LeftLine.Drow();
            VerticalLine RightLine = new VerticalLine(78, 0, 24, '+');

            RightLine.Drow();



            Console.ReadLine();
        }
Example #26
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(80, 25);
            Console.SetWindowSize(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.Drow();
            downLine.Drow();
            leftLine.Drow();
            rightLine.Drow();

            Point p = new Point(4, 5, '*');

            p.Draw();

            Console.ReadKey();
        }
Example #27
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            // Нарисуем рамку
            HorizontalLine lineHup   = new HorizontalLine(0, 78, 0, '+');
            HorizontalLine lineHdown = new HorizontalLine(0, 78, 24, '+');
            VerticalLine   lineVr    = new VerticalLine(0, 24, 0, '+');
            VerticalLine   lineVl    = new VerticalLine(0, 24, 78, '+');

            lineHup.Drow();
            lineHdown.Drow();
            lineVr.Drow();
            lineVl.Drow();

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

            snake.Drow();

            Console.ReadLine();
        }
Example #28
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 #29
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);
            }
        }