Beispiel #1
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();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            hLine upLine = new hLine( 0, 78, 0, '#' );
            hLine downLine = new hLine(0, 78, 24, '#');
            vLine leftLine = new vLine(0, 24, 0, '#');
            vLine rightLine = new vLine(0, 24, 78, '#');

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

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

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

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

            Console.ReadLine();
        }
Beispiel #3
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();
     }
 }
Beispiel #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();
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);
            Console.CursorVisible = false;

            Walls walls = new Walls(80, 25);

            walls.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 (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                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);
                }
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);

            Walls walls = new Walls(120, 30);

            walls.Draw();


            //Отрисовка точек
            point p     = new point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.right);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(120, 30, '$');
            point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                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);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80,25); //установить размер окна и убрать возможность перемотки

            Walls walls = new Walls(80, 25);
            walls.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 (walls.IsHit(snake) || snake.IsHitTail())
                {
                    Console.Clear();
                    Console.SetCursorPosition(37, 7);
                    Console.Write("YOU LOSE");
                    break;
                }
                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);
                }
            }

            Console.ReadKey();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);

            Wall walls = new Wall(120, 30);

            walls.Draw();

            Point p     = new Point(50, 10, '*');
            Snake snake = new Snake(p, 4, Direction.left);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(120, 30, 'o');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }


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

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key);
                }
                Thread.Sleep(400);
                snake.Move();
            }
        }
Beispiel #9
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);
                }
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            // Console.SetBufferSize(60, 20);

            Walls walls = new Walls(60, 20);

            walls.Draw();

            //отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.Right);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(60, 20, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                else if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(150);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);
            walls.Drow();

            //Отрисовка точек
            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Drow();

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

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Drow();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Beispiel #12
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();
        }