寻找用 C# 重写的 Nibbles 游戏

发布于 2024-09-26 09:59:31 字数 189 浏览 3 评论 0原文

我正在编写一个控制台应用程序,它将启动长时间运行的进程。因此,我不想让用户盯着屏幕几分钟,而是希望将处理工作放在后台线程上,并让用户同时玩游戏。

如果您和我同龄,您肯定还记得用 QBasic 编写的 Nibbles 游戏,该游戏多年来一直随 DOS 一起提供。我记得几年前读到有人用 C# 控制台模式重写了它。但我找不到它。有谁知道哪里可以拿到吗?

I am writing a console app that would be kicking off long running processes. So rather than let the user stare at the screen for several minutes, I'd love to throw my processing on a background thread and let the user play a game meanwhile.

If you are my age, you definitely remember the Nibbles game written in QBasic that shipped with DOS for years. I remember reading several years ago that someone rewrote it in C# console mode. But I can't find it. Anyone know where I could grab it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对不⑦ 2024-10-03 09:59:31

我看到你的问题,立即将原始 NIBBLES.BAS 直接翻译成 C#。

当然,代码充满了基础知识;特别是,数组从 1 开始。我更改了 sammycolorTable 数组,以便它们从 0 开始,但 arena 数组不从 0 开始(这个现在有一个未使用的索引0)。

在 C# 中,很多事情都可以做得更“正确”(例如,应该使用枚举而不是数字 1,2,3,4 来表示上、下、左、右方向;应该使用 ConsoleColor 枚举而不是颜色的整数)。

不过,我确实使用了一些 C#ism:初始屏幕上的闪光效果是在单独的线程中完成的,这样我就可以使用 Console.ReadKey() 来等待用户输入。

我必须注释掉设置/取消设置 Num Lock、Caps Lock 和 Scroll Lock 的代码,因为 C# 的 Console 只允许我读取这些状态,而不能更改它们。为此,我必须使用 WinAPI,我认为这有点过分了。

所有评论均来自原文。

编辑:到目前为止,其完成版本已在 github 上。我已经更改了上面的链接以转到 github 存储库而不是 Pastebin。对于那些仍然对原始第一个版本感兴趣的人,这里是原始的 Pastebin 链接

I saw your question and immediately went ahead and translated the original NIBBLES.BAS directly into C#.

Of course, the code is full of Basicisms; in particular, arrays start at 1. I have changed the sammy and colorTable arrays so that they start at 0, but not the arena array (this one now has an unused index 0).

Many things could be done more “properly” in C# (e.g. one should probably use enums instead of the numbers 1,2,3,4 for directions up,down,left,right; one should use the ConsoleColor enum instead of integers for the colors).

I did use a few C#isms though: the sparkle effect on the initial screen is done in a separate thread so that I can just use Console.ReadKey() to wait for user input.

I had to comment out the code that sets/unsets Num Lock, Caps Lock and Scroll Lock because C#’s Console only lets me read the state of those, not change them. I would have had to use WinAPI for this, which I decided would have been over the top.

All the comments are from the original.

EDIT: By now the finished version of this is on github. I’ve changed the above link to go to the github repo instead of a pastebin. For those still interested in the original first version, here’s the original pastebin link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文