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


C++ Hero::get_money方法代码示例

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


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

示例1: Buy

void Market::Buy(void){
	Hero* h;
	int itemchoice,c=0,choice,i,tlvl,tmn;
	
	h=heroes->chooseHero("use for buying");                                     //choose Hero
	tlvl=h->get_level();
	tmn=h->get_money();

	cout<<"Type 1 to see available weapons\n     2 to see available armors\n     3 to see available potions\n     4 to see available spells.\n(More items will appear while you gain level and money)\nInput : ";
	cin>>choice;
	while(choice<1||choice>4){
		cout<<"Invalid Input.Type again : ";
		cin>>choice;
	}

	list<Weapon*>::iterator it;
	list<Armor*>::iterator ita;
	list<Potion*>::iterator itb;
	list<Spell*>::iterator itc;

	switch(choice){
		case 1:                                                                 //buy weapons
  			for ( i=0,it=weapon_list.begin() ; it!= weapon_list.end(); ++it ){  //print only the items which the hero is able to buy
				if( (*(*it)).able(tlvl,tmn) ){
                	cout<<++i<<" : ";
					(*(*it)).printItem();
				}
			}

			if(i==0){cout<<"No weapons can be bought with your money and level\nincrease them and return."<<endl;break;}

			cout<<"Type the number of the weapon you want to buy or 0 to exit : "<<endl;
			cin>>itemchoice;

			while(itemchoice<0 || itemchoice>i){
				cout<<"Wrong Input.Type again : ";
				cin>>itemchoice;
			}

  			for ( it=weapon_list.begin() ; it!= weapon_list.end(); ++it ){      //search list for the item choosen by input from those 
				if((*(*it)).able(tlvl,tmn) ){                               	//that the player can buy
                	c++;
				if(c==itemchoice)
				    break;
				}
			}

			if(h->add_to_bag( (*it) )){

				h->pay_for_item( (*it)->getprice() );
			}

			break;

		case 2:                                                                 //buy armor
  			for ( i=0,ita=armor_list.begin() ; ita != armor_list.end(); ++ita ){
				if( (*(*ita)).able(tlvl,tmn) ){
                cout<<++i<<" : ";
				(*(*ita)).printItem();
				}
			}
			
			if(i==0){cout<<"No armors can be bought with your money and level\nincrease them and return."<<endl;break;}

			cout<<"Type the number of the armor you want to buy or 0 to exit : "<<endl;
			cin>>itemchoice;
			while(itemchoice<0 || itemchoice>i){
				cout<<"Wrong Input.Type again : ";
				cin>>itemchoice;
			}
			
				for ( ita=armor_list.begin() ; ita!= armor_list.end(); ++ita ){
				if((*(*ita)).able(tlvl,tmn) ){
                	c++;
				if(c==itemchoice)
				    break;
				}
			}

			if(h->add_to_bag( (*ita) )){
				h->pay_for_item( (*ita)->getprice() );
            }
            
			break;
			
		case 3:                                                                 //buy potions
  			for ( i=0,itb=potion_list.begin() ; itb != potion_list.end(); ++itb ){

				if( (*(*itb)).able(tlvl,tmn) ){
                cout<<++i<<" : ";
				(*(*itb)).printItem();

				}
			}
			
			if(i==0){cout<<"No armors can be bought with your money and level\nincrease them and return."<<endl;break;}

			cout<<"Type the number of the armor you want to buy or 0 to exit : "<<endl;
			cin>>itemchoice;
			while(itemchoice<0 || itemchoice>i){
//.........这里部分代码省略.........
开发者ID:alexsibetheros,项目名称:simple_rpg,代码行数:101,代码来源:block.cpp


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