繁体   English   中英

c#控制台应用程序游戏中的两个游标

[英]c# two cursors in a console application game

我正在尝试在 ac# 控制台应用程序中制作蛇游戏。

using System.Reflection;

namespace First_console_game
{
    class Program
    {
        static void Main(string[] args)
        {
            Random rnd = new Random();
            int redo = 0;
            Byte Foods = 0;
            Byte Flops = 0;
            int x = 10, y = 20;
            int Foodx = rnd.Next(1, 200);
            int Foody = rnd.Next(1, 175);
            ConsoleKeyInfo keyInfo;
            do
            {
                keyInfo = Console.ReadKey(true);

                //Console.SetCursorPosition(Foodx, Foody); This is the position of the food cell, and this is the part where it doesn't work. 

                Flops += 1;
                if (Flops == 5)
                {
                    Console.Clear();
                    Flops = 0;
                }



                switch (keyInfo.Key)
                {
                    case ConsoleKey.RightArrow:
                        x += 1;
                        Console.SetCursorPosition(x, y);
                        Console.Write("x");
                        break;
                    case ConsoleKey.LeftArrow:
                        x--;
                        Console.SetCursorPosition(x, y);
                        Console.Write("x");
                        break;
                    case ConsoleKey.UpArrow:
                        y -= 1;
                        Console.SetCursorPosition(x, y);
                        Console.Write("^");
                        break;
                    case ConsoleKey.DownArrow:
                        y += 1;
                        Console.SetCursorPosition(x, y);
                        Console.Write("x");
                        break;


                }

            } while (redo == 0);
            Console.ReadLine();
        }
    }
}

在游戏中,我想要两个光标。 一份给食物,一份给玩家。

但很明显,我不能使用Console.SetCursorPosition(Foodx, Foody)因为这会驱动玩家在屏幕上四处走动,从而弄乱游戏。

那么如何添加单独的游标呢? 谢谢。

回复:“但很明显,......” - 这一点都不明显! 您可以在那里设置光标并输出一些“食物”字符,例如*F

Cursor 在你的游戏中不做任何事情,所以你可以用

Console.CursorVisible = false;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM