bool operator <(const Number&nl,const Number&nr)
{
    return nl.getNum()<nr.getNum();
}
コード例 #2
0
//===================================
//Create new Number in case that all 
//conditions are fulfilled
//===================================
void screenMatrix::createNumber(int currentLevel){
	int triesCounter = 0;
	bool isSuccess = false;
	int num;

	if (currentLevel<=11)
		num = rand() % (10 + currentLevel) + 1;
	else
		num = rand() % 21 + 1;
		
	if (num < 10)
	{
		while (isSuccess == false && triesCounter < 10)
		{
			Point numPosition;
			if (numPosition.x != p1.getPosition().x && numPosition.y != p1.getPosition().y
				&& numPosition.x != p2.getPosition().x && numPosition.y != p2.getPosition().y
				&& matrix[numPosition.y][numPosition.x] == NULL
				&& matrix[numPosition.y + 1][numPosition.x] == NULL && matrix[numPosition.y][numPosition.x + 1] == NULL
				&& matrix[numPosition.y - 1][numPosition.x] == NULL && matrix[numPosition.y][numPosition.x - 1] == NULL)
			{
				Number *newOne = new Number;
				newOne->setIsOnes(false);
				newOne->setIsTens(false);
				newOne->setNum(num);
				newOne->setNumberPosition(numPosition);

				matrix[numPosition.y][numPosition.x]=newOne;
				isSuccess = true;

				if (isSuccess==true){
					gotoxy(numPosition.x,numPosition.y);
					cout<<newOne->getNum();
					// +++++++++++++++++++++++++++++++++++++++++++++++++
					// "NEW CODE EX3, author=Dror Moyal, date=2015-06-02
					// +++++++++++++++++++++++++++++++++++++++++++++++++
					numList.insertToTail(newOne);
					nodeMatrix[numPosition.y][numPosition.x] = numList.getTail();
					//+++++++++++++++++++++
					// END of NEW CODE EX3
					//+++++++++++++++++++++
				}
			}
			else
				++triesCounter;
		}
	}
	else if (num >= 10)
	{
		while (isSuccess == false && triesCounter < 10)
		{
			Point tensPosition;
			Point onesPosition(tensPosition.x + 1, tensPosition.y);
			if ((tensPosition.x != p1.getPosition().x && tensPosition.y != p1.getPosition().y 
				&& tensPosition.x != p2.getPosition().x && tensPosition.y != p2.getPosition().y 
				&& matrix[tensPosition.y][tensPosition.x] == NULL
				&& matrix[tensPosition.y + 1][tensPosition.x] == NULL && matrix[tensPosition.y][tensPosition.x + 1] == NULL
				&& matrix[tensPosition.y - 1][tensPosition.x] == NULL && matrix[tensPosition.y][tensPosition.x - 1] == NULL)
				&& 
					(onesPosition.x != p1.getPosition().x && onesPosition.y != p1.getPosition().y
				&& onesPosition.x != p2.getPosition().x && onesPosition.y != p2.getPosition().y
				&& matrix[onesPosition.y][onesPosition.x] == NULL
				&& matrix[onesPosition.y + 1][onesPosition.x] == NULL && matrix[onesPosition.y][onesPosition.x + 1] == NULL
				&& matrix[onesPosition.y - 1][onesPosition.x] == NULL && matrix[onesPosition.y][onesPosition.x - 1] == NULL)
				&& onesPosition.x <= onesPosition.maxX)
			{
				Number *newTens = new Number;
				Number *newOnes = new Number;
				newTens->setIsTens(true);
				newTens->setIsOnes(false);
				newTens->setNum(num/10);
				newTens->setNumberPosition(tensPosition);
				newOnes->setIsOnes(true);
				newOnes->setIsTens(false);
				newOnes->setNum(num % 10);
				newOnes->setNumberPosition(onesPosition);

				matrix[tensPosition.y][tensPosition.x]=newTens;
				matrix[tensPosition.y][tensPosition.x+1]=newOnes;
				isSuccess = true;

				if (isSuccess==true){
					gotoxy(tensPosition.x,tensPosition.y);
					cout<<newTens->getNum()<<newOnes->getNum();
					// +++++++++++++++++++++++++++++++++++++++++++++++++
					// "NEW CODE EX3, author=Dror Moyal, date=2015-06-02
					// +++++++++++++++++++++++++++++++++++++++++++++++++
					numList.insertToTail(newTens);
					nodeMatrix[tensPosition.y][tensPosition.x] = numList.getTail();
					numList.insertToTail(newOnes);
					nodeMatrix[tensPosition.y][tensPosition.x+1] = numList.getTail();
					//+++++++++++++++++++++
					// END of NEW CODE EX3
					//+++++++++++++++++++++
				}
			}
			else
				++triesCounter;

		}
	}
}
bool operator ==(const Number&nl,const Number&ar)
{
    return nl.getNum();
}