当前位置: 首页>>代码示例>>C++>>正文


C++ Number::setIsOnes方法代码示例

本文整理汇总了C++中Number::setIsOnes方法的典型用法代码示例。如果您正苦于以下问题:C++ Number::setIsOnes方法的具体用法?C++ Number::setIsOnes怎么用?C++ Number::setIsOnes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Number的用法示例。


在下文中一共展示了Number::setIsOnes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createNumber

//===================================
//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
					//+++++++++++++++++++++
				}
			}
//.........这里部分代码省略.........
开发者ID:dror1988,项目名称:MathGame_EX2,代码行数:101,代码来源:screenMatrix.cpp


注:本文中的Number::setIsOnes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。