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

Star Trek Game Conversion Project

By David Bolton, About.com

5 of 8

How to use Arrays (and How Not to!)

There was only one array called @ in the Basic code. I think that was all that Tiny Basic supported. In my novice programming days I once crammed lots of different types of data into arrays but it is a truly apalling technique, very difficult to debug and maintain.

Part of this array holds Sectors (8 x 8), Quadrants (8,x8) and ship damage so I created separate arrays and structs for those. As Basic arrays usually start at 1, but C start at 0, I made the arrays one extra- eg an 8 x 8 array was 9 x 9 so elements 1-8 can be indexed without changing any code. Normally in C, an 8 x 8 array is indexed from 0 to 7.

It's easy to criticise the writer of this game but it was 30 years ago and 8 KB is not a lot of code in which to create a game as well as hold the Basic interpreter, so the programmer had to work within very tight constraints. Hopefully we've moved on from these practices!

On the next page What each variable does.

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. How to Use of Array (and How Not to!)

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

All rights reserved.