Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int damage = rand();
- int health = 100;
- const int cannon = 1;
- const int grenade = 2;
- const int rifle = 3;
- int weapon;
- int num_c = 3,
- num_g = 4;
- cout << "\tTEXT BATTLE GAME\n";
- cout << "Choose A Weapon <1, 2, or 3>\n"
- << "1. cannon: " << num_c << " left\n"
- << "2. grenade: " << num_g << " left\n"
- << "3. rifle\n";
- cin >> weapon;
- if (weapon == cannon)
- {
- int damage = 10 + rand() % 6;
- cout << "You've inflicted " << damage << " damage points on the enemy.\n";
- cout << "Computer: " << health - damage << endl << "You: " << health << endl;
- num_c--;
- cin.get();
- }
- else if (weapon == grenade)
- {
- int damage = 7 + rand() % 6;
- cout <<"You've inflicted " << damage << " damage points on the enemy.\n";
- cout << "Computer: " << health - damage << endl << "You: " << health << endl;
- num_g--;
- cin.get();
- }
- else if (weapon == rifle)
- {
- int damage = 3 + rand() % 6;
- cout << " You've inflicted " << damage << " damage points on the enemy.\n";
- cout << "Computer: " << health - damage << endl << "You: " << health << endl;
- cin.get();
- }
- else
- cin.get();
- cout << "Press any key to continue....." << cin.get() << endl;
- int computersChoice = 1 + rand() % 3;
- if (computersChoice = 1)
- {
- int damage = 10 + rand() % 6;
- cout << "The computer used a cannon in the attack.\n";
- cout << "The computer inflicted " << damage << " damage points to you.\n";
- cout << "Computer: " << health << endl << "You: " << health - damage << endl;
- num_c--;
- }
- else if (computersChoice == 2)
- {
- int damage = 7 + rand() % 6;
- cout << "The computer used a grenade in the attack.\n";
- cout << "The computer inflicted " << damage << " damage points to you.\n";
- cout << "Computer: " << health << endl << "You: " << health - damage << endl;
- num_g--;
- }
- else if (computersChoice == 3)
- {
- int damage = 3 + rand() % 6;
- cout << "The computer used a rifle in the attack.\n";
- cout << "The computer inflicted " << damage << " damage points to you.\n";
- cout << "Computer: " << health << endl << "You: " << health - damage << endl;
- }
- else
- cin.get();
- cin.get();
- return 0;
- }