Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- #include <cstring>
- #include <iomanip>
- using namespace std;
- class Student {
- private:
- int change_field(int field, int delta);
- char name[51];
- char surname[51];
- int hp;
- int iq;
- int energy;
- int sanity;
- int excitement;
- public:
- void start_game(char name[51],char surname[51]);
- void setIQ(int iq);
- void setHp(int hp);
- void setNrg(int nrg);
- void setName(char name[51]);
- void setSanity(int sanity);
- void setSurname(char surname[51]);
- void setExcitement(int excitement);
- bool is_alive();
- void show();
- void eat();
- void wait();
- void study();
- void sleep();
- void watch_tv();
- int getHp();
- int getIQ();
- };
- int Student::getHp() { return this->hp; }
- int Student::getIQ() { return this->iq; }
- void Student::setIQ(int iq) { this->iq=iq; }
- void Student::setNrg(int nrg) { this->energy=nrg; }
- void Student::setSanity(int sanity) { this->sanity=sanity; }
- void Student::setExcitement(int excitement) { this->excitement=excitement; }
- void Student::setHp(int hp) { this->hp=hp; }
- void Student::setName(char name[51]) { strcpy(this->name,name); }
- void Student::setSurname(char surname[51]) { strcpy(this->surname,surname); }
- int Student::change_field(int field, int delta)
- {
- if(field+delta>=0&&field+delta<=100) return field+delta;
- else if(field+delta<0) return 0;
- else if(field+delta>100) return 100;
- }
- void Student::watch_tv()
- {
- if(!is_alive()) return;
- this->hp=this->change_field(this->hp,-2);
- this->energy=this->change_field(this->energy,-3);
- this->iq=this->change_field(this->iq,-3);
- this->sanity=this->change_field(this->sanity,+1);
- this->excitement=this->change_field(this->excitement,+5);
- }
- void Student::sleep()
- {
- if(!is_alive()) return;
- this->hp=this->change_field(this->hp,+2);
- this->energy=this->change_field(this->energy,-2);
- this->sanity=this->change_field(this->sanity,+7);
- }
- void Student::study()
- {
- if(!is_alive()) return;
- this->hp=this->change_field(this->hp,-2);
- this->energy=this->change_field(this->energy,-4);
- this->iq=this->change_field(this->iq,+5);
- this->sanity=this->change_field(this->sanity,-5);
- this->excitement=this->change_field(this->excitement,-2);
- }
- void Student::eat()
- {
- if(!is_alive()) return;
- this->hp=this->change_field(this->hp,+1);
- this->energy=this->change_field(this->energy,7);
- this->iq=this->change_field(this->iq,-1);
- this->excitement=this->change_field(this->excitement,-2);
- }
- void Student::wait()
- {
- if(!is_alive()) return;
- this->hp=this->change_field(this->hp,+1);
- this->energy=this->change_field(this->energy,-3);
- this->excitement=this->change_field(this->excitement,-3);
- }
- void Student::start_game(char name[51],char surname[51])
- {
- Student::setHp(100);
- Student::setName(name);
- Student::setSurname(surname);
- Student::setNrg(100);
- Student::setIQ(20);
- Student::setSanity(100);
- Student::setExcitement(50);
- }
- bool Student::is_alive()
- {
- return this->hp>0;
- }
- void Student::show()
- {
- cout <<this->name
- <<" "
- <<this->surname
- <<": HP = "
- <<setfill('0')<<setw(3)<<this->hp
- <<", Energy = "
- <<setfill('0')<<setw(3)<<this->energy
- <<", IQ = "
- <<setfill('0')<<setw(3)<<this->iq
- <<", Sanity = "
- <<setfill('0')<<setw(3)<<this->sanity
- <<", Excitement = "
- <<setfill('0')<<setw(3)<<this->excitement
- <<".";
- if(!is_alive()) cout<<" Game over.";
- cout<<endl;
- }
- int main()
- {
- char name[51]={}, surname[51]={};
- int n;
- cin>>name>>surname;
- cin>>n;
- Student s;
- s.start_game(name,surname);
- char cmd[11]={};
- char m[2]={};
- cin.getline(m,1);
- for(int i=0;i<n;++i)
- {
- cin.getline(cmd,10);
- if(!strcmp(cmd,"Wait")) s.wait();
- else if(!strcmp(cmd,"Eat")) s.eat();
- else if(!strcmp(cmd,"Study")) s.study();
- else if(!strcmp(cmd,"Sleep")) s.sleep();
- else if(!strcmp(cmd,"Watch TV")) s.watch_tv();
- s.show();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement