Click here to Skip to main content
15,868,141 members
Articles / Programming Languages / Visual Basic

Star Trek for Windows

Rate me:
Please Sign up or sign in to vote.
3.62/5 (20 votes)
12 Feb 2009CPOL 73K   805   20   25
A conversion of the old Text Based Star Trek into Windows using VB.NET 2008 Express

I took an OLD Text Basic version and converted it into Visual Basic .NET 2008 Express.

Star-Trek-for-Windows

Introduction

Shows what can be done with attention to small details.

Background

I used to play Apple-][ Trek a lot back around 1978 or so for many many hours.

Using the Code

I took the code with line numbers and converted into a Visual Basic style code. Then I modified sections of code to simplify things as well as used variables and subroutine names that are self documenting.

Here's one of the comments at the top of the program explaining where the code came from originally:

VB.NET
' *2. Took the original source code found on a web site about 
'     Star Trek (Basic) and modified it to be Windows Based
'     version of the Text Based Star Trek. Took some inspiration
'     from the "Apple-][ Trek" program which I enjoyed a lot
'     back in the late 1970's and into early 1980's. Did this
'     project on my own time over a several weeks to get the
'     code up to the current version. Here a little, there a
'     little bit of time.
'
'     Here's the header comments from that code.
'     ---
'     - Extracted from HP tape image 16-Nov-2003 by Pete Turnbull
'     -
'     - HP BASIC PROGRAM LIBRARY
'     -
'     - STTR1: STAR TREK
'     -
'     - 36243 REV B -- 10/73
'     -
'     - CONTRIBUTED PROGRAM
'     - 
'     - STAR TREK: BY MIKE MAYFIELD, CENTERLINE ENGINEERING
'     -
'     - TOTAL INTERACTION GAME - ORIG. 20 OCT 1972
'     ---

Enjoy!

Points of Interest

There were many things that have been changed in the code. This is documented within the code.

There are many areas that can be improved if someone were to take the time to do so.

History / Additional Data

' * Designed the Form Layout using many concepts gained
'  from a lot of Apple-][ Trek and my desire to have
'  everything on one form without constantly having to
'  remap a console to work like the old Apple-][ Trek
'  did things.
'
' * Next customized the code by removing line numbers that
'  were not referenced anywhere else in the code. Then
'  modified the code to use subroutines to work properly
'  in Windows. Later changed the name of the subroutines to
'  tell what each routine does.
'
' * Customized some of the logic. Things like:
'
'  - Pseudo Random Number generator to ensure a different
'    starting layout each time the initialization logic is
'    run.
'    - This is accomplished by the logic using the current
'      date and time as the Pseudo Random Number generator
'      then randomly generating the initialization for the
'      game.
'
'  - Unrolled Array Data in the original program for Long
'    Range Scanner and Sector arrays.
'    - For Example, Unrolled the Data for the Sector Array
'      into ONLY 64 characters instead of using an 8 by 8
'      array which requires a lot more variable space to use.
'
'  - The ">" to the left of the Current Quadrant where the
'    Enterprise is on the Quadrant Map.
'
'  - Allowed Warping around the edge of the map. Such as
'    warping from Quadrant 2,7 at sector 1,4 in Warp
'    Direction of 4.5 at Warp Factor 3!
'
'  - Added Function Buttons that bring up a TabControl based
'    on certain functions for:
'    - Navigation
'    - Photon Torpedo
'    - Phaser Control
'    - Shields Control
'    *** Text Based Data for each tab added to each tab
'        which took away the need for complex list of text
'        needed to show the instructions.
'    *** When the TabControl is needed, it is shown. Then
'        after the function is done, then TabControl is
'        hidden.
'    *** TabControl gets moved from its' hidden location to
'        cover up the function buttons when it is needed
'        by using the upper left location of the hidden
'        control named OverlayLocation.
'
'  - Added Constant Values where needed to simplify changing
'    of Global Values instead of having to find each variable
'    inside of the code to change that value every place it
'    was setup in the original code.
'    - See:
'      Const BaseEnergy = 5000 
'      Const BasePhotons = 25
'      Const BaseShields = 1000
'      Const MaxStarDates = 30
'      Const StarBaseToken = "B" ' Star Base
'      Const EnterpriseToken = "E" ' Enterprise
'      Const StarSpotToken = "*" ' Star on the map
'      Const EmptySpotToken = " " ' Unoccupied space
'      Const KlingonToken = "K" ' Klingon Cruiser
'    - To match the original programs' values to:
'      Const BaseEnergy = 3000
'      Const BasePhotons = 10
'    - I added BaseShields value of 1000 to make sure that
'      each time the program runs or another game is chosen
'      or we dock with a Star Base that the Enterprise's
'      Shields will start at 1000 units of Energy.
'
'  - Added Sound Functionality with the ability to turn sound
'    on and off within the program.
'    - Plays the Wave Files as per the filenames listed inside
'      of this program. The Wave Files are used from the
'      location / directory where the executable program
'      exists. If the Wave File is not found, this program is
'      smart enough not to crash when the file is not there.
'      - See this logic:
'        ' Make Sound!
'        Dim SoundFile As String = _
'           System.AppDomain.CurrentDomain.BaseDirectory + _
'           "EnterpriseKilled.WAV"
'        If System.IO.File.Exists(SoundFile) Then
'           My.Computer.Audio.Play(SoundFile)
'        End If
'
'  - Damage Control Function was automated. So there is no
'    need to press a button to get a report.
'    - Added "Spock used a new repair technique!" like was
'      occasionally seen in Apple-][ Trek when a device was
'      repaired beyond 1 Star Date when moving.
'
'  - Short Range Scan for the Current Quadrant is shown in
'    the Long Range Scan even if the Long Range Scanner is
'    damaged.
'    - If Short Range Scanner is damaged, then ONLY up to 1
'      unit around the Enterprise is shown in the current
'      quadrant instead of being totally blind in the current
'      quadrant.
'
'  - Upon Docking with a Star Base, ALL damaged devices are
'    repaired and the Shields and Energy are reset to the
'    initial values.
'
'  - Displays the Current Date and Time in the lower right
'    corner of the interface.
'
'  - Displays Condition Status Text in Color.
'    - "Green" is displayed in Green.
'    - "Red" is displayed in Red.
'    - "Yellow" is displayed in Yellow.
'
' * There are many areas that the program could be enhanced.
'  Such as:
'
'  - Adding a Library Computer Function to automatically
'    target every Klingon in the current Quadrant then fire
'    Photon Torpedoes at them.
'
'  - Adding a Library Computer Function to calculate moving
'    from the current Sector in this Quadrant to another 
'    Sector in the current Quadrant.
'
'  - Adding a Library Computer Function to calculate the
'    Warp Factor and Warp Direction to move to another
'    Quadrant.
'    - For Example, Calculating the shortest distance from
'      Quadrant 2,7 to Quadrant 4,1.
'
'  - Allowing the Klingons to move like in Apple-][ Trek did
'    when Klingons were nearly destroyed but barely had
'    enough energy to escape to a connected Quadrant if said
'    Klingon was on the outer edge of the current Quadrant
'    BUT ONLY if the Klingon wouldn't cause the Quadrant it
'    wants to move into would not cause the number of
'    Klingons to go above 9!
'    - X or Y values of either 1 or 8.
'
'  - Allowing User Input for up to 200 Klingons with 1 Star
'    Base and 1 Star Base for Every 10 after that.
'    - Allow up to a Maximum Value of 9 Klingons per any
'      randomly chosen Quadrant.
'    * This was done on January 25, 2009 *
'
'  - Allowing up to 9 Klingons per Quadrant.
'    - Modified the Klingon Array to allow up to 9 but didn't
'      modify the code to generate up to 9 in a quadrant.
'      - See "KlingonSectorAndShieldsData" Array!
'
'  - Efficiency Rating needs to be reworked to a better
'    formula. I would suggest something like the way Apple-][
'    Trek did it!
'
'  - Star Date fine tuning to allow subwarp speeds to not
'    calculate as 1 full Star Date. (Warp Speeds under 1)
'
'  - Randomly place Enterprise if Warp Speed is 1 or more
'    and successfully warped.
'    - Currently places Enterprise at the same sector value
'      if Warp Factor is a whole number between 1 and 7.
'      - So if you started at Quadrant 1,2 at Sector 3,4
'        and you warped 2 at direction 1, the Enterprise
'        would end up at Quadrant 3,2 at Sector 3,4.
'
' * There are bugs that may still be in this program!
'   
'  For example: Saw this bug on November 15, 2008:
'
'  Firing a Photon Torpedo from this location that doesn't
'  destroy the star like the message log showed.
'  - FIXED this bug on January 5, 2009! See the note below!
'   
'  Current Quadrant Map displayed as follows for the 
'  "Sector (Short Range Sensor Scan)":
'  +-------------------+
'  |  1 2 3 4 5 6 7 8 |
'  | 1    *          |
'  | 2  *            |
'  | 3                |
'  | 4 K *            |
'  | 5      *        |
'  | 6            *  |
'  | 7            E  |
'  | 8                |
'  +-------------------+
' 
'  Used the "Compute Enemy Direction and Distance" button.
'
'  Fired Photon Torpedo at Direction of "4.5".
'
'  Message Log showed:
'  ---
'  - Direction = 4.5
'  - Distance = 6.70820393249937
'  -
'  - Photon Torpedo Track: (6,6) (6,5) (5,4) (5,3) (4,2)
'  - *** Star Destroyed ***
'  ---
'
'  IF the Photon Torpedo Track were accurate, Star at 5,4
'   should have been destroyed. Then if the SAME direction
'    of 4.5 would have been used then the Star at 4,2 should
'     have been destroyed.
'
'  *** Note *** FIXED on January 5, 2009 by ensuring that the
'               values for Z1 and Z2 are integers by using
'               the following logic:
'  ---
'  - Z1 = Int(S1 + 0.5) ' X location
'  - Z2 = Int(S2 + 0.5) ' Y location
'  - InsertIntoStringArrayForSector(InputData)
'  ---
'
'  * This adjusts the Photon Torpedo Track to:
'    (7,6) (6,5) (6,4) (5,3) (5,2) (4,1)
'
'  * This would mean that the Klingon at 4,1 is destroyed!
'
'  *** This points out why one should be very careful to
'      use integer values when integer values are expected!
'      - For Example, If we pass a double value of 7.99 to
'        an integer value, the program will drop the
'        fractional part (.99) which results in a value of 7
'        instead of 8!
'        - That is why I changed "Z1 = S1" to
'          "Z1 = Int(S1 + 0.5)" to make sure if the value of
'          S1 is almost 8 that 8 will be used for Z1!
' ---

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
BillNew - Software developer since November 1977.

Comments and Discussions

 
AnswerRe: My vote of 2 Pin
Destiny77713-Feb-09 6:58
Destiny77713-Feb-09 6:58 
GeneralA trip down Memory Lane... Pin
djlong13-Feb-09 2:37
djlong13-Feb-09 2:37 
GeneralRe: A trip down Memory Lane... Pin
Destiny77713-Feb-09 6:59
Destiny77713-Feb-09 6:59 
GeneralThanks! Pin
Shabubu13-Feb-09 1:20
Shabubu13-Feb-09 1:20 
GeneralRe: Thanks! Pin
Destiny77713-Feb-09 7:12
Destiny77713-Feb-09 7:12 
NewsContent Updated... Pin
Destiny77712-Feb-09 18:25
Destiny77712-Feb-09 18:25 
GeneralMy vote of 1 Pin
Dave Kreskowiak11-Feb-09 6:21
mveDave Kreskowiak11-Feb-09 6:21 
RantRe: My vote of 1 Pin
Destiny77712-Feb-09 17:48
Destiny77712-Feb-09 17:48 
GeneralRe: My vote of 1 Pin
Scott Dorman13-Feb-09 5:55
professionalScott Dorman13-Feb-09 5:55 
GeneralRe: My vote of 1 Pin
Destiny77713-Feb-09 7:15
Destiny77713-Feb-09 7:15 
GeneralNice Pin
Avery Moore2-Feb-09 16:58
Avery Moore2-Feb-09 16:58 
GeneralRe: Nice Pin
Destiny7774-Feb-09 6:49
Destiny7774-Feb-09 6:49 
GeneralMy vote of 2 Pin
AxelM1-Feb-09 20:51
AxelM1-Feb-09 20:51 
GeneralVery cool! Pin
BrianGoff1-Feb-09 14:50
professionalBrianGoff1-Feb-09 14:50 
GeneralRe: Very cool! Pin
Destiny7771-Feb-09 15:13
Destiny7771-Feb-09 15:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.