コード例 #1
0
ファイル: Program.cs プロジェクト: nielKol/HomeWork2
        static void Main(string[] args)
        {
            Point snake = new Point(Console.WindowWidth / 2, Console.WindowHeight / 2, '@');

            Console.SetCursorPosition(snake.X, snake.Y);
            snake.Display();

            ConsoleKey key;

            do
            {
                key = Console.ReadKey().Key;

                if (key != null)
                {
                    if (key == ConsoleKey.LeftArrow)
                    {
                        snake.X--;
                    }
                    else if (key == ConsoleKey.RightArrow)
                    {
                        snake.X++;
                    }
                    else if (key == ConsoleKey.UpArrow)
                    {
                        snake.Y--;
                    }
                    else if (key == ConsoleKey.DownArrow)
                    {
                        snake.Y++;
                    }

                    Console.Clear();
                    Console.SetCursorPosition(snake.X, snake.Y);
                    snake.Display();
                }
            } while (key != ConsoleKey.Escape);
        }