当前位置: 首页>>代码示例>>C#>>正文


C# Input.CheckInput方法代码示例

本文整理汇总了C#中Input.CheckInput方法的典型用法代码示例。如果您正苦于以下问题:C# Input.CheckInput方法的具体用法?C# Input.CheckInput怎么用?C# Input.CheckInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Input的用法示例。


在下文中一共展示了Input.CheckInput方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] a)
        {
            SnakePart snake = new SnakePart();
            bool gameOver = false;
            bool pause = false;
            bool inuse = false;
            string newKey = "right"; // 0 = up, 1 = right, 2 = down, 3 = left
            string prevKey = newKey;
            int boardWidth = Console.WindowWidth; //
            int boardHeight = Console.WindowHeight; //

            var rng = new Random();
            var point = new Point();
            var snakeParts = new List<Point>();

            Console.CursorVisible = false;
            for (int i = 0; i < 4; i++)
            {
                snakeParts.Add(new Point(10, 10));
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.SetCursorPosition(10, 10);
            Console.Write("@");

               Food food = new Food();

            food.DrawFood();

            /*            while (true)
            {
                Point.X = rng.Next(0, boardWidth);
                Point.Y = rng.Next(0, boardHeight);
                bool spot = true;
                foreach (Point p in snakeParts)
                {
                    if (p.X == Point.X && p.Y == Point.Y)
                    {
                        spot = false;
                        break;
                    }
                }
                if (spot)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(Point.X, Point.Y);
                    Console.Write("$");
                    break;
                }
            }*/
            var time = new Stopwatch();
            time.Start();
            while (!gameOver)
            {

            /*                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo controls = Console.ReadKey(true); // 0 = up, 1 = right, 2 = down, 3 = left
                    if (controls.Key == ConsoleKey.Escape)
                    {
                        gameOver = true;
                    }
                    else if (controls.Key == ConsoleKey.Spacebar)
                    {
                        pause = !pause;
                    }
                    else if (controls.Key == ConsoleKey.UpArrow && prevKey != "down")
                    {
                        newKey = "up";
                    }
                    else if (controls.Key == ConsoleKey.RightArrow && prevKey != "left")
                    {
                        newKey = "right";
                    }
                    else if (controls.Key == ConsoleKey.DownArrow && prevKey != "up")
                    {
                        newKey = "down";
                    }
                    else if (controls.Key == ConsoleKey.LeftArrow && prevKey != "right")
                    {
                        newKey = "left";
                    }
                }*/
                if (!pause)
                {
                    if (time.ElapsedMilliseconds < 100)
                    {
                        continue;
                    }
                    time.Restart();

                    Input input = new Input();
                    input.CheckInput();
            /*                    var tail = new Point(snakeParts.First());
                    var head = new Point(snakeParts.Last());
                    var newHead = new Point(head);*/
            /*                    switch (newKey)
                    {
                        case "up":
                            newHead.Y -= 1;
//.........这里部分代码省略.........
开发者ID:Road11,项目名称:PGInnlevering,代码行数:101,代码来源:Program.cs


注:本文中的Input.CheckInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。