|
|||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
------*------
------------- `--- ------'
`-------- --' / /
\\------- --
'-----------'
The USS Enterprise --- NCC - 1701
Your mission begins with your starship located
in the galactic quadrant Canopus.
Your orders are as follows:
Destroy the 24 Klingon warships which have invaded
the galaxy before they can attack Federation Headquarters
on stardate 3732. This gives you 32 days. There are
3 starbases in the galaxy for resupplying your ship.
Hit any key to accept command.
------------------------
. . . . * . . . Stardate 3700
. . . . . . . . Condition GREEN
. * . . . . . . Quadrant (5, 4)
. . . * . . . . Sector (5, 2)
. <E> . . . . . . Photon Torpedos 10
. * . . . . . . Total Energy 3000
* . * * . . . . Shields 0
. . . . . . . * Klingons 24
------------------------
Command?
IntroductionHere is my entry into The Code Project Random Programming Competition for Summer 2008. It seems that Michael Birken beat me to being the first to post a Star Trek article. Since the two programs have a shared history and game play, which he covers extensively in his article, it's best if you read that one first. (It's OK.... I'll wait.) I'll just concentrate on the difference in my design. BackgroundThis port took a roundabout journey to the pages of CodeProject. As Mr. Birken describes, Mike Mayfield's program was ported to PCs by Creative Computing Magazine, and appeared in David Ahl's "Basic Computer Games, Personal Computer Edition" (I still have my autographed copy) in the late 1970s. Due to the limitations of the language, it was a nightmare of spaghetti code. Then, in 1996, a man named Chris Nystrom took that code, and ported it to Standard C. However, it was a very literal port (much like Mr. Birken's C# version): virtually all variables are global, maintaining their cryptic one or two letter names, and nearly all functions pass their parameters and return values using global variables. I liked the idea, but figured since we now had a powerful language to work with, we should use it to its full advantage. So, in 1997, I set out to write a fully object-oriented version. The goal was for it to have the same look & feel and game-play as the original, but with a modern OO design. Unfortunately, Visual C++ 5.0 was a bit lacking back then -- templates were a bit flakey, and the STL didn't work at all. I gave up after a day's work. A year later, now armed with the more stable Visual C++ 6.0, I put in all of three days work, before getting bored and abandoning it again. When the contest was announced, I remembered this long forgotten project, and to my surprise, I was able to find the code on one of the PCs on my home network (old computers never die, they are just repurposed). So, with 10 years more experience with OO design (if somewhat rusty C++ skills) and a C++ compiler that mostly works (Visual Studio 2008 comes with Microsoft C++ v15), I set out to finally complete the task. Using the CodeThere's nothing particularly notable about the code, unless you want to track how my views on Hungarian notation and instance member prefixes changed over the years. Or how my native C++ coding looks a lot like managed C# code with things like Interfaces and Properties. The key design principle is Separation of Concerns. The whole universe of the game is divided up into little objects, and they handle everything about their little piece of the world, and, with few exceptions, know nothing about anything outside of it. At the heart of this is an object called, naturally enough, Next we have the
Via the base class, each The Then, the derived classes handle the details of their own particular system. For example, the
Similarly, the Two other base classes are of interest:
Note: I've used pieces of the Boost Libraries (www.boost.org), so you'll need to have those installed to re-compile the source code. Boost is an extensive open-source library of C++ classes written by some of the best minds in the field. If you do any C++ coding, you should have it installed anyway. Command? srs
-----------------------
. . . . . . . . Stardate 2800
. . . . . . . . Condition GREEN
. . . . . . . . Quadrant (7, 8)
. . . . * . * . Sector (6, 7)
. . . * . . . . Photon Torpedos 10
. . . . . .
FutureAs with every project, along the way I placed where a major change would make a big improvement, but a deadline loomed, and I didn't want to do anything radical. But a major overhaul is needed. The first thing is that I realized too late the difference between a Quadrant & a Sector -- there isn't one -- so those two classes should be merged. That would make a large swath of code much simpler. I also decided that this really needs an event-driven design, so the quadrant would fire an event say an object moved within it, and that Klingons would listen to the quadrant, and know to fire back. Rather than the current design, where the Engines tell the However, .NET does have such a framework, built right into its core. I had first thought I couldn't port this easily to C#, because I had used multiple inheritance, but I now believe that would be easy to factor out. But, I put a lot of other work aside for the summer to work on this, so that project will have to wait for next summer. History
|
||||||||||||||||||||||||||||||||||||||||