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


C++ World::Display方法代码示例

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


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

示例1: main

int main()
{
    string name;

    cout << "You are about to enter the world of the calamitous WUMPUS,";
    cout << " beware."  << endl << "\nIf you would like to enter WUMPUS world, ";
    cout << "please enter your first name." << endl;
    cin >> name;


    cout << "\n**************Directions****************\n" << endl;
    cout << "Press L to face left. (<)" << endl;                                        //game dirrections
    cout << "Press R to face right. (>)" << endl;
    cout << "Press U to face up. (^)" << endl;
    cout << "Press D to face down. (.)" << endl;
    cout << "Press F to move forward." << endl;
    cout << "You may pick up (P) the gold when one spot away and facing the gold." << endl;
    cout << "You may shoot (S) the WUMPUS when one spot away and facing the WUMPUS.\n" << endl;


    World *world = new World(name);                             //create instance of World
    world->Display();                                       //call display method


    char mInput = ' ';
    bool quit = 0;
    int status;

    while (!quit)                                                       //loop for the action of the game
    {
        //LEFT, RIGHT, FRWRD, SHOOT, PICKUP
        cout << "\n\nType L, R, U, D, F, S, P, or Q" << endl;
        cin >> mInput;
        mInput = toupper(mInput);                                       //convert all to uppercase


        if(mInput == 'Q')break;
        status = world->Action(mInput);
        world->Display();

    }


    cout << "Game Over" << endl;


    return 0;
}
开发者ID:spencercope,项目名称:ResumeProjects,代码行数:48,代码来源:main.cpp

示例2: main

// ======================
//     main function
// ======================
int main()
{
	string s;
	srand(time(NULL));		// Seed random number generator
	World w;

	// Randomly create 100 ants
	int antcount = 0;
	while (antcount < INITIALANTS)
	{
		int x = rand() % WORLDSIZE;
		int y = rand() % WORLDSIZE;
		if (w.getAt(x,y)==NULL)		// Only put ant in empty spot
		{
			antcount++;
			Ant *a1 = new Ant(&w,x,y);
		}
	}
	// Randomly create 5 doodlebugs
	int doodlecount = 0;
	while (doodlecount < INITIALBUGS)
	{
		int x = rand() % WORLDSIZE;
		int y = rand() % WORLDSIZE;
		if (w.getAt(x,y)==NULL)		// Only put doodlebug in empty spot
		{
			doodlecount++;
			Doodlebug *d1 = new Doodlebug(&w,x,y);
		}
	}

	// Run simulation forever, until user cancels
	while (true)
	{
		w.Display();
		w.SimulateOneStep();
		cout << endl << "Press enter for next step" << endl;
		getline(cin,s);
	}
	return 0;
}
开发者ID:3588,项目名称:au-cs122,代码行数:44,代码来源:test.cpp


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