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


C++ ActionList::PrintActions方法代码示例

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


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

示例1: Shop

void GameFlow::Shop()
{
	ActionList actions;
	actions.AddAction("[B] Buy");
	actions.AddAction("[S] Sell");
	actions.AddAction("[X] Leave");
	Map->GetCharacter()->PrintInfo();
	actions.PrintActions();
	char action=GetUserInput(actions);
	while(action!='X')
	{
		system("cls");
		Map->GetCharacter()->PrintInfo();
		//cout<<"Market:"<<endl;
		if(action=='B')
		{
			//set the level of the items available
			int highlevel=Map->GetCurrentTile()->GetLevel()+4;
			int lowlevel=Map->GetCurrentTile()->GetLevel()-4;
			if(lowlevel<1)
				lowlevel=1;

			double markup=3;
			if(Map->GetCurrentTile()->GetContainer()->GetType()==TOWN)
			{
				Town* t=(Town*)Map->GetCurrentTile()->GetContainer();
				if(t->GetSpecialty()=="Market")
				{
					markup=1.5;
					if(Map->GetCharacter()->GetLevel()>highlevel)
						highlevel+=(Map->GetCharacter()->GetLevel()-highlevel)/2;
				}
			}
			else if(Map->GetCurrentTile()->GetContainer()->GetType()==CASTLE)
			{
				markup=2;
				if(Map->GetCharacter()->GetLevel()>highlevel)
					highlevel=Map->GetCharacter()->GetLevel();
			}
			
			//get the items from the level, adding them to possible items
			map<string,Item> tempitemMap;
			for(int i=lowlevel;i<=highlevel;i+=1)
			{
				vector<string> items=Item::ItemLevelMap[i];
				for(unsigned int j=0;j<items.size();j+=1)
					tempitemMap[items[j]]=Item::ItemMap[items[j]];
			}
			//add them to a vector
			vector<Item> sellingItems;
			map<string,Item>::iterator it=tempitemMap.begin();
			while(it!=tempitemMap.end())
			{
				sellingItems.push_back(it->second);
				it++;
			}
			int tag=0;
			while(tag!=-1)
			{
				cout<<"Buying:"<<endl;
				//print the items
				for(unsigned int i=0;i<sellingItems.size();i+=1)
				{
					int price=(int)(sellingItems[i].GetWorth()*markup);
					cout<<i<<". "<<sellingItems[i].GetName()<<" - "<<price<<"Qulz"<<endl;
				}
				//select item
				string input;
				cout<<"Enter the item number you wish to buy(-1 to exit): ";
				cin>>input;
				tag=Printer::StringToInt(input);
				while((tag<(-1))||(tag>=(signed int)sellingItems.size()))
				{
					Printer::MoveBackLine();
					Printer::ClearLine();
					cout<<"Enter the item number you wish to buy(-1 to exit): ";
					cin>>input;
					tag=Printer::StringToInt(input);
				}
				//check to see if you can buy
				if(tag!=-1)
				{
					if(Map->GetCharacter()->GetQulz()>=sellingItems[tag].GetWorth()*markup)
					{
						if(Map->GetCharacter()->AddItem(sellingItems[tag]))
						{
							Map->GetCharacter()->AddQulz((int)(-sellingItems[tag].GetWorth()*markup));
							Printer::pout<<"#014You've purchased the "<<sellingItems[tag].GetName()<<endl;
						}
					}
					else
					{
						Printer::pout<<"#014You don't have enough Qulz to purchase that item"<<endl;
					}
					system("pause");
					system("cls");
					Map->GetCharacter()->PrintInfo();
				}
			}//end while
			system("cls");
//.........这里部分代码省略.........
开发者ID:NicholasDenaro,项目名称:Text-Based-RPG,代码行数:101,代码来源:GameFlow.cpp


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