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


C++ Stack::Consult方法代码示例

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


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

示例1: ShowCommands

void ShowCommands()
{
	//acciones de palabras simples
	std::string action = stackCommands.Consult().c_str();
	int i = 0;
	char result = 's';
	switch (Hashit(Upcase(action)))
	{
	case	ayuda:

			printf(HELP_LIST);
			colortext(WHITE); printf(LEAVE); colortext(LIGHTGREY); printf(HELP_LEAVE);
			colortext(WHITE); printf(OPEN_DOOR); colortext(LIGHTGREY); printf(HELP_OPEN_DOOR);
			colortext(WHITE); printf(CLEAR_SCREEN); colortext(LIGHTGREY); printf(HELP_CLEAR_SCREEN);
			colortext(WHITE); printf(PICKUP); colortext(LIGHTGREY); printf(HELP_PICKUP);
			colortext(WHITE); printf(EAST); colortext(LIGHTGREY); printf(HELP_EAST);
			colortext(WHITE); printf(PUT_IN_BAG); colortext(LIGHTGREY); printf(HELP_PUT_IN_BAG);
			colortext(WHITE); printf(INV); colortext(LIGHTGREY); printf(HELP_INV);
			colortext(WHITE); printf(LOOK); colortext(LIGHTGREY); printf(HELP_LOOK);
			colortext(WHITE); printf(NORTH); colortext(LIGHTGREY); printf(HELP_NORTH);
			colortext(WHITE); printf(WEST); colortext(LIGHTGREY); printf(HELP_WEST);
			colortext(WHITE); printf(EXITS); colortext(LIGHTGREY); printf(HELP_EXITS);
			colortext(WHITE); printf(DROP); colortext(LIGHTGREY); printf(HELP_DROP);
			colortext(WHITE); printf(GET_FROM_BAG); colortext(LIGHTGREY); printf(GET_FROM_BAG);
			colortext(WHITE); printf(SOUTH); colortext(LIGHTGREY); printf(HELP_SOUTH);
			
			break;
	case	mirar:
		NewRoom();
		break;
	case	norte:
		if (myMap.CheckN(myPlayer.GetLatitude(), myPlayer.GetLongitude()) > 0 && myMap.CheckN(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100)
		{
			myPlayer.SetLatitude(myPlayer.GetLatitude() - 1);
			NewRoom();
		}
		else printf(NO_EXITS);
		break;
	case	sur:
		if (myMap.CheckS(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckS(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100)
		{
			myPlayer.SetLatitude(myPlayer.GetLatitude() + 1);
			NewRoom();
		}
		else printf(NO_EXITS);
		break;
	case	este:
		if (myMap.CheckE(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckE(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100)
		{
			myPlayer.SetLongitude(myPlayer.GetLongitude() + 1);
			NewRoom();
		}
		else printf(NO_EXITS);
		break;
	case	oeste:

		if (myMap.CheckW(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckW(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100)
		{
			myPlayer.SetLongitude(myPlayer.GetLongitude() - 1);
			NewRoom();
		}
		else printf(NO_EXITS);
		break;
	case	salidas:
		myMap.ShowExits(myPlayer.GetLatitude(), myPlayer.GetLongitude());
		break;
	case	cls:
		system("cls");
		break;
	case	inventario:
		printf(INVENTORY);
		if (bag.GetState() == 's')
			printf(Show_Item(bag.GetDescription().c_str()));

		if (myPlayer.inventory.Size() > 0)
		{
				for (int i = 0; i < myPlayer.inventory.Size(); ++i)
					printf(Show_Item(myPlayer.inventory.GetDescPosN(i).c_str()));
		}
			else
				if ( bag.GetState() != 's' ) printf( NOTHING_TO_SHOW );
		break;
	default:
		result = 'n';
		break;
	}
	//acciones de 2 palabras
	action = GetWord(stackCommands.Consult().c_str());
	Item::Node *tmp;
	switch (Hashit(Upcase(action)))
	{
	case	coger:
		action = CutFirstWord(stackCommands.Consult().c_str());
		action = GetWord(action.c_str());
	
		if (action == BAG)
		{
			bag.ToInventory(myPlayer.GetLatitude(), myPlayer.GetLongitude());
		}
		else
//.........这里部分代码省略.........
开发者ID:qweilak,项目名称:Leptis---simple-text-adventure-game,代码行数:101,代码来源:main.cpp

示例2: Update

void Update(clock_t &tLast, short &charIndex, bool &newWord, char(&command)[MAX_CHARATERS_PER_LINE])
{

	command[charIndex] = GetCharacter(newWord);					//escuchamos la entrada de datos con un timeout para poder dedicar tiempo a los calculos posteriores

																//verificamos que tenemos caracter leido o nueva palabra empezada
	if (command[charIndex] != NULL || newWord != 0)
	{
		if (newWord == 0) { newWord = 1; }						//ponemos a true el boleano de palabra

																//cuando pulse enter el jugador, almacenamos la palabra en el stack y reseteamos el indice de nuestra palabra asi como el boleano 
																//en caso contrario aumentamos el indice para obtener una nueva letra

		if (command[charIndex] == '\n')
		{
			command[charIndex] = 0;
			if (charIndex > 0)					//si tan solo pulsa enter no necesitamos almacenarlo en la pila
			{
				newWord = 0;
				stackCommands.Push((std::string) command);
				command[0] = 0;
			}
			else
			{
				Prompt();
			}
			charIndex = 0;
		}
		else
		{
			++charIndex;
		}
	}

	//tratamiento acciones o comandos
	//Si la pila no esta vacia y el delay se cumple ejecutamos una nueva instruccion
	if (!stackCommands.Empty() && (clock() - tLast) > DELAY_BETWEEN_COMMANDS)
	{
		//La palabra reservada para ejecutar 'salir del juego' es especial ya que requiere de verificación. 
		if (LEAVE == Upcase(stackCommands.Consult()))
		{
			char a[MAX_CHARATERS_PER_LINE];	//para no obtener datos de la pila definios una nueva variable
			a[0] = 0;
			do				//para salir hay que verificar antes
			{
				printf(LEAVE_Q);
				scanf_s("%s", a, _countof(a));
			} while (!Compare(YES, Upcase(a)) && !Compare(NO, Upcase(a)));

			if (Compare(YES, Upcase(a)))  gameState = endLoop;
			else
			{
				Prompt();
				stackCommands.Pop();
			}
		}
		else
		ShowCommands();
		tLast = clock();
	}
}
开发者ID:qweilak,项目名称:Leptis---simple-text-adventure-game,代码行数:61,代码来源:main.cpp


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