<html>

<head><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>CFGReader</title>
</head>

<body>



<p align="left"><font size="6" color="#FF0000"><span lang="en-ca"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b></span>
<b>Console <span lang="en-ca">Player</span></b></font></p>

<div align="left">
  <pre><b><font color="#ff0000" size="5">A. <span lang="en-ca">Sixth </span>Edition</font></b></pre>
</div>
<div align="left">
  <pre><b>These classes are all base classes for console displays<span lang="en-ca"> and on this edition I finished a simple CPlayer and</span></b></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><b>a CBag</b></span><b><span lang="en-ca"> class </span></b><span lang="en-ca"><b>which has one card rack, one letter rack as its own component. </b></span></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">B</span>.<span lang="en-ca"><a name="problem"></a>The problem</span></font></b></pre>
</div>
<div align="left">
  <pre><b>How to display in console without using iostream class?</b></pre>
</div>
<div align="left">
  <b><font color="#ff0000" size="5"><span lang="en-ca"><a name="explain"></a>C</span>.<span lang="en-ca">The
  </span></font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>idea of 
  program</b></font></span></div>
<div align="left">
  　</div>
<div align="left">
  <pre><b>These classes are for our comp354 project which is going to make a little game like cross word.</b></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5">D.<span lang="en-ca"><a name="Method"></a>The </span>major functions</font></b></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">E</span>.</font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>Further improvement</b></font></span></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">F</span>.</font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>File listing</b></font></span></pre>
</div>
<div align="left">
  <pre><font size="3"><b>1<span lang="en-ca">. </span>tile<span lang="en-ca">.</span>h</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>2<span lang="en-ca">. </span>tile.cpp</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>3<span lang="en-ca">. </span>tiles.h</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>4. tiles.cpp</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>5. token.h</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>6. token.cpp</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>7. tokens.h</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>8. tokens.cpp</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>9. RoverType.h</b></font></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>10. board.h</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>11. board.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>12. cell.h</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>13. cell.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>14. block.h</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>15. block.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><font size="3"><b>16. rummy.h</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>17. rummy.cpp</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>18. dictionary.h</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>19. dictionary.cpp</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>20. listener.h</b></font></pre>
</div>
<div align="left">
  <pre><font size="3"><b>21. listener.cpp</b></font></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>22. rack.h</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>23. rack.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>24. background.h</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>25. background.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>26. deck.h</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>27. deck.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>28. player.h</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>29. player.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>30. bag.h</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>31. bag.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><font size="3"><b><span lang="en-ca">32</span>. <span lang="en-ca">main.cpp (main)</span></b></font></pre>
</div>
<p>　</p>
<p><span lang="en-ca"><font size="3" color="#FF0000"><b>file name: </span>tile<span lang="en-ca">.h</span></b></font></p>
<pre>#ifndef TILE_H
#define TILE_H

#include &quot;RoverType.h&quot;

class CTile
{
protected:
	char ch;
	WORD ftColor;
	WORD bkColor;
public:
	void display(int x, int y);
	void setFontColor(WORD theColor){ftColor=theColor;}
	void setBKGroundColor(WORD theColor){ bkColor=theColor;}
	void setValue(char myCh) { ch=myCh;}
	char getValue(){ return ch;}
	CTile(char myCh=DefaultCharacter);
};

#endif</pre>
<pre>　</pre>
<p><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>tile<span lang="en-ca">.</span></b></font><font color="#FF0000"><b>cpp</b></font></p>
<pre>#include &quot;Tile.h&quot;

HANDLE hOutPut=0;

CTile::CTile(char myCh)
{
	ftColor=DefaultFontColor;
	bkColor=DefaultBKGroundColor;
	setValue(myCh);
	if (hOutPut==0)
	{
		hOutPut=GetStdHandle(STD_OUTPUT_HANDLE);
	}
}

void CTile::display(int x, int y)
{
	COORD coord;
	coord.X=x;
	coord.Y=y;
	FillConsoleOutputAttribute(hOutPut, ftColor|bkColor, 1, coord, NULL);
	FillConsoleOutputCharacter(hOutPut, ch, 1, coord, NULL);
}

</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>tiles.h</b></font></pre>
<pre>#ifndef TILES_H
#define TILES_H

#include &quot;tile.h&quot;

class CTiles
{
private:
	CTile* tiles;
	int len;
	WORD ftColor;
	WORD bkColor;
	bool isVertical;
	void initialize();	
public:
	CTiles(const char* str);
	CTiles();
	virtual	~CTiles();
	void setDirection(bool beVertical){ isVertical=beVertical;}
	CTile&amp; operator[](int index){return tiles[index];}
	void setFontColor(WORD theColor){ftColor=theColor;}
	void setBKGroundColor(WORD theColor){bkColor=theColor;}
	int getLength(){return len;}
	void display(int x, int y);
	void setValue(const char* str);
	void setLength(int size);
	void setNumber(int num);
};

#endif</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>tiles.cpp</b></font></pre>
<pre>#include &quot;tiles.h&quot;

CTiles::CTiles()
{
	initialize();
}

void CTiles::initialize()
{
	len=0;
	tiles=NULL;
	isVertical=false;
	ftColor=DefaultFontColor;
	bkColor=DefaultBKGroundColor;
}

void CTiles::setNumber(int num)
{
	char buffer[10];
	itoa(num, buffer, 10);
	setValue(buffer);
}


CTiles::~CTiles()
{
	delete[]tiles;
}

void CTiles::setValue(const char* str)
{	
	//len=;
	setLength(strlen(str));
	for (int i=0; i&lt;len; i++)
	{
		tiles[i].setValue(str[i]);
	}
}

CTiles::CTiles(const char* str)
{
	initialize();
	setValue(str);
}


void CTiles::display(int x, int y)
{
	for (int i=0; i&lt;len; i++)
	{
		tiles[i].setFontColor(ftColor);
		tiles[i].setBKGroundColor(bkColor);
		if (!isVertical)
		{
			tiles[i].display(x+i, y);
		}
		else
		{
			tiles[i].display(x, y+i);
		}
	}
}

void CTiles::setLength(int size)
{
	if (len!=size)
	{
		len=size;
		delete[]tiles;
		tiles=new CTile[len] ;
	}
}</pre>
<pre>　</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>token.</b></font><span lang="en-ca"><font size="3" color="#FF0000"><b>h</b></font></span></pre>
<pre>#ifndef TOKEN_H
#define TOKEN_H

#include &quot;block.h&quot;


class CToken : public CBlock
{
protected:

public:	
	CToken(int num);
	CToken(char ch=DefaultCharacter);
	const CToken&amp; operator=(const CToken&amp; theToken);
	int getNumber();
	void setNumber(int num);	
	void setSuit(int theSuit);
	int getSuit();
};

class CCardBack: public CToken
{
public:
	CCardBack();
};

#endif</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>token.cpp</b></font></pre>
<pre>#include &quot;token.h&quot;
#include &quot;tile.h&quot;

