本文整理汇总了C++中Tank::moveBack方法的典型用法代码示例。如果您正苦于以下问题:C++ Tank::moveBack方法的具体用法?C++ Tank::moveBack怎么用?C++ Tank::moveBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tank
的用法示例。
在下文中一共展示了Tank::moveBack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _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!");
}
//.........这里部分代码省略.........