Advertisement
MISTERVODKA

Untitled

Dec 8th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. #include <cstring>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. class Student {
  9. private:
  10.     int change_field(int field, int delta);
  11.  
  12.     char name[51];
  13.     char surname[51];
  14.     int hp;
  15.     int iq;
  16.     int energy;
  17.     int sanity;
  18.     int excitement;
  19. public:
  20.     void start_game(char name[51],char surname[51]);
  21.     void setIQ(int iq);
  22.     void setHp(int hp);
  23.     void setNrg(int nrg);
  24.     void setName(char name[51]);
  25.     void setSanity(int sanity);
  26.     void setSurname(char surname[51]);
  27.     void setExcitement(int excitement);
  28.     bool is_alive();
  29.     void show();
  30.     void eat();
  31.     void wait();
  32.     void study();
  33.     void sleep();
  34.     void watch_tv();
  35.  
  36.     int getHp();
  37.     int getIQ();
  38. };
  39.  
  40. int Student::getHp() { return this->hp; }
  41. int Student::getIQ() { return this->iq; }
  42.  
  43. void Student::setIQ(int iq) { this->iq=iq; }
  44. void Student::setNrg(int nrg) { this->energy=nrg; }
  45. void Student::setSanity(int sanity) { this->sanity=sanity; }
  46. void Student::setExcitement(int excitement) { this->excitement=excitement; }
  47. void Student::setHp(int hp) { this->hp=hp; }
  48. void Student::setName(char name[51]) { strcpy(this->name,name); }
  49. void Student::setSurname(char surname[51]) { strcpy(this->surname,surname); }
  50.  
  51. int Student::change_field(int field, int delta)
  52. {
  53.     if(field+delta>=0&&field+delta<=100) return field+delta;
  54.     else if(field+delta<0) return 0;
  55.     else if(field+delta>100) return 100;
  56. }
  57.  
  58. void Student::watch_tv()
  59. {
  60.     if(!is_alive()) return;
  61.     this->hp=this->change_field(this->hp,-2);
  62.     this->energy=this->change_field(this->energy,-3);
  63.     this->iq=this->change_field(this->iq,-3);
  64.     this->sanity=this->change_field(this->sanity,+1);
  65.     this->excitement=this->change_field(this->excitement,+5);
  66. }
  67.  
  68. void Student::sleep()
  69. {
  70.     if(!is_alive()) return;
  71.     this->hp=this->change_field(this->hp,+2);
  72.     this->energy=this->change_field(this->energy,-2);
  73.     this->sanity=this->change_field(this->sanity,+7);
  74. }
  75.  
  76. void Student::study()
  77. {
  78.     if(!is_alive()) return;
  79.     this->hp=this->change_field(this->hp,-2);
  80.     this->energy=this->change_field(this->energy,-4);
  81.     this->iq=this->change_field(this->iq,+5);
  82.     this->sanity=this->change_field(this->sanity,-5);
  83.     this->excitement=this->change_field(this->excitement,-2);
  84. }
  85.  
  86. void Student::eat()
  87. {
  88.     if(!is_alive()) return;
  89.     this->hp=this->change_field(this->hp,+1);
  90.     this->energy=this->change_field(this->energy,7);
  91.     this->iq=this->change_field(this->iq,-1);
  92.     this->excitement=this->change_field(this->excitement,-2);
  93. }
  94.  
  95. void Student::wait()
  96. {
  97.     if(!is_alive()) return;
  98.     this->hp=this->change_field(this->hp,+1);
  99.     this->energy=this->change_field(this->energy,-3);
  100.     this->excitement=this->change_field(this->excitement,-3);
  101. }
  102.  
  103. void Student::start_game(char name[51],char surname[51])
  104. {
  105.     Student::setHp(100);
  106.     Student::setName(name);
  107.     Student::setSurname(surname);
  108.     Student::setNrg(100);
  109.     Student::setIQ(20);
  110.     Student::setSanity(100);
  111.     Student::setExcitement(50);
  112. }
  113.  
  114. bool Student::is_alive()
  115. {
  116.     return this->hp>0;
  117. }
  118.  
  119. void Student::show()
  120. {
  121.     cout <<this->name
  122.          <<" "
  123.          <<this->surname
  124.          <<": HP = "
  125.          <<setfill('0')<<setw(3)<<this->hp
  126.          <<", Energy = "
  127.          <<setfill('0')<<setw(3)<<this->energy
  128.          <<", IQ = "
  129.          <<setfill('0')<<setw(3)<<this->iq
  130.          <<", Sanity = "
  131.          <<setfill('0')<<setw(3)<<this->sanity
  132.          <<", Excitement = "
  133.          <<setfill('0')<<setw(3)<<this->excitement
  134.          <<".";
  135.     if(!is_alive()) cout<<" Game over.";
  136.     cout<<endl;
  137. }
  138.  
  139. int main()
  140. {
  141.     char name[51]={}, surname[51]={};
  142.     int n;
  143.     cin>>name>>surname;
  144.     cin>>n;
  145.     Student s;
  146.     s.start_game(name,surname);
  147.     char cmd[11]={};
  148.     char m[2]={};
  149.     cin.getline(m,1);
  150.  
  151.     for(int i=0;i<n;++i)
  152.     {
  153.         cin.getline(cmd,10);
  154.         if(!strcmp(cmd,"Wait")) s.wait();
  155.         else if(!strcmp(cmd,"Eat")) s.eat();
  156.         else if(!strcmp(cmd,"Study")) s.study();
  157.         else if(!strcmp(cmd,"Sleep")) s.sleep();
  158.         else if(!strcmp(cmd,"Watch TV")) s.watch_tv();
  159.  
  160.         s.show();
  161.     }
  162.  
  163.     return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement