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

Star Trek Game Conversion Project

By David Bolton, About.com

4 of 8

Notes about the Original code

Line Numbers

Line numbers remained until the third pass. GOS. 175 is a function call to line 175 that prints the Enterprise's location. As the main functions and code flow were identified, unnecesary line numbers were removed. I left the Gosub line numbers in as comments, in case I missed one.

Use of variables

In Tiny Basic all variables are global and there is no concept of local variables. This simplifies understanding but makes it easy to introduce bugs.

Initially I thought I'd leave all variables.in and use them as they were. However, changing them to more meaningful names made a lot more sense and vastly increased the readability.

Lines 120 and 125 use S, G, L, P, R, W and T variables to hold the line number of the subroutines that do the main commands. That's what the Goto A in line 125 does! The if in that line is just a clever switch statement. Inside an if statement a + is more like ||, and a * is like an &&.

This is quite clever- what do you think it (line 20) does?

20 M=R.(Y),M=(M<209)+(M<99)+(M<49)+(M<24)+(M<9)+(M<2)
The first assignment to M is a random number between 1 and Y. The 2nd assignment to M (after the comma) sets it to 0 to 5 depending on the value of M. If M is 209 or higher then all these tests fail and the value assigned is 0. If M was 16 then it is less than 209, less than 99 and less than 49 so it has a value of 3. Each test that passes adds 1 to M.

On the next page Learn about converting arrays

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. Notes about the Original code

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

All rights reserved.