【问题标题】:Console game Character主机游戏角色
【发布时间】:2018-10-28 12:13:44
【问题描述】:

自从开始开发我的游戏以来,我学到了很多东西。现在我正处于需要实现适当的玩家角色的阶段。我一直在尝试这样做一段时间,但我无法让它与我的运动系统一起工作。这是我的运动系统(有碰撞):

ConsoleKeyInfo input = Console.ReadKey(true);
                    switch (input.KeyChar)
                    {
                        case 'w':
                            if (y >= 1 && data[y - 1][x] != '#')
                            {
                                oldx = Console.CursorLeft;
                                oldy = Console.CursorTop;
                                Console.SetCursorPosition(x + 0, y - 1);
                                x = Console.CursorLeft;
                                y = Console.CursorTop;
                                //if (x == 11 && y == 11 )            
                            }
                            break;

                        case 'a':
                            if (x >= 1 && data[y][x - 1] != '#')
                            {
                                oldx = Console.CursorLeft;
                                oldy = Console.CursorTop;
                                Console.SetCursorPosition(x - 1, y + 0);
                                x = Console.CursorLeft;
                                y = Console.CursorTop;
                            }
                            break;

                        case 's':
                            if (y < Console.WindowHeight - 1 && data[y + 1][x] != '#')
                            {
                                oldx = Console.CursorLeft;
                                oldy = Console.CursorTop;
                                Console.SetCursorPosition(x + 0, y + 1);
                                x = Console.CursorLeft;
                                y = Console.CursorTop;
                            }
                            break;

                        case 'd':
                            if (x < Console.WindowWidth - 1 && data[y][x + 1] != '#')
                            {
                                oldx = Console.CursorLeft;
                                oldy = Console.CursorTop;
                                Console.SetCursorPosition(x + 1, y + 0);
                                x = Console.CursorLeft;
                                y = Console.CursorTop;
                            }
                            break;
                    }

我的地图是 ascii 地图,以 ConsoleColor 必须提供的颜色显示。在玩家角色的后面,应该重绘对应的地图图块,而不是重绘整个地图(在游戏过程中必须这样做真的很烦人)

当您退出地图时,将绘制一张新地图,并将玩家传送到该地图的入口处。

如何将角色的绘制实现为子程序?

提前谢谢你!

【问题讨论】:

  • 你可以设置光标位置,但是这有点hacky
  • @TheGeneral 嗯,实际上是的,如果设置光标位置并写入,它会更新几个字符

标签: c# ascii console-application


【解决方案1】:

试试这些

protected static void WriteAt(string s, int x, int y)
{
    try
    {
       Console.SetCursorPosition(origCol+x, origRow+y);
       Console.Write(s);
    }
    catch (ArgumentOutOfRangeException e)
    {
       Console.Clear();
       Console.WriteLine(e.Message);
    }
}

Console.CursorTop Property

获取或设置光标在缓冲区内的行位置。

Console.CursorLeft Property

获取或设置光标在缓冲区内的列位置。

Console.SetCursorPosition(Int32, Int32) Method

设置光标的位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多