Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class Student {
- private:
- char name[51]{};
- char surname[51]{};
- int oldhp;
- int oldenergy;
- int oldiq;
- int oldsanity;
- int oldexcitement;
- void change_field(int& field, int delta)
- {
- field += delta;
- if (field > 100) {
- field = 100;
- }
- if (field < 0) {
- field = 0;
- }
- }
- void change_params(int hp, int energy, int iq, int sanity, int excitement) {
- change_field(oldhp, hp);
- change_field(oldenergy, energy);
- change_field(oldiq, iq);
- change_field(oldsanity, sanity);
- change_field(oldexcitement, excitement);
- }
- public:
- Student() {
- cin >> name >> surname;
- oldhp = 100;
- oldenergy = 100;
- oldiq = 20;
- oldsanity = 100;
- oldexcitement = 50;
- }
- Student(char* name, char *surname) {
- oldhp = 100;
- oldenergy = 100;
- oldiq = 20;
- oldsanity = 100;
- oldexcitement = 50;
- }
- bool isAlive() {
- if (oldhp > 0) return true;
- else return false;
- }
- void show() {
- cout << name << " " << surname << ": HP = " << setw(3) << setfill('0') << hp
- << ", Energy = " << setw(3) << setfill('0') << energy
- << ", IQ = " << setw(3) << setfill('0') << iq
- << ", Sanity = " << setw(3) << setfill('0') << sanity
- << ", Excitement = " << setw(3) << setfill('0') << excitement << ".";
- if (!is_alive()) {
- cout << " Game over.";
- }
- cout << endl;
- }
- void eat() {
- if (!isAlive()) return;
- else change_params(1, 7, -1, 0, -2);
- }
- void wait() {
- if (!isAlive()) return;
- else change_params(1, -3, 0, 0, -3);
- }
- void study() {
- if (!isAlive()) return;
- else change_params(-2, -4, 5, -5, -2);
- }
- void sleep() {
- if (!isAlive()) return;
- else change_params(2,-2, 0, 7, 0);
- }
- void watchTV() {
- if (!isAlive()) return;
- else change_params(-2, -3, -3, 1, 5);
- }
- };
- int main() {
- Student student;
- int cmdCount;
- cin >> cmdCount;
- string cmd;
- for (int i = 0; i < cmdCount; i++) {
- cin >> cmd;
- if (cmd == "Eat") student.eat();
- else if (cmd == "Wait") student.wait();
- else if (cmd == "Study") student.study();
- else if (cmd == "Sleep") student.sleep();
- else if (cmd == "Watch TV") student.watchTV();
- student.show();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement