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


C++ Thing::getName方法代码示例

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


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

示例1: ArrayItr

void AppClass::
list()
{
	Thing *theThing;
	ArrayItr *theItr = new ArrayItr(testArray,testArray->getSize() );
	int i = 0;
	bool result = theItr->getNext(theThing);
	while(result)
	{
		cout << i+1 << ":ID = " << theThing->getID() 
			 <<" Name = " << theThing->getName() << "." <<endl;
		result = theItr->getNext(theThing);
		i++;
	}
}
开发者ID:jsjtxietian,项目名称:Cpp,代码行数:15,代码来源:排序【面向对象C++数据结构器.cpp

示例2:

void AppClass::
retrieve()
{
	int pos;
	cout<<"\nEnter an array position: ";
	cin >> pos;
	
	Thing * theThing ;
	bool result = 
		testArray->getElement(pos,theThing);
	
	if(result)
	{
		cout << "\nThe Thing at " << pos 
		     << " has an ID of " << theThing->getID()
			 << " and a name of " << theThing->getName() << "." << endl;
	}
	else
	{
		cout << "The position is out of Range." <<endl;
	}
}
开发者ID:jsjtxietian,项目名称:Cpp,代码行数:22,代码来源:排序【面向对象C++数据结构器.cpp

示例3: main

//----------------------------------------------------------------------
//                              MAIN
//----------------------------------------------------------------------
int main(int argc, char *argv[]) {
	shiplog("Initialising", 1);
	// init, and enter game loop checking for keyboard input
	init_for_draw();
	init_monsters();
	initMapDrawingChars();

	shiplog("Going to title screen", 1);
	vis_cursor(0);
	title_screen();
	clear();

	// TODO: check for savegame

	shiplog("Getting name", 1);
	vis_cursor(1);
	string iname = get_pcname();
	clear();
	vis_cursor(0);

	shiplog("Getting origin world", 1);
	playerWorld w_choice = world_choice();
	clear();
	shiplog("Getting regiment choice", 1);
	playerCareer c_choice = career_choice();

	shiplog("Generating starting level", 1);
	LevelMap currentLevelMap(1, MAIN);
	currentLevelMap.generate(1, CAVERN);
	Level currentLevel(&currentLevelMap);
  currentLevel.addFloorItems(2);
  currentLevel.addLevelMonsters();

	shiplog("Creating PC", 1);
	Location startLoc = currentLevel.findEmptyLocation();
	Player pc(iname, w_choice, c_choice, startLoc.x, startLoc.y, WHITE, '@');

	clear();
	printScreen(currentLevel, pc, TRUE);

	MessageLog msg;
	msg.print("You're inside.");
  
	shiplog("Entering main game loop", 1);
	while (1) {
	// get curses terminal keyboard input
  	char c = getch();

	// vi-like movement keys
	//
	// TODO: Sort out numpad & cursor keys
	// TODO: Handle more failures to move than just hitting
	//       a wall
  	if (c == 'h' || c == 'j' || c == 'k' || c == 'l' ||
  		c == 'y' || c == 'u' || c == 'b' || c == 'n') {
  		direction dir;
  	switch (c) {
  		case 'h':
  		dir = WEST; break;
  		case 'j':
  		dir = SOUTH; break;
  		case 'k':
  		dir = NORTH; break;
  		case 'l':
  		dir = EAST; break;
  		case 'y':
  		dir = NORTHWEST; break;
  		case 'u':
  		dir = NORTHEAST; break;
  		case 'b':
  		dir = SOUTHWEST; break;
  		case 'n':
  		dir = SOUTHEAST; break;
  	}

  	if (pc.setLocation(dir, currentLevelMap) == 0) {
  		msg.print("Bonk.");
  	} else {
  		printScreen(currentLevel, pc, FALSE);
      Location loc = pc.getLocation();
  		unsigned int objectId = currentLevel.objectAt(loc.x,loc.y);
  		if (objectId != 0) {
  			Thing t = currentLevel.getObject(objectId);
  			string s = "You see ";
  			string name = t.getName();
  			if (name[0] == 'a' || name[0] == 'e' || name[0] == 'i' || name[0] == 'o' || name[0] == 'u') {
  				s.append("an ");
  			} else {
  				s.append("a ");
  			}
  			s.append(name);
  			s.append(".");
  			msg.print(s);
  		}
  	}
  }

//.........这里部分代码省略.........
开发者ID:kokorhekkus,项目名称:the-ship-cpp,代码行数:101,代码来源:main.cpp

示例4: execute

   void TakeAction::execute(Player *player, Command *command, Game *game) {

      Place            *location = player->getLocation();
      ThingListCItPair roomItems = location->getThingsByName(command->getDirectObject());

      if (roomItems.begin == roomItems.end) {
         player->out("display") << "There is no " << command->getDirectObject()
            << " here!" << endl;
         return;
      }

      try {

         Thing *thing =
            Entity::clarifyEntity<ThingListCItPair, ThingListCIt, Thing *>(roomItems,
            player);

         if (ENTITY_OBJECT != thing->getType()) {
            player->out("display") << "You can't take that!" << endl;
         }

         else {

            try {

               player->take(static_cast<Object *>(thing));

               string message = thing->getMessage("take");
               if (message.length() > 0) {
                  player->out("display") << message << endl;
               }

               else {
                  player->out("display") << "You take the " << thing->getName()
                     << "." << endl;
               }
            }

            catch (enum Being::takeError error) {

               // TODO: consider custom messages
               switch (error) {

                  case Being::TAKE_TOO_HEAVY:
                     player->out("display") << command->getDirectObject()
                        << " is too heavy.  Try dropping something first."
                        << endl;
                     break;

                  case Being::TAKE_UNTAKEABLE:
                     player->out("display") << "You can't take that!" << endl;
                     break;

                  default:
                     player->err() << "Unknown error taking object.  "
                        << "This is a bug." << endl;
                     break;
               }
            }
         }
      }

      catch (string name) {
         player->out("display") << "There is no " << name << " here!" << endl;
      }
   }
开发者ID:Ockin,项目名称:trogdor-pp,代码行数:66,代码来源:actions.cpp


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