示例#1
0
void enemy::AI(player &mainchar)
{
	int num;
	num = rand()% 50 + 1;
	if(num <= chancefirethrow)
	{
		cout << "The monster attempts a fire attack!" << endl;
		num = rand()% 50 +1;
		if (num <= chancetohitmagic)
		{
			cout << "It gets you for "<< dmgfirethrow << " damage" << endl << endl;
			mainchar.sethealth(mainchar.gethealth() - (dmgfirethrow));
		}
			else
		{
			cout << "It misses!" << endl << endl;
		}
	}
	else
	{
		num = rand()% 50 + 1;
		if (num <= chancetohit)
		{
			cout << "The monster deals " << atk + atkbonus << " damage to you." << endl << endl;
			mainchar.sethealth(mainchar.gethealth() - (atk + atkbonus));
		}
		else
		{
			cout << "The monster misses you!" <<endl<<endl;
		}
	}
	
	if(regen == true)
	{
		if (health + 2 < healthcap)
		{
			health = health + 4;
		}
	}
}
示例#2
0
void location::roommenu(player &mainchar, map &maplocation)
{
	if (mainchar.alive == false)
	{
		return;
	}
	
	bool validinput = false;
	
	while(validinput == false)
	{
		if((mainchar.gethealth() + 5) < mainchar.gethealthcap())
		{
			mainchar.sethealth(mainchar.gethealth() + 5);
		}
		if((mainchar.getmana() + 5) < mainchar.getmanacap())
		{
			mainchar.setmana(mainchar.getmana() + 5);
		}
		cout<<"The Menu:"<<endl;
		if(goN == true)
		{
			cout<<"(N) Go North"<<endl;
		}
		if(goS == true)
		{
			cout<<"(S) Go South"<<endl;
		}
		if(goE == true)
		{
			cout<<"(E) Go East"<<endl;
		}
		if(goW == true)
		{
			cout<<"(W) Go West"<<endl;
		}
		
		cout<<"(1) Inventory"<<endl;
		cout<<"(2) Stats"<<endl;
		cout<<"(3) Equip Weapon"<<endl;
		char input;
		cin>>input;
		switch(input)
		{
		case 'n':
		case 'N':
			if(goN == true)
			{
				maplocation.goN();
				validinput = true;
			}
			else
			{
				cout<<"Invalid Input.  Try Again."<<endl;
			}
			break;
		case 's':
		case 'S':
			if(goS == true)
			{
				maplocation.goS();
				validinput = true;
			}
			else
			{
				cout<<"Invalid Input.  Try Again."<<endl;
			}
			break;
		case 'e':
		case 'E':
			if(goE == true)
			{
				maplocation.goE();
				validinput = true;
			}
			else
			{
				cout<<"Invalid Input.  Try Again."<<endl;
			}
			break;
		case 'w':
		case 'W':
			if(goW == true)
			{
				maplocation.goW();
				validinput = true;
			}
			else
			{
				cout<<"Invalid Input.  Try Again."<<endl;
			}
			break;
		case '1':
			mainchar.displayinv();
			break;
		case '2':
			displaystats();
			break;
		case '3':
			mainchar.displayinv();
			cout<<"Which item would you like to equip (inventory slot number)?"<<endl;
			cin>>input;
			input -= 48;
			mainchar.equipweapon(input - 1);
			validinput = true;
			break;
		default:
			cout<<"Invalid Input.  Try Again."<<endl<<endl;
		}
	}
	}