Click here to Skip to main content
15,893,594 members
Articles / Desktop Programming / MFC

Adding high score capability to MS Solitaire

Rate me:
Please Sign up or sign in to vote.
4.70/5 (16 votes)
25 Jul 2007CPOL14 min read 44.1K   713   18  
An application that manages MS Solitaire high scores by reading and writing Solitaire memory
// Includes
#include "stdafx.h"
#include "HighscoreEntry.h"
#include <string>

////////////////////////////////////// Construction   /////////////////////////////////
CHighscoreEntry::CHighscoreEntry(long lScore, const CString& strName, long lTime) : m_lScore(lScore), m_strName(strName), m_dtTimeStamp(CTime::GetCurrentTime())
{
	if (lTime > 0)
	{
		m_dtTimeStamp = lTime;
	}
	else
	{
		 m_dtTimeStamp = CTime::GetCurrentTime();
	}
}

CHighscoreEntry::~CHighscoreEntry()
{
}

const CHighscoreEntry& CHighscoreEntry::operator=(const CHighscoreEntry& hse)
{
	(*this).m_lScore = hse.m_lScore;
	(*this).m_strName = hse.m_strName;
	(*this).m_dtTimeStamp = hse.m_dtTimeStamp;
	return (*this);
}

CHighscoreEntry::CHighscoreEntry(const CHighscoreEntry& hse)
{
	(*this) = hse;
}

////////////////////////////////////// Operators   /////////////////////////////////
bool CHighscoreEntry::operator==(const CHighscoreEntry& hse) const
{
	return ((*this).m_lScore == hse.m_lScore);
}

bool CHighscoreEntry::operator!=(const CHighscoreEntry& hse) const
{
	return !((*this) == hse);
}

bool CHighscoreEntry::operator<(const CHighscoreEntry& hse) const
{
	return ((*this).m_lScore < hse.m_lScore);
}

bool CHighscoreEntry::operator>(const CHighscoreEntry& hse) const
{
	// yes there's more than one way to do it
	// this is better for complex objects usually
	return !((*this) < hse || (*this) == hse);
}

bool CHighscoreEntry::operator>=(const CHighscoreEntry& hse) const
{
	return ((*this) > hse || (*this) == hse);
}

bool CHighscoreEntry::operator<=(const CHighscoreEntry& hse) const
{
	return ((*this) < hse || (*this) == hse);
}

// mainly for testing purposes
ostream& operator<<(ostream& os, const CHighscoreEntry& hse)
{
	char* name = new char[100];
	ConvertToChar(hse.m_strName, name);

	os << name << ' ' << hse.m_lScore << ' ' << hse.m_dtTimeStamp.GetDay() << '/' << hse.m_dtTimeStamp.GetMonth() << '/' << hse.m_dtTimeStamp.GetYear();
	delete name;
    return os;
}

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
Israel Israel
Software designer and programmer.
Programming languages:
MFC, C++, Java , C#, VB and sometimes C and assembly.

Comments and Discussions