const CToken&amp; CToken::operator =(const CToken&amp; theToken)
{	
	for (int i=0; i&lt;3; i++)
	{
		for (int j=0; j&lt;3; j++)
		{
			block[i][j].setValue(theToken.block[i][j].getValue());
		}
	}
	return *this;
}

void CToken::setSuit(int theSuit)
{
	block[0][0].setValue(theSuit);
	block[2][2].setValue(theSuit);
}

CToken::CToken(char ch):CBlock(3)
{
	block[1][1].setValue(ch);	
}

int CToken::getNumber()
{
	if (block[1][0].getValue()!=0)
	{
		return (block[1][0].getValue()-'0')*10+block[1][1].getValue()-'0';
	}
	if (block[1][1].getValue()&gt;'9')
	{
		switch(block[1][1].getValue())
		{
			case 'J': return 11;
			case 'Q': return 12;
			case 'K': return 13;
			case 'A': return 14;
		}
	}
	return block[1][1].getValue()-'0';
}

void CToken::setNumber(int num)
{
	//in no condition, this would happen
	if (num&gt;99)
	{
		return ;
	}
	if (num&gt;9)
	{
		block[1][0].setValue(num/10+'0');
		block[1][1].setValue(num%10+'0');
	}
	else
	{
		block[1][1].setValue(num+'0');
	}
}

CToken::CToken(int num)
{
	initialize();
	setNumber(num);
}

int CToken::getSuit()
{
	return block[0][0].getValue();
}

CCardBack::CCardBack()
{
	block[0][0].setValue(Club);
	block[0][2].setValue(Diamond);
	block[2][0].setValue(Heart);
	block[2][2].setValue(Spade);
	for (int i=0; i&lt;3; i++)
	{
		for (int j=0; j&lt;3; j++)
		{
			block[i][j].setBKGroundColor(DefaultCardBackBKGroundColor);
			block[i][j].setFontColor(DefaultCardBackFontColor);
		}
	}
}
</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>tokens.</b></font><span lang="en-ca"><font size="3" color="#FF0000"><b>h</b></font></span></pre>
<pre>#ifndef TOKENS_H
#define TOKENS_H

#include &quot;token.h&quot;


class CTokens
{
protected:
	CToken* tokens;
	int len;
	int pos;
	WORD ftColor;
	WORD bkColor;
	WORD frColor;
	bool isVertical;//default is false
	void initialize();	
	bool pushToken(const CToken&amp; token);
	bool popToken(CToken&amp; token);
public:
	CTokens(int theLen=DefaultTokenLength);
	CTokens(const char* str);
	CToken&amp; operator[](unsigned short index){ return tokens[index];}
	void setDirection(bool beVertical){isVertical=beVertical;}
	void setLength(int size);
	void setValue(const char* str);
	void setFontColor(WORD theColor);
	void setBKGroundColor(WORD theColor);
	void setFrameColor(WORD theColor);
	virtual ~CTokens();
	void display(int x, int y);
	//initialize the position of starting stack pos
	void setStackPos(int startPos=0){ pos=startPos;}
	void shuffle();
};

#endif</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>tokens.cpp</b></font></pre>
<pre>#include &quot;tokens.h&quot;

CTokens::CTokens(int theLen)
{
	initialize();
	setLength(theLen);
}

CTokens::CTokens(const char* str)
{
	initialize();
	setValue(str);
}

void CTokens::initialize()
{
	len=0;
	tokens=NULL;
	isVertical=false;
	ftColor=DefaultFontColor;
	bkColor=DefaultBKGroundColor;
	frColor=DefaultFrameColor;
}

void CTokens::setBKGroundColor(WORD theColor)
{
	for (int i=0; i&lt;len; i++)
	{
		tokens[i].setBKGroundColor(theColor);
	}
}

void CTokens::setFontColor(WORD theColor)
{
	for (int i=0; i&lt;len; i++)
	{
		tokens[i].setFontColor(theColor);
	}
}

void CTokens::setFrameColor(WORD theColor)
{
	for (int i=0; i&lt;len; i++)
	{
		tokens[i].setFrameColor(theColor);
	}
}

void CTokens::setLength(int size)
{
	if (len!=size)
	{
		delete []tokens;
		len=size;
		tokens=new CToken[len];
	}
}


void CTokens::setValue(const char* str)
{
	len=strlen(str);
	//tokens=new CToken[len];
	setLength(len);
	for (int i=0; i&lt;len; i++)
	{
		tokens[i].setValue(str[i]);
	}
}

void CTokens::display(int x, int y)
{
	for (int i=0; i&lt;len; i++)
	{
		if (!isVertical)
		{
			tokens[i].display(x+i*4, y);
		}
		else
		{
			tokens[i].display(x, y+i*4);
		}
	}
}

CTokens::~CTokens()
{
	delete [] tokens;	
}</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>RoverType.h</b></font></pre>
<pre>#include &lt;windows.h&gt;

/*****************************nick****************************/

extern HANDLE hOutPut;


//the font color
#define  FTBLUE        FOREGROUND_BLUE 
#define	 FTGREEN       FOREGROUND_GREEN 
#define	 FTRED         FOREGROUND_RED 
#define	 FTPURPLE      FOREGROUND_BLUE|FOREGROUND_RED
#define	 FTGREY        FOREGROUND_BLUE|FOREGROUND_GREEN
#define	 FTBROWN	   FOREGROUND_RED|FOREGROUND_GREEN
#define	 FTWHITE       FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED
#define	 FTINTENSITY   FOREGROUND_INTENSITY

//the background color
#define	 BKBLUE        BACKGROUND_BLUE 
#define  BKGREEN       BACKGROUND_GREEN 
#define	 BKRED         BACKGROUND_RED 
#define	 BKPURPLE      BACKGROUND_BLUE|BACKGROUND_RED
#define	 BKGREY        BACKGROUND_BLUE|BACKGROUND_GREEN
#define	 BKBROWN	   BACKGROUND_RED|BACKGROUND_GREEN
#define	 BKWHITE       BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED
#define	 BKINTENSITY   BACKGROUND_INTENSITY

#define DefaultFontColor           FTRED
#define DefaultBKGroundColor       BKWHITE
#define DefaultFrameColor          BKGREY
#define DefaultIndexFontColor      FTWHITE
#define DefaultIndexBKGroundColor  BKBLUE
#define DefaultIndexFrameColor     BKBLUE
#define DefaultHighLightFont	   FTINTENSITY


#define DefaultBoardSize		   15
#define MaxBoardSize			   20

#define DefaultCharacter           0
#define DefaultTokenLength         7
#define MinimumLengthOfWord		   2
#define MaxInputBufferLength	   20


#define DefaultScreenWidth        120
#define DefaultScreenHeight       60

#define LetterCount               26
#define MaxLengthOfWord			  20
#define DefaultInputPositionRow   30
#define DefaultInputPositionCol   30

//rack
#define DefaultSelectedBKGColor   BKINTENSITY
#define DefaultSelectedFontColor  FTBROWN

#define DefaultLetterRack_x             30
#define DefaultLetterRack_y             30
#define DefaultCardRack_x               30
#define DefaultCardRack_y               38


