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


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

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


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

示例1: goEast

bool MazeSolver::goEast(Creature& myCreature, Maze& myMaze) {
	// coming from the west
	cout << "Trying to head East!" << endl;
	if ((myCreature.getCrCol() + 1) < myMaze.getMazeWidth())
	{
		//get the state of the space to the east
		char stateOfEast = myMaze.getSquareState(myCreature.getCrRow(), myCreature.getCrCol() + 1);
		cout << "State of the East reads: " << stateOfEast << endl;
		// and if space to the east is clear
		if (stateOfEast == myMaze.getClearSymbol() || stateOfEast == myMaze.getPathSymbol()) // if the square is clear or on path, it has not been visited
		{
			cout << "Moving the creature east. " << endl;
			myCreature.moveEast();
			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 = goEast(myCreature, myMaze); // else try to go east
					if (!success)
					{
						success = goSouth(myCreature, myMaze);// else try to go south
						if (!success)
						{
							cout << "Heading back West!" << endl << endl;
							myCreature.markAsVisited(); // else mark the square as visited
							goWest(myCreature, myMaze); // and head back West
						}
					}
				}
			}
		}
	}
	else success = false;
	return success;
}
开发者ID:jmacvey,项目名称:c_code,代码行数:46,代码来源:MazeSolver.cpp


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