Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / C

Another Star Trek Game (The Retro One)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (14 votes)
27 Aug 2008CPOL6 min read 54.5K   2.2K   32  
The Star Trek game reworked, using a 2D retro look
#pragma once

#include "StarCoordinate.h"

class KlingonShip;
class StarBase;

class Sector
{
public:
	class Info
	{
	public:
		Info()
		{
			initData(NULL);
		}

    Info(const Info& rInfo)
    {
      m_iStars      = rInfo.m_iStars;
      m_iKlingons   = rInfo.m_iKlingons;
      m_iStarBases  = rInfo.m_iStarBases;
    }

    Info& operator=(const Info& rInfo)
    {
      m_iStars      = rInfo.m_iStars;
      m_iKlingons   = rInfo.m_iKlingons;
      m_iStarBases  = rInfo.m_iStarBases;

      return *this;
    }

		void initData(Sector* pSector = NULL)
		{
			if(!pSector)
			{
				m_iStars = -1;
				m_iKlingons = -1;
				m_iStarBases = -1;
			}
			else
			{
				m_iStars = pSector->getStars().size();
				m_iKlingons = pSector->getNumberofKlingons();
				m_iStarBases = pSector->getStarBase() ? 1: 0;
			}
		}

		bool isOuterSpace()
		{
			return m_iStars == -1;
		}

		stringw toString()
		{
			if (isOuterSpace())
			{
				return L"...";
			}

			stringw strData;
			
			strData += m_iStarBases;
			strData += m_iKlingons;
			strData += m_iStars;

			return strData;
		}

	protected:
		int m_iStars;
		int m_iKlingons;
		int m_iStarBases;
	};

public:
	Sector(void);
	~Sector(void);

	void seedStars();

	void addStarBase();
  void addKlingonShip();
  bool isCoordinateUsed(StarCoordinate& coCheck);

	void enterSector(StarCoordinate* pEnterprise);
	void leaveSector();

	int getNumberofKlingons();

  bool                          isStarAt(StarCoordinate& coCheck);
  StarBase*                     getStarBaseAt(StarCoordinate& coCheck);
  KlingonShip*									getKlingonAt(StarCoordinate& coCheck);
	KlingonShip*									getFirstKlingon();


	std::vector<StarCoordinate>&	getStars();
	std::vector<KlingonShip*>&		getKlingons();
	StarBase*											getStarBase();

protected:
	std::vector<StarCoordinate>		m_vecStars;
  std::vector<KlingonShip*>			m_vecKlingon;
  StarBase*											m_pStarBase;
};

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)
Belgium Belgium
I'm from Belgium, happily (should my wife ever read this) married and have two boys.

After a first attempt on the Atari during college in
an old foreign dialect of basic, via Pascal I am now
developing mostly in VC++ / VB / C#.

Comments and Discussions