//card back color
#define DefaultCardBackBKGroundColor BKBROWN
#define DefaultCardBackFontColor     FTBLUE

//bag
#define BagTokenNumber    0
#define BagTokenPoints    1
#define DefaultNumberOfToken   100
#define DefaultBlankTokenValue  255

//coord of bag
#define DefaultBag_x      40
#define DefaultBag_y      40
/*
enum Suit
{Club=5, Diamond=4, Heart=3, Spade=6};
*/
#define Club           5
#define Diamond        4
#define Heart          3
#define Spade          6

/****************************nick*****************************/

</pre>
<pre></pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: board.h</span></b></font></pre>
<pre>#ifndef BOARD_H
#define BOARD_H

#include &quot;cell.h&quot;

class CBoard
{
private:
	int curRow, curCol;
	int headRow, headCol;
	bool isVer;
	bool isFirst;
	char buffer[MaxBoardSize];
	bool doFindStr();
	void setStartPoint();
	void getFirstStr();
	int findHead(int startRow, int startCol, bool isVertical);
protected:
	CCell** board;
	int boardWidth;
	void initialize(int size);
public:
	CBoard(int size=DefaultBoardSize);
	void setSize(int size);
	void display(int x, int y);
	char getValue(int r, int c);
	void setValue(int r, int c, char ch);
	void setValue(char** matrix);
	bool placeWord(int r, int c, const char* str, bool isVertical=false);
	void update(bool rollBack=false);
	char* getNextStr();
};

#endif</pre>
<pre>　</pre>
<pre>　</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: board.cpp</span></b></font></pre>
<pre>#include &quot;board.h&quot;

void CBoard::initialize(int size)
{
	boardWidth=0;
	board=NULL;
	isFirst=true;
	setSize(size);
	for (int i=0; i&lt;=size; i++)
	{
		for (int j=0; j&lt;=size; j++)
		{
			if (i==0||j==0)
			{
				board[i][j].setBKGAll(DefaultIndexFontColor, DefaultIndexBKGroundColor);
								
				if (i!=0)
				{
					board[i][j].setNumber(i-1, false);
				}
				if (j!=0)
				{
					board[i][j].setNumber(j-1, true);
				}
			}
		}
	}
}

void CBoard::setValue(char** matrix)
{
	for (int i=1; i&lt;=boardWidth; i++)
	{
		for (int j=1; j&lt;=boardWidth; j++)
		{
			board[i][j].setValue(matrix[i-1][j-1]);
		}
	}
}

void CBoard::setSize(int size)
{
	if (boardWidth!=size)
	{
		if (board!=NULL)
		{
			for (int i=0; i&lt;=boardWidth; i++)
			{
				delete []board[i];			
			}
		}
		delete[] board;
		boardWidth=size;
		board=new CCell*[size+1];
		for (int i=0; i&lt;=size; i++)
		{			
			board[i]=new CCell[size+1];
		}		
	}
}
		

CBoard::CBoard(int size)
{
	initialize(size);	
}

void CBoard::setValue(int r, int c, char ch)
{
	board[r+1][c+1].setValue(ch);
}

char CBoard::getValue(int r, int c)
{
	return board[r+1][c+1].getValue();
}

void CBoard::display(int x, int y)
{	
	for (int i=0; i&lt;=boardWidth; i++)
	{
		for (int j=0; j&lt;=boardWidth; j++)
		{
			board[i][j].display(x+2*j, y+i*2);
		}

	}
}

void CBoard::update(bool rollBack)
{
	int row=curRow, col=curCol;
	while (board[row][col].getValue()!=0)
	{
		if (rollBack)
		{
			if (!board[row][col].getStatus())
			{				
				board[row][col].setValue(DefaultCharacter);
			}
		}	
		board[row][col].setFontColor(DefaultFontColor);
		board[row][col].setStatus(true);
		if (isVer)
		{
			row++;
		}
		else
		{
			col++;
		}
		if (row&gt;boardWidth||col&gt;boardWidth)
		{
			break;
		}
	}
}

void CBoard::setStartPoint()
{
	headRow=curRow;
	headCol=curCol;
	if (isVer)
	{
		headRow=findHead(headRow, headCol, isVer);
	}
	else
	{
		headCol=findHead(headRow, headCol, isVer);
	}	
}



void CBoard::getFirstStr()
{
	int row=headRow, col=headCol, pos=0;
	while (board[row][col].getValue()!=0) 
	{
		buffer[pos]=board[row][col].getValue();
		pos++;
		if (isVer)
		{
			row++;
		}
		else
		{
			col++;
		}
		if (row==boardWidth||col==boardWidth)
		{
			break;
		}
	}
	buffer[pos]='\0';
}

char* CBoard::getNextStr()
{	
	if (isFirst)
	{
		setStartPoint();
		isFirst=false;
		getFirstStr();
		return buffer;//the original one will always return
	}
	if (doFindStr())
	{
		return buffer;
	}
	else
	{
		return NULL;
	}
}

bool CBoard::doFindStr()
{
	int row=headRow, col=headCol, pos=0;
	if (headRow&gt;boardWidth||headCol&gt;boardWidth)
	{
		return false;
	}
	if (board[row][col].getValue()==0)
	{
		return false;
	}
	if (isVer)
	{
		//skip the old word placed by others
		if (board[row][col].getStatus())
		{
			headRow++;
			return doFindStr();
		}
		col=findHead(row, col, !isVer);//the crossing direction
		do//the boardWidth is one more than the real size 
		{
			buffer[pos]=board[row][col].getValue();
			col++;
			pos++;
			if (col&gt;boardWidth)
			{
				break;
			}
		} while (board[row][col].getValue()!=0);
		buffer[pos]='\0';
		headRow++;
		if (pos&gt;MinimumLengthOfWord)
		{
			return true;
		}
		else
		{			
			return doFindStr();
		}
	}
	else
	{
		if (board[row][col].getStatus())
		{
			headCol++;
			return doFindStr();
		}
		row=findHead(row, col, !isVer);
		do
		{
			buffer[pos]=board[row][col].getValue();
			row++;
			pos++;
			if (row&gt;boardWidth)
			{
				break;
			}
		}while (board[row][col].getValue()!=0);
		buffer[pos]='\0';
		headCol++;
		if (pos&gt;MinimumLengthOfWord)
		{
			return true;
		}
		else
		{			
			return doFindStr();
		}
	}
}

//to do
int CBoard::findHead(int startRow, int startCol, bool isVertical)
{
	if (isVertical)
	{
		while (startRow&gt;0) //because the coord is starting from 1
		{
			if (board[startRow][startCol].getValue()==0)
			{
				break;
			}
			startRow--;
		}
		return startRow+1;
	}
	else
	{
		while (startCol&gt;0)
		{
			if (board[startRow][startCol].getValue()==0)
			{
				break;
			}
			startCol--;
		}
		return startCol+1;
	} 
}



