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


C++ Tank::gethitsScored方法代码示例

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


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

示例1: displayTurnStats

/**  
	stat menu displayed every turn, the only function 
	that I could get passing objects to work with
	tried to make the stat menu seem as if it was a static 
	screen that updated each turn instead of a scrolling display
*/
void displayTurnStats(Tank tank1, Tank tank2)
{
    cout << tank1.getplayerName() << "          vs          " << tank2.getplayerName() << endl;
	cout << tank1.getbarrelAngle() << "/" << tank1.getroundVelocity() << " " << tank1.getlastShot() << "              " << tank2.getlastShot() << endl;
    cout << "MyPos: " << tank1.getxpos() << endl;
    cout << "Armor: " << tank1.getarmor()     << "                    " << "Armor: " << tank2.getarmor() << endl;
    cout << "Ammo:  " << tank1.getnumRounds() << "                     " << "Ammo: " << tank2.getnumRounds()<< endl;
    cout << "Fuel:  " << tank1.getfuelLevel() << "                   " << "Fuel: " << tank2.getfuelLevel()<< endl;
    cout << tank1.gethitsScored() << "                             " << tank2.gethitsScored() << endl;
    cout << endl;
    cout << endl;
    cout << endl;
    cout << "   __q--                          --p__   " << endl;
    cout << "___0o-o0__________________________0o-o0___" << endl;
    cout << endl;
    cout << endl;
}//end displayTurnStats
开发者ID:tapickell,项目名称:MetalTank,代码行数:23,代码来源:MyFinalProject.cpp

示例2: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	while(restartFlag == 1) // when set to anything other than 1 exits program
	{
		showIntro();
		// create tanks
		Tank playerTank;
		Tank enemyTank;

/**
	using x axis from 0 - 600 as playing field
	tanks start 50 units from end and are not allowed
	to move off field. xpos is the center of tank
	and 0 on y axis, turret is 6 units up on y.
	I gave the tanks 30 units on either side of xpos 
	for tank length and to add arcade fun factor, 
*/
		/*setupPlayer(playerTank, enemyTank);*/
		string nameString = getInput <string> ("Enter your name: ");
		playerTank.setplayerName(nameString);
		playerTank.setxpos(50);
		if(nameString == "pickle")
		{
			playerTank.rootTank();// cheat mode settings
			superSecretMenu();// fake menu for dramatic effect
		}
		enemyTank.setplayerName("General Morden");
		enemyTank.setxpos(550);

/**
	I originally tried using this as a seperate function 
	and passing the tank objects to it, but that would 
	reset the values of the objects like they were new again
*/
		/*monkeyEngine(playerTank, enemyTank);*/
		int turnCounter = 1;
		bool gameOn = true;
		while(gameOn == true)
		{
			cout << "        ******METAL  TANK****** " << endl;
			cout << endl;
			cout << "Turn: " << turnCounter << endl;
			cout << playerTank.getmessage() << endl;
			displayTurnStats(playerTank, enemyTank);
			cout << endl;
/**
	This is the menu that allows the user to choose what 
	move they want to make, Fwd, Back, Fire or Exit
*/
			int menu = showBattleMenu();
			switch(menu)
			{
			case 1:	
				//	player selects move forward from menu
				if(playerTank.getfuelLevel()>0 && playerTank.getxpos()<300)
				{
					playerTank.moveFwd();
				}
				else
				{
					playerTank.setmessage("You can't move that way!");
				}
				break;
			case 2:
				//	player selects move backward from menu
				if(playerTank.getfuelLevel()>0 && playerTank.getxpos()>playerTank.getmoveDist())
				{
					playerTank.moveBack();
				}
				else
				{
					playerTank.setmessage("You can't move that way!");
				}
				break;
			case 3:	
				//	player selects fire round from menu
				if(playerTank.getnumRounds()>0)
				{
					int angleInt = getInput <int>("Enter angle (12-65): ");// angles are from M1-Abrams tank
					playerTank.setbarrelAngle(angleInt);
					int velInt = getInput <int>("Enter velocity (60-80): ");// the 60-80 are to keep the player within range
					playerTank.setroundVelocity(velInt);
					playerTank.fireRound();
					double myRound = calcRoundTrajectory(playerTank.getbarrelAngle(), playerTank.getroundVelocity());
					playerTank.setroundDist(myRound);
					double finalRoundPos = (playerTank.getxpos() + playerTank.getroundDist());
					if(finalRoundPos > (enemyTank.getxpos() - 30) && finalRoundPos < (enemyTank.getxpos() + 30))
					{
						playerTank.setlastShot("Direct Hit!");
						enemyTank.setarmor(enemyTank.getarmor() - 4);
						playerTank.sethitsScored(playerTank.gethitsScored()+1);
					}
					else if(finalRoundPos > (enemyTank.getxpos() + 30))
					{
						playerTank.setlastShot("Over Shot!");
					}
					else
					{
						playerTank.setlastShot("Fell Short!");
					}
//.........这里部分代码省略.........
开发者ID:tapickell,项目名称:MetalTank,代码行数:101,代码来源:MyFinalProject.cpp


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