views:

125

answers:

2

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?

+4  A: 

Do you mean this one?

Here's one that's console-based.

Robert Harvey
@ChristopheD: See my edit.
Robert Harvey
It is a shame that the author would use ASCII characters like `|`, `+` and `-` instead of the box-drawing/filling characters that the original QBasic Nibbles used.
Timwi
It's pretty close. The one I was thinking of had the extended ASCII for the | chars as Timwi had mentioned. It's awesome though.
AngryHacker
The characters are defined in the game levels. Just go into it and replace the - and | with their extended ascii characters and you are good to go. Back in the 80s.
AngryHacker
+4  A: 

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.

Timwi
That's pretty awesome.
AngryHacker
One complaint. It works well if in the properties for the DOS window you've selected Lucida Console fonts. But if you have the Raster Fonts selected (which I think is the default), the screen is an absolute mess.
AngryHacker
@AngryHacker: I know. It’s very unfortunate. If you know of a way to fix this, I would love to hear. I don’t know how to change the console font programmatically, or even to determine what the font is. If I could at least determine it, then I could use the old DOS codepage when it is Raster Fonts.
Timwi
@Timwi: I fixed it to work with both raster and TT fonts. I also added a few other minor changes like properly restoring the console. http://pastebin.com/LjXn7246
Tergiver
There's also a bug in `InitColors`. The background color needs to be set (black) before calling `Console.Clear`. There's a small chance (I saw it once in about 25 levels played) that the background color is non-black prior to a level change.
Tergiver
...That would be colorTable[3], not black.
Tergiver
Why does pastebin give you a new URL for corrections? That's not very usable. Here is the corrected one: http://pastebin.com/AzECdgYw
Tergiver
Fixed the lack of arrows for raster fonts. http://pastebin.com/KkuwFLCd
Tergiver
@Tergiver: Thanks, I’ll take a look at it tomorrow. By now I have considerably “fixed” the code on my end here, removing all the Basicisms and making it more C#-like. I’ll try to merge your changes and then upload it to Codeplex or something, OK?
Timwi
@Timwi: Cool. I thought about cleaning it up myself, it's even more messy with the changes I made, but I got distracted by writing a QBasic PLAY routine so I could put the sounds in. I have something working now which uses DirectSound, but it uses SlimDX and I want to remove any 3rd party DX wrapper (no SlimDX/MDX). There's only a handful of DX calls, but doing them without unsafe code requires a ton of wrapper code.
Tergiver
@Tergiver: [Done.](http://csnibbles.codeplex.com/) (I haven’t copied all of your code — the character code changes weren’t necessary. I’ve implemented my own rudimentary version of PLAY, which doesn’t really work very well — feel free to replace it completely if you like.)
Timwi
@Timwi: Nice. I made several issue reports. These notes are primarily for myself as I looked it over, but can't work on it right now.
Tergiver
@Tergiver: Are you working on those issues you submitted? A friend of mine is strongly suggesting that we move this to BitBucket which is supposedly better, what do you think? — Also, if you would like to get in contact so we don’t have to use this StackOverflow thread, please contact me on Skype (timwiterby), thanks!
Timwi
@Timwi: Yes, check Source Code > Patches. There is where all the fixes are. (I knew that patches section was too out of the way to see).
Tergiver