Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- class Player {
- private:
- public:
- // variables
- char *name;
- int level;
- char grade;
- // create new stats and grades
- int str, spd, eva; // new
- char gStr, gSpd, gEva; // new
- // functions
- Player(char g, char *name);
- void levelUp(void);
- void showInfo(void);
- };
- // constructor
- Player::Player(char g, char *n)
- {
- name = n;
- level = 1;
- // assign the new stats
- str = 10; // new
- spd = 10; // new
- eva = 10; // new
- // assign the grades for each stat
- gStr = (char)(rand()%4 + 65); // new
- gSpd = (char)(rand()%4 + 65); // new
- gEva = (char)(rand()%4 + 65); // new
- cout << name << " is created" << endl;
- }
- void Player::levelUp()
- {
- // increment stats based upon each stat
- if (level % (gEva-64) == 0)
- eva += 2; // new
- if (level % (gSpd-64) == 0)
- spd += 2; // new
- if (level % (gStr-64) == 0)
- str += 2; // new
- level++;
- cout << name << " level up!" << endl;
- }
- void Player::showInfo()
- {
- // print player info (with new stats)
- cout << "Name: " << name << " - grade: " << grade << " - level: " << level << " - stats: " << str << ","
- << spd << "," << eva << endl;
- }
- int main()
- {
- // create three players
- Player pA('A', "Player A");
- Player pB('B', "Player B");
- Player pC('C', "Player C");
- cout << endl;
- // alter player A stats
- pA.showInfo();
- pA.levelUp();
- pA.showInfo();
- pA.levelUp();
- pA.showInfo();
- pA.levelUp();
- pA.showInfo();
- cout << endl;
- // alter player B stats
- pB.showInfo();
- pB.levelUp();
- pB.showInfo();
- pB.levelUp();
- pB.showInfo();
- pB.levelUp();
- pB.showInfo();
- cout << endl;
- // alter player C stats
- pC.showInfo();
- pC.levelUp();
- pC.showInfo();
- pC.levelUp();
- pC.showInfo();
- pC.levelUp();
- pC.showInfo();
- return 0;
- }
Add Comment
Please, Sign In to add comment