c# - 如何制作边界线
问题描述
所以我正在制作一个游戏,我正在尝试制作一个从控制台顶部到控制台左侧底部的边界线。这是我尝试制作这条线的代码
Console.SetCursorPosition(0, Console.WindowWidth + 20);
Console.Write(new string( '|', Console.WindowHeight));
我的这个控制台的尺寸是
Console.SetWindowSize(120, 30);
Console.SetBufferSize(120, 30);
我只是一个初学者,所以如果有一个简单的方法可以帮助我。
解决方案
看看我的代码,我在这里找到了大部分代码并根据您的需要进行了调整。
protected static int origRow;
protected static int origCol;
static void Main(string[] args)
{
Console.SetWindowSize(120, 30);
// Clear the screen, then save the top and left coordinates.
Console.Clear();
origRow = Console.CursorTop;
origCol = Console.CursorLeft;
int height = Console.WindowHeight;
for (int i = 0; i < height; i++)
WriteAt("|", 0, i);
// this is to force to keep the application running. Now visual studio
// will not put some extra text at the end of the screen
Console.ReadLine();
}
// write a string as location x,y
public 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);
}
}
推荐阅读
- authentication - 团队中的图形工具包组件使用情况在没有登录组件的情况下反应应用程序
- javascript - 单击按钮时增加一个数字
- vue.js - Vee-Validate - 检查输入是否已填写
- php - 通过 ssh 连接的 RAM 消耗非常高
- javascript - 如何使用 puppeteer 捕获加载的脚本错误
- java - 如何使用 srcML 实现数据流分析?
- python - Selenium 找不到 div 输入字段元素
- javascript - 如何将 API 数据传递给子组件
- windows-10 - Sharepoint 驱动器已映射但无法访问?
- mariadb - 查询 MariaDB 的安装文件夹?