Advertisement
vovkakorben

pussycat

Dec 24th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #pragma hdrstop
  4.  
  5. #include "cat_class.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8.  
  9. const int min_per_year = 365 * 24 * 60;
  10. tcat::tcat(int m) {
  11.   alive = true;
  12.   age = 0;
  13.   max_age = 10 * min_per_year +
  14.             round(rand() / RAND_MAX * 4 * min_per_year);  // 10-14 years
  15.   hunger = m / 2;
  16.   lucky = m / 2;
  17.  
  18.   hunger_mod = -1;
  19.   lucky_mod = -1;
  20. }
  21.  
  22. void tcat::feed() {
  23.   if (!alive) {
  24.     return;
  25.   }
  26.   feed_timer = 20 + round(rand() / RAND_MAX * 40);  // play time 20..60
  27.   hunger_mod = 12;
  28. }
  29.  
  30. void tcat::play() {
  31.   if (!alive) {
  32.     return;
  33.   }
  34.   play_timer = 10 + round(rand() / RAND_MAX * 10);  // feed time 10..20
  35.   lucky_mod = 12;
  36. }
  37.  
  38. void tcat::step(int n = 1) {
  39.   if (!alive) {
  40.     return;
  41.   }
  42.   age += n;
  43.  
  44.   if (feed_timer > 0) {
  45.     feed_timer -= n;
  46.   } else {
  47.     feed_timer = 0;
  48.     hunger_mod = -1;
  49.   }
  50.  
  51.   if (play_timer > 0) {
  52.     play_timer -= n;
  53.   } else {
  54.     play_timer = 0;
  55.     lucky_mod = -1;
  56.   }
  57.   hunger += hunger_mod * n;
  58.   lucky += lucky_mod * n;
  59.   if (hunger <= 0) {
  60.     alive = false;
  61.   }
  62.   if (lucky <= 10) {
  63.     lucky = 10;
  64.   }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement