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


C++ Coords::setCoords方法代码示例

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


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

示例1: mapGen

void mapGen(int** checkWall, int** checkVisited, int X, int Y)
{
	int x = 0, y = 1, tolerance = 0; //x and y are the starting coordinates of the path through the maze
	int sum = 0;
	Coords temp;
	temp.setCoords(1, 0);
	stack<Coords> coordinates;
	coordinates.push(temp);


	while (!coordinates.empty()) { //continues the loop until the stack is emptied
								   //////////////////////////////////////////////////
		cout << "size of stack:   " << coordinates.size() << endl;
		mapgen << "size of stack:  " << coordinates.size() << endl;
		/////////////////////////////////////////////////
		int* possible = checkAvail(coordinates.top(), checkVisited, X, Y, tolerance); //ptr to the array of size 4 that contains the four directions' validity
		sum = 0;
		for (int i = 0; i < 4; i++)
		{
			sum += possible[i]; //sets sum to the total number of choices
		}
		////////////////////////////////////
		Coords test = coordinates.top();
		int testX = test.getX();
		int testY = test.getY();
		mapgen << "options: " << sum << "     coords: " << testX << "      " << testY << endl;
		///////////////////////////////////////

		if (sum == 0) { //executes if there are no choices at the current location (dead end)
			coordinates.pop(); //pops the top layer off the stack
			tolerance = 1; //allows checkAvail to evaluate to true even if the location has been visited once before (allows the making of intersections
						   /////////////////////////////////////////
			mapgen << "pop" << endl;
						   /////////////////////////////////////////
			continue; //back up to beginning of the while loop
		}
		tolerance = 0; //for checkAvail on the next run through the loop
		temp = coordinates.top(); //local variables for the x- and y-coordinates of the current location
		x = temp.getX();
		y = temp.getY();
		int Picked = pickDir(possible);
		//////////////////////////
		mapgen << "direction:" << Picked << endl;
		/////////////////////////
		if (x > 0)							//updates checkVisited now that we've moved
			checkVisited[x - 1][y] ++;		//
		if (x < X - 2)						//
			checkVisited[x + 1][y] ++;		//
		if (y > 0)							//
			checkVisited[x][y - 1] ++;		//
		if (y < Y - 2)						//
			checkVisited[x][y + 1] ++;		//

		switch (Picked)			//moves us to the next location
		{						//
		case 0: { //up			//
			y--;				//
			break;				//
		}					//
		case 1: { //left		//
			x--;				//
			break;				//
		}					//
		case 2: { //down		//
			y++;				//
			break;				//
		}					//
		case 3: { //right		//
			x++;				//
			break;				//
		}					//
		}
		temp.setCoords(x, y);	//puts the new location into a Coords object
		coordinates.push(temp);	//adds the new location to the stack
		checkWall[x][y] = 0;	//makes the new location a space
		checkVisited[x][y] += 2;//sets it to "double visited," so it can never be visited again
	}
}
开发者ID:Cmoore28,项目名称:CS172,代码行数:78,代码来源:Source.cpp


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