bool CBoard::placeWord(int r, int c, const char* str, bool isVertical)
{
	int row=r+1, col=c+1, pos=0;
	curRow=row;
	curCol=col;
	isVer=isVertical;
	while (str[pos]!='\0')
	{
		if (board[row][col].getValue()==0)
		{
			board[row][col].setValue(str[pos]);
			board[row][col].setFontColor(DefaultHighLightFont);
			board[row][col].setStatus(false);
			pos++;
		}
		else
		{
			//the starting position cannot be occupied
			if (pos==0)
			{
				return false;
			}
		}
		if (isVertical)
		{
			row++;
		}
		else
		{
			col++;
		}
		if (row&gt;boardWidth||col&gt;boardWidth)//the bound is boardWidth
		{			
			return str[pos]=='\0';
		}
	}
	return true;
}


		

</pre>
<pre></pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: cell.h</span></b></font></pre>
<pre>#ifndef CELL_H
#define CELL_H

#include &quot;block.h&quot;

class CCell: public CBlock
{
protected:
	bool isOld;
public:
	CCell();
	void setStatus(bool beOld);
	bool getStatus();
	void setNumber(int num, bool atBottom);//special for index bar
	void setBKGAll(WORD theFont, WORD theBKG);
};

#endif</pre>
<pre>　</pre>
<pre>　</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: cell.cpp</span></b></font></pre>
<pre>#include &quot;cell.h&quot;

CCell::CCell():CBlock(1)
{
	isOld=true;
}

void CCell::setStatus(bool beOld)
{
	isOld=beOld;
}

bool CCell::getStatus()
{
	return isOld;
}

void CCell::setNumber(int num, bool atBottom)
{
	int y=0;
	if (atBottom)
	{
		y=1;
	}
	if (num&gt;9)
	{
		block[0][y].setValue(num/10+'0');
		block[1][y].setValue(num%10+'0');
	}
	else
	{
		block[0][y].setValue(num+'0');
	}
}

void CCell::setBKGAll(WORD theFont, WORD theBKG)
{
	for (int i=0; i&lt;2; i++)
	{
		for (int j=0; j&lt;2; j++)
		{
			block[i][j].setBKGroundColor(theBKG);
			block[i][j].setFontColor(theFont);
		}
	}
}</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: block.h</span></b></font></pre>
<pre>#ifndef BLOCK_H
#define BLOCK_H

#include &quot;tile.h&quot;

class CBlock
{
protected:
	CTile** block;
	int width;
	void initialize();
public:
	CBlock(int size=1);
	void setLength(int size);
	void setValue(char myCh);
	char getValue();
	void setFrameColor(WORD theColor);
	void setFontColor(WORD theColor);
	void setBKGroundColor(WORD theColor);
	void display(int x, int y);
};

#endif</pre>
<pre>　</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: block.cpp</span></b></font></pre>
<pre>#include &quot;block.h&quot;

CBlock::CBlock(int size)
{
	initialize();
	setLength(size);
}

void CBlock::initialize()
{
	block=NULL;
	width=0;
}

void CBlock::setLength(int size)
{
	width=size;
	block=new CTile*[size+1];
	for (int i=0; i&lt;=size; i++)
	{
		block[i]=new CTile[size+1];
		for (int j=0; j&lt;=size; j++)
		{
			if (i==size||j==size)
			{
				block[i][j].setBKGroundColor(DefaultFrameColor);
			}
		}
	}
}

void CBlock::setValue(char myCh)
{
	block[(width-1)/2][(width-1)/2].setValue(myCh);
}

void CBlock::setBKGroundColor(WORD theColor)
{
	for (int i=0; i&lt;width; i++)
	{
		for (int j=0; j&lt;width; j++)
		{
			block[i][j].setBKGroundColor(theColor);
		}
	}
}

void CBlock::setFontColor(WORD theColor)
{
	for (int i=0; i&lt;width; i++)
	{
		for (int j=0; j&lt;width; j++)
		{
			block[i][j].setFontColor(theColor);
		}
	}
}

void CBlock::setFrameColor(WORD theColor)
{
	for (int i=0; i&lt;=width; i++)
	{
		for (int j=0; j&lt;=width; j++)
		{
			if (i==width||j==width)
			{
				block[i][j].setBKGroundColor(theColor);
			}
		}
	}
}

char CBlock::getValue()
{
	return block[(width-1)/2][(width-1)/2].getValue();
}

void CBlock::display(int x, int y)
{
	for (int i=0; i&lt;=width; i++)
	{
		for (int j=0; j&lt;=width; j++)
		{
			block[i][j].display(x+j, y+i);
		}
	}
}</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>rummy<span lang="en-ca">.h</span></b></font></pre>
<pre>#ifndef RUMMY_H
#define RUMMY_H

#include &quot;token.h&quot;

class CRummy
{
private:
	int array[7];
	int pos;
	void addOne(CToken* tokens, int index);
public:
	bool verify(CToken* tokens, int len);
	CRummy();
};

#endif</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>rummy<span lang="en-ca">.</span>cpp</b></font></pre>
<pre>#include &quot;rummy.h&quot;

bool CRummy::verify(CToken* tokens, int len)
{
	bool sameSuit=true, isSequence=true, isGroup=true;
	int theSuit, theBase, theNext;
	for (int i=0; i&lt;len; i++)
	{
		addOne(tokens, i);
	}
	theSuit=tokens[array[0]].getSuit();
	theBase=tokens[array[0]].getNumber();
	for (i=1; i&lt;len; i++)
	{
		if (tokens[array[i]].getSuit()!=theSuit)
		{
			sameSuit=false;
		}
		theNext=tokens[array[i]].getNumber();
		if (theNext-theBase!=0)
		{
			isGroup=false;
		}
		if (theNext-theBase!=-1)
		{
			isSequence=false;
		}
		theBase=theNext;
	}
	return sameSuit||isSequence||isGroup;
}
	

CRummy::CRummy()
{
	pos=0;
}

void CRummy::addOne(CToken* tokens, int index)
{
	int i=0;
	if (pos==0)
	{
		array[0]=index;
		pos++;
		return;
	}
	//insertion sorting	
	while (i&lt;pos)
	{
		if (tokens[index].getNumber()&gt;tokens[array[i]].getNumber())
		{
			break;
		}
		i++;	
	}
	
	for (int j=pos; j&gt;i; j--)
	{
		array[j]=array[j-1];
	}
	array[i]=index;
	pos++;
}</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>dictionary<span lang="en-ca">.</span>h</b></font></pre>
<pre>#include &quot;RoverType.h&quot;


struct Letter
{
	char ch;
	Letter* next;
	Letter* son;
	bool end;
};

class Dictionary
{
private:
	Letter* root[52];
	Letter* current;
	Letter* findBrother(Letter* brother, char ch);
	Letter* createLetter(char ch);
	Letter* addSon(char ch);
	int indexOf(char ch);
	bool caseSensitive;
	void change2Capital(char* target, char* source);
public:
	bool addWord(char* str);
	bool findWord(char* str);
	void readFile(const char* fileName);
	void setCaseSensitive(bool isCaseSensitive);
	Dictionary(bool isCaseSensitive=true);
};

