1. Home
  2. Computing & Technology
  3. C / C++ / C#

Star Trek Game Conversion Project

By David Bolton, About.com

7 of 8

Game Architecture Changes

The Basic game was a typical spaghettish application with many Gosubs (function calls) and Gotos throughout. I have a preference for having the main function last so I moved it there. Refactoring is essential with this.

I changed the array into multiple structures so Quadrants and Klingons were stored as structs and Sectors was just an array of ints.

I moved the main function to the end of the file. The game is effectively two nested do while loops. The outer loop runs a complete game, while the inner loop shows the Enterprise location, processes commands from the player and after a Warp move, phasers fired or photon torpedo launch, checks to see if the Enterprise has moved near a starbase and does attacks from any Klingons in the same quadrant.

I tried to stay faithful to the original Basic source as much as possible but clearly 100% accuracy was not an option!

The complicated expressions are great for compact code but a real pain to maintain and debug.

Player Input

All input from the player is done by a call to gets a library function in <stdio.h>. This reads characters (until enter is pressed) into a character array. Note these have fixed limits so if you type in long strings you will crash the application! Feel free to improve on this. Nowadays it's not considered safe to use gets().

On the next page : Notes about particular sections of code.

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. Projects
  5. Star Trek Conversion
  6. Game Architecture Changes

©2009 About.com, a part of The New York Times Company.

All rights reserved.