<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 display <span lang="en-ca">board</span></b></font></p>

<div align="left">
  <pre><b><font color="#ff0000" size="5">A. <span lang="en-ca">Second</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 board class</span>.</b></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>10. <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();
	~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);
};

#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;
}

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++)
	{
		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><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);
};

#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()
{
	return (block[1][0].getValue()-'0')*10+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);
}
</pre>
<pre>
</pre>
<pre>　</pre>
<pre><font size="3" color="#FF0000"><b><span lang="en-ca">file name: </span>tokens.h</b></font></pre>
<pre>#ifndef TOKENS_H
#define TOKENS_H

#include &quot;token.h&quot;


class CTokens
{
protected:
	CToken* tokens;
	int len;
	WORD ftColor;
	WORD bkColor;
	WORD frColor;
	bool isVertical;//default is false
	void initialize();
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);
	~CTokens();
	void display(int x, int y);
};

#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>　</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;


//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 DefaultBoardSize		   15

#define DefaultCharacter           0
#define DefaultTokenLength         7
/*
enum Suit
{Club=5, Diamond=4, Heart=3, Spade=6};
*/
#define Club           5
#define Diamond        4
#define Heart          3
#define Spade          6</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:
	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);
};

#endif</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)
{
	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];
		}		
	}
}
		

/*	
	column.setBKGroundColor(DefaultIndexBKGroundColor);
	column.setFontColor(DefaultIndexFontColor);
	row.setBKGroundColor(DefaultIndexBKGroundColor);
	row.setFontColor(DefaultIndexFontColor);
	*/

CBoard::CBoard(int size)
{
	boardWidth=0;
	board=NULL;
	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);
		}

	}
}

		

</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
{
public:
	CCell();
	void setNumber(int num, bool atBottom);//special for index bar
	void setBKGAll(WORD theFont, WORD theBKG);
};

#endif</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)
{
}

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>　</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+i, y+j);
		}
	}
}</pre>
<pre>　</pre>
<pre>　</pre>
<pre></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;


int  main()
{
	const int Size=14;
	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);
	C.setValue(matrix);
	C.display(1,1);
	return 0;

}

</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>