コード例 #1
0
ファイル: Program.cs プロジェクト: Maximilian13/Project_1
        static void Main(string[] args)
        {
            int Width = 80;
            int Height = 45;
            Console.SetBufferSize(Width, Height);
            Console.SetWindowSize(Width - 1, Height - 1);

            Obstacles border = new Obstacles();
            border.setBorder(Width, Height);
            border.setObstacles(Width, Height);

            Point p1 = new Point(2, 2, '*');
            Snake snake = new Snake(p1, 3, Direction.Right);
            snake.Drow();

            FoodCreator foodCreator = new FoodCreator(Width - 3, Height - 3, '#');
            Point food = foodCreator.CreateFood();
            food.Draw();
            int k = 150;

            while (true)
            {
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    k -= 5;
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Pressure(key.Key);
                }

                Thread.Sleep(k);
                snake.Move();
                Console.SetCursorPosition(0, 0);
            }
        }