Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #pragma hdrstop
- #include "cat_class.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- const int min_per_year = 365 * 24 * 60;
- tcat::tcat(int m) {
- alive = true;
- age = 0;
- max_age = 10 * min_per_year +
- round(rand() / RAND_MAX * 4 * min_per_year); // 10-14 years
- hunger = m / 2;
- lucky = m / 2;
- hunger_mod = -1;
- lucky_mod = -1;
- }
- void tcat::feed() {
- if (!alive) {
- return;
- }
- feed_timer = 20 + round(rand() / RAND_MAX * 40); // play time 20..60
- hunger_mod = 12;
- }
- void tcat::play() {
- if (!alive) {
- return;
- }
- play_timer = 10 + round(rand() / RAND_MAX * 10); // feed time 10..20
- lucky_mod = 12;
- }
- void tcat::step(int n = 1) {
- if (!alive) {
- return;
- }
- age += n;
- if (feed_timer > 0) {
- feed_timer -= n;
- } else {
- feed_timer = 0;
- hunger_mod = -1;
- }
- if (play_timer > 0) {
- play_timer -= n;
- } else {
- play_timer = 0;
- lucky_mod = -1;
- }
- hunger += hunger_mod * n;
- lucky += lucky_mod * n;
- if (hunger <= 0) {
- alive = false;
- }
- if (lucky <= 10) {
- lucky = 10;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement