Click here to Skip to main content
15,886,802 members
Articles / Programming Languages / C++

The Object-Oriented Text Star Trek Game in C++

Rate me:
Please Sign up or sign in to vote.
4.74/5 (10 votes)
6 Aug 2008CPOL6 min read 42.4K   816   34  
The Classic Super Star Trek Game rewritten in modern Object-oriented C++
/* ---------------------------------------------------------
Super Star Trek
C++ Port Copyright 2008, James M. Curran    <jamescurran@mvps.org>
based upon the C Port, Copyright 1996, Chris Nystrom
based upon the PC Basic port, Copyright 1978, Workman Publishing
based upon the HP Basic original, PD circa 1971, Mike Mayfield

C++ code licensed using the Code Project Open License v1.02
http://www.codeproject.com/info/cpol10.aspx
 -------------------------------------------------------------- */
#if !defined (OUTPUT_F_FILE_INCLUDED)
#define OUTPUT_F_FILE_INCLUDED

#include <iostream>
#include <ios>
#include <streambuf>

using std::cout;
using std::endl;
using std::ostream;
using std::cin;

#include <string>
using std::string;

struct IDisplayable
{
		virtual void DisplayOn(ostream&) const =0;
};


inline ostream& operator<< (ostream& os, const IDisplayable& Q)
{
	Q.DisplayOn(os);
	return os;
}

inline string center(const string text, int width)
{
	int len = text.length();
	if (len >= width)
		return text;

	int front = (width - len)/2;
	int back = front;
	if ((len & 1) == 1)
		++front;

	return string(front, ' ') + text + string(back, ' ');
}

inline void AnyKey()
{
	cout << "\n====Press [Enter] to continue ====";
		char c[2];
	cin.sync();
	cin.read(c, 1);
	cout << endl;
}


// NullDevice functions exactly like cout (and can be used in it's place)
// except text output through it isn't displayed anywhere.
// Good for the "other times" when sometimes you want something 
// displayed, and other time, you don't.
class NullDevice : virtual public   ostream 
{
public:
	NullDevice() : ostream(NULL, false) {}
};

extern NullDevice nulldev;

#endif	//defined (OUTPUT_F_FILE_INCLUDED)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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) NovelTheory LLC
United States United States
20+ years as a developer : Assembly, C, C++ and C# (in that order) with sidelines in ASP/VBScript, ASP.Net, JavaScript, Perl, QuickBasic, VisualBasic, plus a few others which I'm not going to mention because if I did someone might ask me to use them again (shudder)

Microsoft MVP in VC++ (1994-2004)

I also run www.NJTheater.com as a hobby.

Full resume & stuff at NovelTheory.com

Underused blog at HonestIllusion.com

Comments and Discussions