示例#1
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.Drow();
            downLine.Drow();
            leftLine.Drow();
            rightLine.Drow();
            Point p = new Point(5, 4, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            Food foodcreate = new Food(80,25,'$');
            Point food = foodcreate.CreatePossition();
            food.Draw();

            Console.Title = "Змейка";

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Arrow( key.Key );
                }
                Thread.Sleep(100);
                if (snake.Eat(food))
                {
                    food = foodcreate.CreatePossition();
                    food.Draw();
                }
                if (snake.die())
                {
                    snake = new Snake(p, 4, Direction.RIGHT);
                }
                snake.Move();

            }
        }