I took an OLD Text Basic version and converted it into Visual Basic .NET 2008 Express.
Shows what can be done with attention to small details.
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:
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
' - 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
' - 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
' *** 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 + _
' If System.IO.File.Exists(SoundFile) Then
' 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
' - 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
' - 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
' - 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!