AngryHacker AngryHacker - 1 month ago 11
C# Question

Looking for the Nibbles game rewritten in 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?

Answer

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.

Comments