Class:
Code:
#include <iostream>
#include <ctime>
class Player1
{
public:
int Health;
Player1();
int Attack();
int Attack1();
int Attack2();
int Burn(int damage);
int Heal();
void Damage(int damage);
void DisplayHP();
};
class Monster1
{
public:
int Health;
Monster1();
int RandomAttack();
void Damage(int damage);
void DisplayHP();
};
class Monster2
{
public:
int Health;
Monster2();
int RandomAttack();
void Damage(int damage);
void DisplayHP();
};
class Monster3
{
public:
int Health;
Monster3();
int RandomAttack();
void Damage(int damage);
void DisplayHP();
};
Main:
Code:
int main()
{
srand( (unsigned) time(0) );
Instructions();
return 0;
}
void Instructions()
{
string exit;
cout << "Do you want to start?: ";
cin >> exit;
if (exit == "no")
{
}
else if (exit == "yes")
{
system ("cls");
cout << "Attack the monster!" << endl
<< "Press 1 to use assault rifle (weak/accurate)" << endl
<< "Press 2 to big boom (stronger/less accurate)" << endl
<< "Press 3 to heal (You can't attack)" << endl;
system("pause");
pick();
system("pause");
system ("cls");
}
else if (exit == "mudkipz")
{
EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);
DrawMenuBar(GetConsoleWindow());
intro();
}
}
void pick()
{
string pick;
cout << "Which monster do you want to fight? (Truck, Tank, Plane): ";
cin >> pick;
if (pick == "Truck")
{
system("cls");
Combat1();
}
else if (pick == "Tank")
{
system("cls");
Combat2();
}
else if (pick == "Plane")
{
system ("cls");
Combat3();
}
}
Player1::Player1()
{
Health = 100;
}
Monster1::Monster1()
{
Health = 500;
}
Monster2::Monster2()
{
Health = 1000;
}
Monster3::Monster3()
{
Health = 200;
}
void Player1::DisplayHP()
{
cout << "Your HP: " << Health << endl;
}
void Monster1::DisplayHP()
{
cout << "Truck's HP: " << Health << endl;
}
void Monster2::DisplayHP()
{
cout << "Tank's HP: " << Health << endl;
}
void Monster3::DisplayHP()
{
cout << "Plane's HP: " << Health << endl;
}
void Player1::Damage(int damage)
{
Health -= damage;
}
void Monster1::Damage(int damage)
{
Health -= damage;
}
void Monster2::Damage(int damage)
{
Health -= damage;
}
void Monster3::Damage(int damage)
{
Health -= damage;
}
int Player1::Heal()
{
int randdamage;
randdamage = -(rand() % 20 + 1);
cout << "You healed: " << -(randdamage) << endl;
return randdamage;
}
int Player1::Attack()
{
int randdamage;
randdamage = rand() % 4 + 20;
cout << "You dealt: " << randdamage << " damage" << endl;
return randdamage;
}
int Player1::Attack1()
{
int randdamage;
randdamage = rand() % 100 + 5;
cout << "You dealt: " << randdamage << " damage" << endl;
return randdamage;
}
int Player1::Attack2()
{
int randdamage;
randdamage = rand() % 4 + 10;
cout << "You dealt: " << randdamage << " damage" << endl;
return randdamage;
}
int Monster1::RandomAttack()
{
int randdamage;
int randattack;
randattack = rand() % 2 + 1;
if (randattack == 1)
{
randdamage = rand() % 10 + 5;
}
else if (randattack == 2)
{
randdamage = rand() % 20 + 5;
}
cout << "You received: " << randdamage << " damage" << endl;
return randdamage;
}
int Monster2::RandomAttack()
{
int randdamage;
int randattack;
randattack = rand() % 2 + 1;
if (randattack == 1)
{
randdamage = rand() % 5 + 5;
}
else if (randattack == 2)
{
randdamage = rand() % 8 + 5;
}
cout << "You received: " << randdamage << " damage" << endl;
return randdamage;
}
int Monster3::RandomAttack()
{
int randdamage;
int randattack;
randattack = rand() % 2 + 1;
if (randattack == 1)
{
randdamage = rand() % 5 + 5;
}
else if (randattack == 2)
{
randdamage = rand() % 50 + 5;
}
cout << "You received: " << randdamage << " damage" << endl;
return randdamage;
}
void Combat1()
{
int choice;
Player1 User;
Monster1 Monster;
User.DisplayHP();
Monster.DisplayHP();
while (User.Health > 0)
{
cout << "Press 1 to use assault rifle (weak/accurate)" << endl
<< "Press 2 to big boom (stronger/less accurate)" << endl
<< "Press 3 to heal (You can't attack)" << endl;
cin >> choice;
switch (choice)
{
case 1:
Monster.Damage(User.Attack());
Monster.DisplayHP();
User.Damage(Monster.RandomAttack());
User.DisplayHP();
break;
case 2:
Monster.Damage(User.Attack1());
Monster.DisplayHP();
User.Damage(Monster.RandomAttack());
User.DisplayHP();
break;
case 3:
User.Damage(User.Heal());
Monster.DisplayHP();
User.Damage(Monster.RandomAttack());
User.DisplayHP();
break;
case 1337:
Monster.Damage(1000000);
Monster.DisplayHP();
User.DisplayHP();
cout << "you cheater" << endl;
break;
}
if (User.Health <= 0)
{
MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
system("pause");
system("cls");
Instructions();
break;
}
if (Monster.Health <= 0)
{
MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
cout << "You ween" << endl;
system("pause");
system("cls");
Instructions();
break;
}
}
}
void Combat2()
{
int choice;
Player1 User;
Monster2 Tank;
User.DisplayHP();
Tank.DisplayHP();
while (User.Health > 0)
{
cout << "Press 1 to use assault rifle (weak/accurate)" << endl
<< "Press 2 to big boom (stronger/less accurate)" << endl
<< "Press 3 to heal (You can't attack)" << endl;
cin >> choice;
switch (choice)
{
case 1:
Tank.Damage(User.Attack());
Tank.DisplayHP();
User.Damage(Tank.RandomAttack());
User.DisplayHP();
break;
case 2:
Tank.Damage(User.Attack1());
Tank.DisplayHP();
User.Damage(Tank.RandomAttack());
User.DisplayHP();
break;
case 3:
User.Damage(User.Heal());
Tank.DisplayHP();
User.Damage(Tank.RandomAttack());
User.DisplayHP();
break;
case 4:
Tank.Damage(User.Attack2());
Tank.DisplayHP();
User.Damage(Tank.RandomAttack());
User.DisplayHP();
break;
case 1337:
Tank.Damage(1000000);
Tank.DisplayHP();
User.DisplayHP();
cout << "you cheater" << endl;
break;
}
if (User.Health <= 0)
{
MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
system("pause");
system("cls");
Instructions();
break;
}
if (Tank.Health <= 0)
{
MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
system("pause");
system("cls");
Instructions();
break;
}
}
}
void Combat3()
{
int choice;
Player1 User;
Monster3 Plane;
User.DisplayHP();
Plane.DisplayHP();
while (User.Health > 0)
{
cout << "Press 1 to use assault rifle (weak/accurate)" << endl
<< "Press 2 to big boom (stronger/less accurate)" << endl
<< "Press 3 to heal (You can't attack)" << endl;
cin >> choice;
switch (choice)
{
case 1:
Plane.Damage(User.Attack());
Plane.DisplayHP();
User.Damage(Plane.RandomAttack());
User.DisplayHP();
break;
case 2:
Plane.Damage(User.Attack1());
Plane.DisplayHP();
User.Damage(Plane.RandomAttack());
User.DisplayHP();
break;
case 3:
User.Damage(User.Heal());
Plane.DisplayHP();
User.Damage(Plane.RandomAttack());
User.DisplayHP();
break;
case 4:
Plane.Damage(User.Attack2());
Plane.DisplayHP();
User.Damage(Plane.RandomAttack());
User.DisplayHP();
break;
case 1337:
Plane.Damage(1000000);
Plane.DisplayHP();
User.DisplayHP();
cout << "you cheater" << endl;
break;
}
if (User.Health <= 0)
{
MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
system("pause");
system("cls");
Instructions();
break;
}
if (Plane.Health <= 0)
{
MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
system("pause");
system("cls");
Instructions();
break;
}
}
}
hehe. probably should have put the combats into classes, but i did this a long time ago. missing some stuff cuz it would be way too long.
EDIT: @the noob on top of me. why the hell would the program close randomly because of int main()? ya sure u aint sleepin in class?