c# - 主机游戏角色
问题描述
自从开始开发我的游戏以来,我学到了很多东西。现在我正处于需要实现适当的玩家角色的阶段。我一直在尝试这样做一段时间,但我无法让它与我的运动系统一起工作。这是我的运动系统(有碰撞):
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 必须提供的颜色显示。在玩家角色后面,应该重绘相应的地图图块,而不是重绘整个地图(必须这样做在游戏过程中真的很烦人)
当您退出地图时,将绘制一张新地图,并将玩家传送到该地图的入口。
我将如何将角色的绘制实现为子程序?
先感谢您!
解决方案
试试这些
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.SetCursorPosition(Int32, Int32) 方法
设置光标的位置。
推荐阅读
- search - 你如何使用 vim-extension 在 vscode 中显示搜索文本?
- python - 在python中解析子/孙
- java - Java 静态到 Kotlin 的转换
- docker - Redis 将数据存储在 backup.db 文件中
- discord.js - 检查反应/每个用户,限制
- c - 使函数在 C 中的库外部不可见
- .htaccess - 当.htm 不在特定文件夹中时,htaccess 会重定向除 .htm 之外的所有内容
- python - 在谷歌云上运行 python 脚本时出现内存错误
- sql - 在层次结构表中复制一行及其下方的所有行
- python - 简单的 LSTM ValueError Python