</pre>
  <pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: </span>dictionary</b><span lang="en-ca"><b>.</b></span><b>cpp</b></font></pre>
<pre>#include &lt;stdio.h&gt;
#include &quot;dictionary.h&quot;

void Dictionary::change2Capital(char* target, char* source)
{
	char* tgt=target, *src=source;
	do
	{
		*tgt=toupper(*src);
		tgt++;
		src++;
	}while (*src!='\0');
	*tgt='\0';
}

void Dictionary::readFile(const char* fileName)
{
	char buffer[MaxLengthOfWord];
	char*ptr=buffer;
	char ch;
	FILE* stream;
	stream=fopen(fileName, &quot;r&quot;);
	while (!feof(stream))
	{
		ch=fgetc(stream);
		if (isalnum(ch))
		{
			if (!caseSensitive)
			{
				*ptr=toupper(ch);
			}
			else
			{
				*ptr=ch;
			}
			ptr++;
		}
		else
		{
			*ptr='\0';
			if (ptr!=buffer)
			{
				addWord(buffer);
				ptr=buffer;
			}
			//else remain the same ptr.
		}
	}
}


bool Dictionary::findWord(char* str)
{
	char* ptr=str;
	char buffer[MaxLengthOfWord];
	if (!caseSensitive)
	{		
		ptr=buffer;
		change2Capital(buffer, str);
	}
	Letter* hold;
	int index;
	//not empty string
	if (ptr!=NULL)
	{
		index = indexOf(*ptr);
		if (index==-1)
		{
			return false;
		}
		current=root[index];		
		ptr++;

		if (current-&gt;son==NULL)
		{
			//if string is a one-letter string
			if (*ptr=='\0')
			{
				//and there is a one-letter word in dictionary
				return current-&gt;end;
			}
			else
			{
				return false;
			}
		}
		hold=current;//
		current=current-&gt;son;
		
		while (*ptr!='\0')
		{				
			current=findBrother(current, *ptr);
			if (current==NULL)
			{
				return false;
			}
			if (current-&gt;ch==*ptr)
			{
				hold=current;
				current=current-&gt;son;
			}
			else
			{
				//not found
				return false;
			}
			ptr++;
		} 
		return hold-&gt;end;
	}
	//in my dictionary there is no empty string word
	return false;
}
	

Letter* Dictionary::createLetter(char ch)
{
	Letter* ptr=new Letter;
	ptr-&gt;ch=ch;
	ptr-&gt;end=false;
	ptr-&gt;next=NULL;
	ptr-&gt;son=NULL;
	return ptr;
}

//ch is not '\0'
Letter* Dictionary::findBrother(Letter* brother, char ch)
{
	Letter* hold=brother;
	if (brother==NULL)
	{
		return NULL;
	}
	while (hold-&gt;next!=NULL)
	{
		if (hold-&gt;ch==ch)
		{
			break;
		}
		hold=hold-&gt;next;
	}
	return hold;
}

Letter* Dictionary::addSon(char ch)
{
	//the word ends
	if (ch=='\0')
	{
		current-&gt;end=true;		
	}
	else
	{
		//need a new son
		if (current-&gt;son==NULL)
		{
			current-&gt;son=createLetter(ch);
			current=current-&gt;son;
		}
		else
		{
			//current-&gt;son is not NULL!!!
			current=findBrother(current-&gt;son, ch);
			//check if the current is the node
			if (current-&gt;ch!=ch)
			{
				current-&gt;next=createLetter(ch);	
				current=current-&gt;next;//add brother
			}	
			//else return current;!!!
		}
	}
	return current;
}


//add word actually add letter by letter till NULL, nonsense!
bool Dictionary::addWord(char* str)
{
	char* ptr=str;
	int index;
	if (*ptr!='\0')
	{
		index=indexOf(*ptr);
		if (index==-1)
		{
			return false;
		}
		current=root[index];		
		do
		{
			ptr++;
			current=addSon(*ptr);			
		} while (*ptr!='\0');
		return true;
	}
	return false;
}

Dictionary::Dictionary(bool isCaseSensitive)
{
	caseSensitive=isCaseSensitive;

	for (int i=0; i&lt;LetterCount; i++)
	{
		root[i]=new Letter;
		root[i]-&gt;ch='A'+i;
		root[i]-&gt;next=NULL;
		root[i]-&gt;son=NULL;
	}
	if (caseSensitive)
	{
		for (i=0; i&lt;LetterCount; i++)
		{
			root[i+LetterCount]=new Letter;
			root[i+LetterCount]-&gt;ch='a'+i;
			root[i+LetterCount]-&gt;next=NULL;
			root[i+LetterCount]-&gt;son=NULL;
		}
	}
}

int Dictionary::indexOf(char ch)
{
	if (ch-'A'&gt;=0&amp;&amp;ch-'Z'&lt;=0)
	{
		return ch-'A';
	}
	if (ch-'a'&gt;=0&amp;&amp;ch-'z'&lt;=0)
	{
		return ch-'a'+LetterCount;
	}
	return -1;
}


</pre>
  <pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: </span>listener.h</b></font></pre>
<pre>#include &quot;RoverType.h&quot;

class CListener
{
protected:
	static HANDLE hOut;
	static char buffer[MaxInputBufferLength];
	void initialize();
public:
	CListener();
	int listenMenu();
	char* listenStr();//must ended by entering return
};

</pre>
  <pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: </span>listener.cpp</b></font></pre>
<pre>#include &quot;listener.h&quot;

HANDLE CListener::hOut=NULL;
char CListener::buffer[MaxInputBufferLength];

CListener::CListener()
{
	initialize();
}

void CListener::initialize()
{
	hOut=GetStdHandle(STD_INPUT_HANDLE);
	
}

int CListener::listenMenu()
{
	DWORD temp;
	SetConsoleMode(hOut, 0);
	ReadConsole(hOut, buffer, 1, &amp;temp, NULL);
	return buffer[0]-'0';
}

char* CListener::listenStr()
{
	DWORD temp;
	SetConsoleMode(hOut, ENABLE_LINE_INPUT);
	ReadConsole(hOut, buffer, MaxInputBufferLength, &amp;temp, NULL);
	buffer[temp-1]='\0';
	return buffer;
}
</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: background.h</span></b></font></pre>
<pre>//background
#ifndef BACKGROUND_H
#define BACKGROUND_H

#include &quot;RoverType.h&quot;

class CBackGround
{
private:
	int width, height;
	int row, col;
	WORD ftColor;
	WORD bkColor;
public:
	CBackGround(int theRow=0, int theCol=0);
};

#endif</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: background</span></b><span lang="en-ca"><b>.</b></span><b>cpp</b></font></pre>
<pre>#include &quot;background.h&quot;



