Disfunctional Function Declaration

Pages: 12
an old BASIC Star Trek game I played back in public school on computer terminals,


Which system - not HP 2000F/Access TSB? That had quite a good Star Trek game that I played at school when no teachers etc were looking...
Last edited on
Another good book about Clean Code is "Clean C++" by Stephan Roth.


Yes :) I have the C++17 version. There's now a C++20 version out.

https://www.amazon.co.uk/Clean-20-Sustainable-Development-Practices-dp-1484259483/dp/1484259483/ref=dp_ob_title_bk

Also Design Patterns in Modern C++ which is an update to the standard GoF book (again I have the C++17 version)

https://www.amazon.co.uk/Design-Patterns-Modern-Approaches-Object-Oriented-dp-1484272943/dp/1484272943/ref=dp_ob_title_bk
Possibly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <cstring>

void boxtotalmath(int& GBox, int& RBox, int& BBox) {
	BBox += GBox / 1'000;
	GBox %= 1'000;
	RBox += BBox / 100'000;
	BBox %= 100'000;
}

int main() {
	int GBox {};
	int BBox {};
	int RBox {};

	bool gameExit {};

	while (!gameExit) {
		static constexpr char valid[] {"aidx"};
		char resp {};

		boxtotalmath(GBox, RBox, BBox);

		std::cout << "Green Box Value: " << GBox << "\nBlue Box Value: " << BBox << "\nRed Box Value: " << RBox;
		std::cout << "\n\n(a)dd 1\n" << "(i)ncrease by 750\n" << "(d)rop in 750,000\n" << "e(x)it\n";
		std::cout << "Response : ";

		std::cin >> resp;
		std::cout << "\n\n";

		if (std::strchr(valid, resp)) {
			GBox += resp == 'a' || resp == 'A';
			GBox += (resp == 'i' || resp == 'I') * 750;
			GBox += (resp == 'd' || resp == 'D') * 750'000;
			gameExit = resp == 'x' || resp == 'X';
		} else
			std::cout << "Authorized responses are a, i, d or x!\n";
	}
} 

The terminals were old paper print-out, paper-tape data storage terminals tied to the school district's mainframe.

Exactly what brand/specifications, I haven't a clue. They were 1960's/1970's technology, after all. I was more interested in using the terminals to program and play games.

The version of Star Trek available on the terminals wasn't what is now called Super Star Trek. It was a more crude BASIC version. I used to have the BASIC source until a couple of years ago.

The closest I've found online to what I remember the source code as being is this 1971/72 version:
https://www.codeproject.com/articles/28228/star-trek-1971-text-game

That source could be what I had, I just don't remember.

Looking closer at that source it is not what I remember. Each entity in the map was represented by a single character. E for the Enterprise, K for Klingons, etc.
Last edited on
I might not know Java, but I can look at some Java code and kinda get the gist without understanding all of what its doing.

That's the good thing about Java, it's easy to read.
The principles of clean code are language agnostic so it doesn't matter what language the examples are. There's no code to copy and paste.
Re star-trek. That codeproject reference is for the HP Basic version that I used to play - sorry use. The original source is at http://www.decodesystems.com/hp2000/sttr1.bas

There is a HP TSB simulator at http://simh.trailing-edge.com/hp/
You want the 2000F TSB kit and if interested, the later 2000 Access TSB kit.
There's also links to sites that have the manuals.

This can be used to emulate a HP TSB system - complete with operator's console and multiple user consoles. I have a working system, complete with a working original star-trek program!

As you know, TSB had a library (account A000) accessible from every account (where sttr1 etc was located). A copy of the programs/files in this account that can be loaded from the operator terminal is at http://www.bitsavers.org/bits/HP/tapes/2000tsb/ These are 2000 Access programs so some won't work with the 2000F simulator but require the 2000 Access simulator. You want the 2000dump5

Other files in that directory contain other TSB files for other accounts.

Have fun!

PS simh also have simulators for various DEC computers - complete with various OS kits to use. I have a working RSTS/E emulation. There's also TOPS-10 and TOPs-20 OS kits.
Last edited on
My interest and desire in recreating in C++ the Star Trek game I remember is to be able to change how commands were entered, for one. For instance, "PHA 500" (for phasers) from a single prompt instead of having to enter the "PHA" command and then getting a "how much energy?" prompt. Of course if someone entered just "PHA" the energy prompt would appear.

