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


C++ Maze::display方法代码示例

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


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

示例1: goWest

bool MazeSolver::goWest(Creature& myCreature, Maze& myMaze){
	// coming from the east
	// if space to the west is within the maze
	cout << "Trying to head West." << endl;
	if ((myCreature.getCrCol() - 1) >= 0)
	{
		//get the state of the space to the north
		char stateOfWest = myMaze.getSquareState(myCreature.getCrRow(), myCreature.getCrCol() - 1);
		cout << "State of the West reads: " << stateOfWest << endl;
		// and if space to the west is clear
		if (stateOfWest == myMaze.getClearSymbol() || stateOfWest == myMaze.getPathSymbol()) // if the path is clear, it has not been visited
		{
			cout << "Moving the creature west. " << endl;
			myCreature.moveWest();
			cout << "Movement is a success... Marking the path..." << endl;
			myCreature.markAsPath();
			cout << "Path Marked." << endl;
			myMaze.display();
			// if we're at the exit, we're done
			if (isAtExit(myCreature, myMaze))
			{
				cout << "We've reached the end of the maze!" << endl;
				success = true;
			}
			else
			{
				success = goNorth(myCreature, myMaze); // else try to go north again
				if (!success)
				{
					success = goWest(myCreature, myMaze); // else try to go west
					if (!success)
					{
						success = goSouth(myCreature, myMaze);// else try to go south
						if (!success)
						{
							cout << "Heading back East!" << endl << endl;
							myCreature.markAsVisited(); // else mark the square as visited
							goEast(myCreature, myMaze); // and head back east
						}
					}
				}
			}
		}
	}
	else success = false;
	return success;
}
开发者ID:jmacvey,项目名称:c_code,代码行数:47,代码来源:MazeSolver.cpp

示例2: goSouth

bool MazeSolver::goSouth(Creature& myCreature, Maze& myMaze){
	cout << "Trying to head South!" << endl;
	if ((myCreature.getCrRow() + 1) < myMaze.getMazeLength())
	{
		//get the state of the space to the east
		char stateOfSouth = myMaze.getSquareState(myCreature.getCrRow()+1, myCreature.getCrCol());
		cout << "State of the South reads: " << stateOfSouth << endl;
		// and if space to the east is clear
		if (stateOfSouth == myMaze.getClearSymbol() || stateOfSouth == myMaze.getPathSymbol()) // if the square is clear or on path, it has not been visited
		{
			cout << "Moving the creature Soutg. " << endl;
			myCreature.moveSouth();
			cout << "Movement is a success... Marking the path..." << endl;
			myCreature.markAsPath();
			cout << "Path Marked." << endl;
			myMaze.display();
			// if we're at the exit, we're done
			if (isAtExit(myCreature, myMaze))
			{
				cout << "We've reached the end of the maze!" << endl;
				success = true;
			}
			else
			{
				success = goWest(myCreature, myMaze); // else try to go north again
				if (!success)
				{
					success = goSouth(myCreature, myMaze); // else try to go south again
					if (!success)
					{
						success = goEast(myCreature, myMaze);// else try to go east
						if (!success)
						{
							cout << "No room here, partner!  Heading back North!" << endl << endl;
							myCreature.markAsVisited(); // else mark the square as visited
							goNorth(myCreature, myMaze); // and head back north
						}
					}
				}
			}
		}
	}
	else success = false;
	return success;
}
开发者ID:jmacvey,项目名称:c_code,代码行数:45,代码来源:MazeSolver.cpp


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