CBackGround::CBackGround(int theRow, int theCol)
{
	char ch=0;
	COORD coord;
	bkColor=BKGREEN;
	ftColor=FTWHITE;
	width=DefaultScreenWidth;
	height=DefaultScreenHeight;
	row=theRow;
	col=theCol;
	if (hOutPut==0)
	{
		hOutPut=GetStdHandle(STD_OUTPUT_HANDLE);
	}
	//SetConsoleTextAttribute(hOutPut, bkColor|ftColor);
	for (int r=row; r&lt;height; r++)
	{
		for (int c=col; c&lt;width; c++)
		{	
			coord.X=c;
			coord.Y=r;
			FillConsoleOutputAttribute(hOutPut, ftColor|bkColor, 1, coord, NULL);
			FillConsoleOutputCharacter(hOutPut, ch, 1, coord, NULL);
		}
	}
	SetConsoleTitle(&quot;WordRover&quot;);
	CONSOLE_CURSOR_INFO cursorInfo;
	cursorInfo.bVisible=false;
	cursorInfo.dwSize=50;
	SetConsoleCursorInfo(hOutPut, &amp;cursorInfo);
	coord.X = DefaultInputPositionCol;
	coord.Y =DefaultInputPositionRow;
	SetConsoleCursorPosition(hOutPut, coord);

}

</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: rack</span></b><span lang="en-ca"><b>.h</b></span></font></pre>
<pre>#ifndef CRACK_H
#define CRACK_H
#include &quot;tokens.h&quot;
#include &quot;rummy.h&quot;

class CRack: public CTokens
{
protected:
	char buffer[9];
	CToken cardBuf[7];
	char exchanged;	
	static CRummy rummy;
	CToken empty;
    int selected[7];
	int selectedCount;
	int x,y;
public:
	int exchangedIndex;
	CRack();
	bool selectToken(int index, bool isLetter=true);//success return true
	void addToken(const CToken&amp; token);
	//void showRack(int x,int y);
	void addExchanged(char exch);
	void updateRack(bool rollBack=false);
	bool canAdd() { return selectedCount&gt;0;}
	const char* exportWord();
	bool verifyCards();
	void setCoord(int theX, int theY){ x=theX; y=theY;}
	void removeToken(int index, CToken&amp; result);
	void showRack();
};

#endif</pre>
<pre>　</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: rack</span></b><span lang="en-ca"><b>.</b></span><b>cpp</b></font></pre>
<pre>#include &quot;rack.h&quot;


CRummy CRack::rummy;

CRack::CRack():CTokens(7)
{
	selectedCount=7;//means empty at beginning
	for (int i=0; i&lt;7; i++)
	{
		selected[i]=i;
	}
	exchangedIndex=-1;//means no exchanged!!!
	x=y=0;
}


bool CRack::selectToken(int index, bool isLetter)
{
	if (selectedCount==7)
	{
		return false;
	}
	for (int i=0; i&lt;selectedCount; i++)
	{
		if (index==selected[i])
		{
			return false;//means repeat selecting
		}
	}
	selected[selectedCount]=index;
	if (isLetter)
	{
		buffer[selectedCount]=tokens[index].getValue();	
	}
	else
	{
		cardBuf[selectedCount]=tokens[index];
	}
	tokens[index].setBKGroundColor(DefaultSelectedBKGColor);	
	tokens[index].setFontColor(DefaultSelectedFontColor);
	selectedCount++;
	showRack();
	return true;
}

bool CRack::verifyCards()
{
	if (selectedCount==0)
	{
		return false;
	}
	return rummy.verify(cardBuf, selectedCount);
}

void CRack::addToken(const CToken&amp; newToken)
{
	if (selectedCount&gt;0)
	{
		tokens[selected[--selectedCount]]=newToken;
	}
}


void CRack::addExchanged(char ch)
{
	exchanged=ch;
	exchangedIndex=selectedCount;
}


void CRack::showRack()
{
	display(x,y);
}


void CRack::removeToken(int index, CToken&amp; result)
{
	result=tokens[index];
	tokens[index]=empty;
}

const char* CRack::exportWord()
{
	//insert the exchanged letter
	if (exchangedIndex!=-1)
	{
		for (int i=selectedCount; i&gt;exchangedIndex; i--)
		{
			buffer[i]=buffer[i-1];
		}
		buffer[exchangedIndex]=exchanged; //insert the char
		buffer[selectedCount+1]='\0';
	}
	else
	{
		buffer[selectedCount]='\0';
	}
	return buffer;
}

void CRack::updateRack(bool rollBack)
{
	if(rollBack)
	{
		for(int i=0; i&lt;selectedCount;i++)
		{
			tokens[selected[i]].setBKGroundColor(DefaultBKGroundColor);
			tokens[selected[i]].setFontColor(DefaultFontColor);			
		}
		selectedCount=0;
		exchangedIndex=-1;
	}
	else
	{
		for(int i=0; i&lt;selectedCount;i++)
		{
			tokens[selected[i]]=empty;			
		}        
		exchangedIndex=-1;//should I do at this moment?
	}
}
</pre>
<pre>
</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: deck</span></b><span lang="en-ca"><b>.h</b></span></font></pre>
<pre>#ifndef DECK_H
#define DECK_H	

#include &quot;tokens.h&quot;

class CDeck: public CTokens
{
protected:
	CCardBack deckBack;
	bool faceDown;
public:
	CDeck(bool isEmpty=false);
	void showHand();
    int  numOfCards();
	bool addCard(const CToken&amp; card);
	bool removeCard(CToken&amp; token);	
	void setFace(bool faceDown=true);
	void display(int x, int y);
};

#endif
</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: deck</span></b><span lang="en-ca"><b>.</b></span></font><span lang="en-ca"><font size="3" color="#FF0000"><b>cpp</b></font></span></pre>
<pre>#include &quot;deck.h&quot;

char cardValue[12]={'2','3','4','5','6','7','8','9','J','Q','K','A'};
int suitValue[4]={Club, Diamond, Heart, Spade};

CDeck::CDeck(bool isEmpty):CTokens(52)
{   
	//do initialize
	faceDown=true;
	for(int i=0;i&lt;4;i++)
	{		
		for(int j=0;j&lt;13; j++)
		{
			if (j==12)
			{
				tokens[i*13+j].setNumber(10);
			}
			else
			{
				tokens[i*13+j].setValue(cardValue[j]);
			}
			tokens[i*13+j].setSuit(suitValue[i]);
		}
	} 
	if (isEmpty)
	{
		pos=0;	
	}
	else
	{
		pos=len;
	}	
}

void CDeck::showHand()
{
	for (int i=0; i&lt;4; i++)
	{
		for (int j=0; j&lt;13; j++)
		{
			tokens[i*13+j].display(j*4, i*4);
		}
	}
}

bool CDeck::addCard(const CToken&amp; card)
{
	return pushToken(card);
}

bool CDeck::removeCard(CToken&amp; card)
{
	return popToken(card);
}

void CDeck::setFace(bool isFaceDown)
{
	faceDown=isFaceDown;
}

void CDeck::display(int x, int y)
{
	if (faceDown||pos==0)
	{
		deckBack.display(x, y);
	}
	else
	{
		tokens[pos-1].display(x, y);
	}
}


<font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: </span></b><span lang="en-ca"><b>player.h</b></span></font></pre>
<pre>#ifndef CPLAYER_H
#define CPLAYER_H

#include &quot;rovertype.h&quot;
#include &quot;rack.h&quot;

//to do:
//I need charles's CScoreBoard to put an instance inside Player
//so that all set, get method is implemented by CScoreBoard
class CPlayer
{
private:
	char* name;
	CRack rackLetter;
	CRack rackCard;
	int currentScore;
	int totalScore;
	int index;
public:
	CPlayer();
	~CPlayer();
	void setName(const char* theName);
	const char* getName();
	int getCurrentScore();
	void setCurrentScore(int score);
	int getTotalScore();
	void setTotalScore(int score);
	int getIndex(void);
	void setIndex(int theIndex);
	bool selectCard(int index);
	bool selectLetter(int index);
	void addCard(const CToken &amp; newCard );
	void addLetter(const CToken&amp; newLetter);
	const char* exportWord();
	bool verifyCards();
	void display();
	void discardCard(int index, CToken&amp; result);
	void discardLetter(int index, CToken&amp; result);
	bool canAddCard();
	bool canAddLetter();
};

#endif</pre>
<pre>　</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: player</span></b><span lang="en-ca"><b>.</b></span><b>cpp</b></font></pre>
<pre>#include &quot;player.h&quot;


CPlayer::CPlayer()
{
	name=NULL;
	index=-1;
	rackLetter.setCoord(DefaultLetterRack_x, DefaultLetterRack_y);
	rackCard.setCoord(DefaultCardRack_x, DefaultCardRack_y);
	display();
}

void CPlayer::display()
{
	rackLetter.showRack();
	rackCard.showRack();
	//to do:
	//here to call scoreboard set current player method
}

void CPlayer::discardCard(int index, CToken&amp; result)
{
	rackCard.removeToken(index, result);
}

void CPlayer::discardLetter(int index, CToken&amp; result)
{
	rackLetter.removeToken(index, result);
}


CPlayer::~CPlayer()
{
	if (name!=NULL)
	{
		delete[]name;
	}
}

void CPlayer::setName(const char* theName)
{
	if (name!=NULL)
	{
		delete[]name;
	}
	name=new char[strlen(theName)+1];
	strcpy(name, theName);
}


const char* CPlayer::getName()
{
	return name;
}

void CPlayer::setCurrentScore(int score)
{
	currentScore=score;
}

int CPlayer::getCurrentScore()
{
	return currentScore;
}

void CPlayer::setTotalScore(int score)
{
	totalScore=score;
}

int CPlayer::getTotalScore()
{
	return totalScore;
}

int CPlayer::getIndex()
{
	return index;
}

bool CPlayer::selectCard(int index)
{
	return rackCard.selectToken(index);
}

bool CPlayer::selectLetter(int index)
{
	return rackLetter.selectToken(index);
}

void CPlayer::addCard(const CToken&amp; newToken)
{
	rackCard.addToken(newToken);
}
  
void CPlayer::addLetter(const CToken&amp; newToken)
{
	rackLetter.addToken(newToken);
}

const char* CPlayer::exportWord()
{
	return rackLetter.exportWord();
}
  
bool CPlayer::verifyCards()
{
	return rackCard.verifyCards();
}

bool CPlayer::canAddCard()
{
	return rackCard.canAdd();
}

bool CPlayer::canAddLetter()
{
	return rackLetter.canAdd();
}



</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: bag</span></b><span lang="en-ca"><b>.h</b></span></font></pre>
<pre>#ifndef BAG_H
#define BAG_H

#include &quot;RoverType.h&quot;
#include &quot;tokens.h&quot;

class CBag: public CTokens
{
private:
	static int tokenData[27][2];
	int tokenLeft;
	CToken bag;
public:
	CBag();
	int getTokenPoint(char ch);
	int getBlankNumber();
	void setBlankNumber(int newNum);	
	int getTokenNumber(char ch);
	void setTokenPoint(char ch, int newPoint);
	void setTokenNumber(char ch, int newNumber);	
	bool getToken(CToken&amp; result);
	void showBag();//only show the number of left tokens
};

#endif
</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: bag</span></b><span lang="en-ca"><b>.</b></span><b>cpp</b></font>



</pre>
<pre>#include &quot;bag.h&quot;

/*
 2 &quot;blank&quot; tiles (scoring 0 points), 9 As (1 point), 2 Bs (3), 2 Cs (3), 4 Ds (2), 
 12 Es (1), 2 Fs (4), 3 Gs (2), 2 Hs (4), 9 Is (1), 1 J (8), 1 K (5), 4 Ls (1), 
 2 Ms (3), 6 Ns (1), 8 Os (1), 2 Ps (3), 1 Q (10), 6 Rs (1), 4 Ss (1), 6 Ts (1),
 4 Us (1), 2 Vs (4), 2 Ws (4), 1 X (8), 2 Ys (4), and 1 Z (10).

  */

int CBag::tokenData[27][2]=
{
	{9,  1}, // As (1 point),
	{2,  3},// Bs (3),
	{2,  3},// Cs (3), 
	{4,  2},// Ds (2), 
	{12, 1},//Es (1),
	{2,  4},// Fs (4),
	{3,  2},//Gs (2), 
	{2,  4},//Hs (4),
	{9,  1},// Is (1), 
	{1,  8},// J (8), 
	{1,  5},// K (5), 
	{4,  1},// Ls (1),
	{2,  3},// Ms (3),
	{6,  1},//Ns (1), 
	{8,  1},// Os (1),
	{2,  3},// Ps (3), 
	{1,  10},// Q (10),
	{6,  1},// Rs (1),
	{4,  1},// Ss (1), 
	{6,  1},// Ts (1),
	{4,  1},// Us (1),
	{2,  4},// Vs (4),
	{2,  4},// Ws (4),
	{1,  8},// X (8),
	{2,  4},// Ys (4), and 
	{1,  10},// Z (10).
	{2,   0}//blank token valued 255
};


bool CBag::getToken(CToken&amp; result)
{
	if (tokenLeft==0)
	{
		return false;
	}
	result=tokens[--tokenLeft];
	return true;
}

CBag::CBag():CTokens(DefaultNumberOfToken)
{
	bag.setNumber(DefaultNumberOfToken);
	tokenLeft=DefaultNumberOfToken;
	int index=0;
	for (int i=0; i&lt;27; i++)
	{
		int j=0;
		while (j&lt;tokenData[i][BagTokenNumber])
		{
			if (i!=26)
			{
				tokens[index].setValue(i+'A');
			}
			else
			{
				tokens[index].setValue((char)DefaultBlankTokenValue);
			}
			j++;//always
			index++;
		}
	}
	shuffle();
}

void CBag::showBag()
{
	bag.setNumber(tokenLeft);
	bag.display(DefaultBag_x, DefaultBag_y);
}

int CBag::getTokenNumber(char ch)
{
	return tokenData[ch-'A'][BagTokenNumber];
}

int CBag::getBlankNumber()
{
	return tokenData[26][BagTokenNumber];
}

void CBag::setBlankNumber(int newNum)
{
	tokenLeft+= newNum-tokenData[26][BagTokenNumber];
}

void CBag::setTokenNumber(char ch, int newNum)
{
	tokenLeft+=newNum-tokenData[ch-'A'][BagTokenNumber];
	tokenData[ch-'A'][BagTokenNumber]=newNum;
}

void CBag::setTokenPoint(char ch, int newPoint)
{
	tokenData[ch-'A'][BagTokenPoints]=newPoint;
}

int CBag::getTokenPoint(char ch)
{
	return tokenData[ch-'A'][BagTokenPoints];
}





</pre>
<div align="left">
  <pre><font size="3" color="#FF0000"><b>f<span lang="en-ca">ile name: </span></b></font><font size="3" color="#FF0000"><b><span lang="en-ca">main</span></b></font><font size="3" color="#FF0000"><span lang="en-ca"><b>.</b></span><b>cpp(main)</b></font></pre>
</div>
<pre>#include &quot;tokens.h&quot;
#include &quot;tiles.h&quot;
#include &quot;board.h&quot;
#include &quot;block.h&quot;
#include &quot;listener.h&quot;
#include &quot;rummy.h&quot;
#include &quot;dictionary.h&quot;
#include &quot;background.h&quot;
#include &quot;deck.h&quot;
#include &quot;rack.h&quot;
#include &quot;bag.h&quot;
#include &quot;player.h&quot;


//#include &lt;iostream&gt;
//using namespace std;


int  main()
{
//	const int Size=14;
	CBackGround CB;
/*
	char** matrix;
	
	matrix=new char*[Size];
	for (int i=0; i&lt;Size; i++)
	{
		matrix[i]=new char[Size];
		for (int j=0; j&lt;Size; j++)
		{
			matrix[i][j]='A'+i+j;
		}
	}
	
	CBoard C(Size);
	//normally display a string
	C.placeWord(5, 4, &quot;first&quot;);
	C.update();//with updates, change color to normal
	//C.display(1,1);
	//try to place a string which will exceed bounds
	C.placeWord(6, 5, &quot;invisable&quot;);
	C.update();
	//update with &quot;roll back&quot; and erase it
	//C.update(true);
	//so you see nothing of this new string
	//C.display(1,1);
	//place a third string for comparison and vertically
	C.placeWord(2, 7, &quot;vertical&quot;, true);
	C.update();
	//C.update();
	C.placeWord(7, 5, &quot;newstring&quot;);
	C.update();
	C.placeWord(8, 3, &quot;third&quot;);
	C.update();
	C.placeWord(9, 6, &quot;fourth&quot;);
	//so you will see 1st, 3rd string
	C.display(1,1);

	CTiles D;
	char* ptr;
	int i=0;
	while ((ptr=C.getNextStr())!=NULL)
	{
		D.setValue(ptr);
		D.display(18, 37+i);
		i++;
	}
*/
	//CListener C;
	//CToken T;
	//T.setNumber(C.listenMenu());
	//T.display(10, 10);

	//CTokens tokens;//(C.listenStr());
	//tokens.setValue(C.listenStr());
	//tokens.display(1, 15);
	/*
	const int len=3;
	CTiles ok(&quot;ok&quot;);
	CToken tokens[len];
	/*
	for (int i=0; i&lt;len; i++)
	{
		tokens[i].setNumber((i+1)*2);
		tokens[i].setSuit(
	}

	tokens[0].setNumber(7);
	tokens[0].setSuit(Spade);
	tokens[1].setNumber(7);
	tokens[1].setSuit(Heart);
	tokens[2].setNumber(7);
	tokens[2].setSuit(Diamond);
	CRummy R;
	if (R.verify(tokens, 3))
	{
		ok.display(1,1);
	}

	for (int i=0; i&lt;len; i++)
	{
		tokens[i].display(i*4+3, 5);
	}
		*/
	char buffer[15]={'a','B', 'c', 'g','x', 'u','o','\0'};
	//CTiles C(&quot;ok&quot;);
	//Dictionary D(false);
	//D.readFile(&quot;wordsource.txt&quot;);
	//CDeck deck;
	//deck.setFace();
	//deck.display(5, 5);
	/*
	for (int i=0; i&lt;4; i++)
	{
		CToken token;
		token.setValue(buffer[i]);
		deck.addCard(token);
	}
	//deck.setFace(false);
	
	//deck.
	
	//deck.display(15,15);
	CToken card;
	card.setValue('B');
	//card.display(23, 23);
	deck.shuffle();
	deck.showHand();
	*/
	/*
	CRack C;
	CToken token;
	int i=0;
	while (C.canAdd())
	{
		token.setValue(buffer[i]);

		C.AddToken(token);
		i++;
	}
	C.showRack();

	C.SelectToken(3);
	C.SelectToken(5);
	C.addExchanged('A');
	C.SelectToken(0);
	C.SelectToken(5);
	CTiles t(C.exportSelected());
	t.display(10,10);
	//C.updateRack();
	C.showRack();

	t.setNumber(C.exchangedIndex);
	t.display(5,5);
	*/
	//CBag C;
	//CToken hold;
	
	//C.display(0,0);
	//C.showBag();
	/*
	int x=0, y=0;
	CToken token;

	while (C.getToken(token))
	{
		x+=6;
		if (x&gt;100)
		{
			x=0;
			y+=6;
		}
		//hold.setValue(token.setValue())
		//hold.display(2,2);
		token.display(x,y);
		if (x&gt;15)
			break;
		
	}
	C.showBag();
*/
	CPlayer P;
	CListener C;
	P.display();
	CToken t;
	int i=Heart;
	while (P.canAddCard())
	{
		t.setSuit(i%4+Heart);
		t.setNumber(i+1);
		P.addCard(t);
		i=C.listenMenu();
	}
	while (P.canAddLetter())
	{
		t.setValue(i+'B');
		P.addLetter(t);
		i=C.listenMenu();
	}


	return 0;


}

</pre>
<pre>

</pre>
<pre></pre>
<pre></pre>
<pre></pre>
<pre></pre>
<pre></pre>
<pre><font color="#0000FF"><b><span lang="en-ca">The input is something like following:</span></b></font></pre>
<pre><font color="#0000FF"><b>Here is the <a name="result"></a><a name="result" href="picture/Console.JPG">result:</a></b></font></pre>

<p>　</p>

<pre></pre>

<pre></pre>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                   
&nbsp;&nbsp;&nbsp; <a href="WhoAmI.htm">                  







                       <img src="picture/back.gif" style="border: medium none" alt="back.gif (341 bytes)" width="32" height="35"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<a href="index.htm">
<img src="picture/up.gif" style="border: medium none" alt="up.gif (335 bytes)" width="35" height="32"></a>       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                         
<img src="picture/next.gif" style="border: medium none" alt="next.gif (337 bytes)" width="32" height="35">          


</p>

</body>

</html>