I modified the BASIC source on the school mainframe to use gradians instead of degrees, and the 0 direction was "dead ahead" (due "North") instead of off to the right. I'd like to replicate that, something easy-peasy math-wise.

Another mod is to have stars and starbases and Klingons stay in the same location initially placed at random. The game as originally programmed when leaving a sector and returning the object locations were redone at random.

M'ok, so the Klingons might actually move around a bit when they detect a Federation enemy near-by. More design work brain squashing.

And instead of a short range scan being squarish showing everything in a sector even if the Enterprise is near a side or corner. Center the scan and be able to "see" across sector boundaries. More design work.

I've been too lazy to do more than just plan ideas, currently mashing my brain over doing the input that reads an entire line, parses the data into tokens and then read each token in turn to figure out if it is a valid token for any given input. "PHA 500" would be valid, "PHA SRS" (short range scan) would be invalid for the amount of energy so the stored token would be "dumped", a prompt would be displayed and the input parser would be waiting for a numeric value out of a new input line that would be parsed into tokens...

I got the idea from how Dungeon/Zork did its command parser. "DROP LAMP" for instance worked if you were carrying the lamp.
Then your version of star trek wasn't the HP TSB version. That version used a menu of options (3 was to fire phasers) and course was by direction (1 - 8) instead of angles. It was probably the later Super Star Trek which used commands. This Basic version was published in The Best Of Creative Computing Vol 1 1976 (together with the source for that other famous game - Hunt The Wumpus!). Another version was published in Basic Computer Games (1978). I have original printed copies of both of these.

Good luck with writing your updated version of Star Trek.

PS You may be interested in this book. It covers practical design and implementation of a case study around a calculator - both for command line and QT - in C++20.

https://www.amazon.co.uk/Practical-C-Design-Programming-Architecture/dp/1484274067/ref=sr_1_4 (second edition - first edition was for C++17).

PPS. Looking at the old Basic code (derived from Dartmouth Basic), just shows how 'bad' programming was back then - max 2 char variable names, global variables, 'spaghetti' code etc. And to think that I used to program like that when I first learnt programming (50+ years ago) and thought it was great! Ah, the fun old days...
Last edited on
The version of Star Trek was in my hazy memory rather crude in how input was done and displaying information. Fun long before there were video games arcades. Nostalgia across 45+ years sure plays a part.

One of the reasons why I want to make an updated C++ version.

BASIC was kinda designed to be a bad programming paradigm, but a lot of people learned programming that way back in the 1960s/1970's. I was one of them.

I had a Radio Shack TRS-80 desktop computer, with a BASIC game of Taipan. Sailing ship trading and piracy in 18th century China Sea area. Ooooh, fancy-dancy with two(!) floppy disk drives!

https://www.cbtnuggets.com/blog/wp-content/uploads/2012/03/trs80.jpg

I remember MS had their own version of BASIC that got sideways mutated into Visual Basic. *UGH!*
the dos basic was fairly clean from what I recall. I learned a lot tearing apart the 'gorilla' game (tank wars/ scorched earth type game 2 monkeys threw bananas at each other with angle and speed ) and there was another one that was kinda like tron (cycles) or something.

VB became what was in part because it was morphed to allow plugins to office, I think. My memory is hazy too but it seems like they added basic to office which needed some rudimentary gui elements and that led to VB. VB wasn't bad for what it was -- anyone with half a brain could code up a simple windows program with it, which was really nice. And visual or not, basic got a lot of us where we are today. I am the odd one .. didn't get a computer until later on, and learned to program on a HP calculator.
Don't forget that Microsoft came into being on the back of Bill's Basic interpreter for the original Altair (1974/1975). MS Basic eventually became the 'de-facto' micro-computer Basic and was found on many home computers of the day. It was only after IBM failed to do a deal with Digital Research for an OS for their new PC that Microsoft got involved with operating systems - by buying one from Seattle Computer Products, modifying it and then licencing it to IBM. The rest they say is history.
[@lare26 - sorry for the thread hijack]

@George - are you going to update the game to also include black alert/spore drive (Discovery) and time travel (original Tomorrow is Yesterday and the film The Voyage Home)? What about also having Romulans and The Borg?


[Moved making a game chatter here]:
http://www.cplusplus.com/forum/lounge/282391/
Topic archived. No new replies allowed.
Pages: 12