Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <ctime>
- #include <vector>
- #include <algorithm>
- //#include "Fighter.h"
- //#include "Swordsman.h"
- using namespace std;
- // 1. Swordsman.h (power 5-8)
- class Swordsman{
- unsigned int power;
- public:
- // Constructors, destructor
- Swordsman(){ power = ( rand()%4 ) + 5; }
- Swordsman(unsigned int power){ this->power = power; }
- ~Swordsman(){ cout << "Swordsman with power " << power << " has been destroyed." << endl; }
- // Setter, getter
- void setPower(unsigned int i){ power = i; }
- unsigned int getPower(){ return power; }
- // Methods
- void show(){ cout << "Swordsman's power: " << power << endl; }
- };
- // 2. Archer.h (power 4-6)
- class Archer{
- unsigned int power;
- public:
- // Constructors, destructor
- Archer(){ power = ( rand()%3 ) + 4; }
- Archer(unsigned int power){ this->power = power; }
- ~Archer(){ cout << "Archer with power " << power << " has been destroyed." << endl; }
- // Setter, getter
- void setPower(unsigned int i){ power = i; }
- unsigned int getPower(){ return power; }
- // Methods
- void show(){ cout << "Archer's power: " << power << endl; }
- };
- // 3. Trooper.h (power 10-12)
- class Trooper{
- unsigned int power;
- public:
- // Constructors, destructor
- Trooper(){ power = ( rand()%3 ) + 10; }
- Trooper(unsigned int power){ this->power = power; }
- ~Trooper(){ cout << "Trooper with power " << power << " has been destroyed." << endl; }
- // Setter, getter
- void setPower(unsigned int i){ power = i; }
- unsigned int getPower(){ return power; }
- // Methods
- void show(){ cout << "Trooper's power: " << power << endl; }
- };
- // 4. Tank.h (power 15-20)
- class Tank{
- unsigned int power;
- public:
- // Constructors, destructor
- Tank(){ power = ( rand()%6 ) + 15; }
- Tank(unsigned int power){ this->power = power; }
- ~Tank(){ cout << "Tank with power " << power << " has been destroyed." << endl; }
- // Setter, getter
- void setPower(unsigned int i){ power = i; }
- unsigned int getPower(){ return power; }
- // Methods
- void show(){ cout << "Tank's power: " << power << endl; }
- };
- // 5. MythicalHero.h (power 40-50)
- class MythicalHero{
- unsigned int power;
- public:
- // Constructors, destructor
- MythicalHero(){ power = ( rand()%11 ) + 40; }
- MythicalHero(unsigned int power){ this->power = power; }
- ~MythicalHero(){ cout << "MythicalHero with power " << power << " has been destroyed." << endl; }
- // Setter, getter
- void setPower(unsigned int i){ power = i; }
- unsigned int getPower(){ return power; }
- // Methods
- void show(){ cout << "MythicalHero's power: " << power << endl; }
- };
- // Auxiliary Function to create numbers which are near a given number
- int near(int n){
- int prosimo = rand() % 2;
- int apolytiTimi = rand() % 6;
- int apoklisi;
- // If prosimo = 0 then apoklisi = + apoltimi (+ because of 0), else if prosimo is 1, apoklisi = - apoltimi (- because of 1)
- if (prosimo == 0){
- apoklisi = apolytiTimi;
- }
- else{
- apoklisi = -apolytiTimi;
- }
- return (n + apoklisi);
- }
- int main()
- {
- srand(time(NULL));
- // For user's team
- cout << "Give me 5 numbers as the numbers of the 5 different types of fighters." << endl;
- cout << "The 1st, 2nd, 3rd, 4th and 5th number will be for: " << endl;
- cout << "1. Swordsmen, 2. Archers, 3. Troopers, 4. Tanks, 5. MythicalHeroes" << endl << endl << endl;
- unsigned int a1, a2, a3, a4, a5;
- cin >> a1;
- cin >> a2;
- cin >> a3;
- cin >> a4;
- cin >> a5;
- // Creating the 5 types of fighters - Creating Classes' objects
- // 1. For Swordsmen
- Swordsman swo;
- Swordsman v1[a1];
- for(int i=0; i<a1; i++){
- v1[i] = swo;
- }
- // 2. For Archers
- Archer ar;
- Archer v2[a2];
- for(int i=0; i<a2; i++){
- v2[i] = ar;
- }
- // 3. For Troopers
- Trooper tr;
- Trooper v3[a3];
- for(int i=0; i<a3; i++){
- v3[i] = tr;
- }
- // 4. For Tanks
- Tank tan;
- Tank v4[a4];
- for(int i=0; i<a4; i++){
- v4[i] = tan;
- }
- // 5. For MythicalHeroes
- MythicalHero mh;
- MythicalHero v5[a5];
- for(int i=0; i<a5; i++){
- v5[i] = mh;
- }
- cout << endl << "So, you chose your team, which is: " << endl << endl;
- cout << " " << a1 << " Swordsmen with power " << v1[0].getPower() * a1 << " (One swordsman's power = " << v1[0].getPower() << ")" << endl;
- cout << " " << a2 << " Archers with power " << v2[0].getPower() * a2 << " (One archer's power = " << v2[0].getPower() << ")" << endl;
- cout << " " << a3 << " Troopers with power " << v3[0].getPower() * a3 << " (One trooper's power = " << v3[0].getPower() << ")" << endl;
- cout << " " << a4 << " Tanks with power " << v4[0].getPower() * a4 << " (One tank's power = " << v4[0].getPower() << ")" << endl;
- cout << " " << a5 << " MythicalHeroes with power " << v5[0].getPower() * a5 << " (One mythicalHero's power = " << v5[0].getPower() << ")" << endl;
- int POWER1 = v1[0].getPower() * a1 + v2[0].getPower() * a2 + v3[0].getPower() * a3 + v4[0].getPower() * a4 + v5[0].getPower() * a5;
- cout << endl << " " << "WHOLE POWER = " << POWER1 << endl << endl << endl;
- // Creation of the enemy team
- int near1 = near(a1);
- int near2 = near(a2);
- int near3 = near(a3);
- int near4 = near(a4);
- int near5 = near(a5);
- cout << endl << endl << "Enemy team: " << endl;
- cout << " " << near1 << " Swordsmen with power " << v1[0].getPower() * near1 << " (One swordsman's power = " << v1[0].getPower() << ")" << endl;
- cout << " " << near2 << " Archers with power " << v2[0].getPower() * near2 << " (One archer's power = " << v2[0].getPower() << ")" << endl;
- cout << " " << near3 << " Troopers with power " << v3[0].getPower() * near3 << " (One trooper's power = " << v3[0].getPower() << ")" << endl;
- cout << " " << near4 << " Tanks with power " << v4[0].getPower() * near4 << " (One tank's power = " << v4[0].getPower() << ")" << endl;
- cout << " " << near5 << " MythicalHeroes with power " << v5[0].getPower() * near5 << " (One mythicalHero's power = " << v5[0].getPower() << ")" << endl;
- int POWER2 = v1[0].getPower() * near1 + v2[0].getPower() * near2 + v3[0].getPower() * near3 + v4[0].getPower() * near4 + v5[0].getPower() * near5;
- cout << endl << " " << "WHOLE POWER = " << POWER2 << endl << endl;
- // Comparison between the 2 teams
- cout << endl << endl << endl;
- if (POWER1 > POWER2){
- cout << "VICTORY! You won the enemy team!" << endl;
- cout << "Difference in power between the 2 teams: " << POWER1 - POWER2 << endl;
- }
- else{
- cout << "DEFEAT... You lost form the enemy team..." << endl;
- cout << "Difference in power between the 2 teams: " << POWER2 - POWER1 << endl;
- }
- cout << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement