Guest User

Untitled

a guest
Nov 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. class Human {
  3.  
  4. var $heartBeat;// bool hearth beating (true -> live, false -> dead)
  5. var $weight;
  6. var $energy;
  7. var $dialyCalories;
  8.  
  9. function __construct($heartBeat)
  10. {
  11. $this->heartBeat = $heartBeat;
  12. $this->weight = 3500; // weight when born
  13. $this->energy = 50; //energy
  14. $this->dialyCalories = 20;//statr calories
  15. }
  16.  
  17. function is_alive()
  18. {
  19. return $this->heartBeat;
  20. }
  21.  
  22. function dead()
  23. {
  24. $this->heartBeat = false;
  25. }
  26.  
  27. function get_energy()
  28. {
  29. return $this->energy;
  30. }
  31.  
  32. function eat()
  33. {
  34. $this->weight += 300;
  35. $this->dialyCalories += 700;
  36. $this->energy += 10;
  37. }
  38.  
  39. function drink()
  40. {
  41. $this->weight += 200;
  42. $this->dialyCalories += 10;
  43. $this->energy += 5;
  44. }
  45.  
  46. function sleep()
  47. {
  48. $this->weight -= 300;
  49. $this->dialyCalories -= 2000;
  50. $this->energy += 40;
  51. }
  52.  
  53. function is_hungry()
  54. {
  55. return $this->dialyCalories;
  56. }
  57.  
  58. function stress()
  59. {
  60. $this->energy -= 25;
  61. }
  62.  
  63. function decrease_energy($decreaseFactor)
  64. {
  65. $this->energy -= $decreaseFactor;
  66. }
  67.  
  68. function work()
  69. {
  70. $this->weight -= 300;
  71. $this->dialyCalories -= 500;
  72. $this->energy -= 30;
  73. }
  74.  
  75. function getWeight()
  76. {
  77. return $this->weight;
  78. }
  79. }
  80.  
  81. $one = true;
  82. $two = true;
  83. $tree = true;
  84. $man = new Human(true);
  85.  
  86. while ($man->is_alive())
  87. {
  88. if($man->is_hungry() < 2500)
  89. {
  90. $man->eat();
  91. $man->drink();
  92. }
  93. else
  94. {
  95. $man->sleep();
  96. $man->eat();
  97. $man->drink();
  98. }
  99. $man->work();
  100. $man->stress();
  101.  
  102. if(getWeight() < 40000)
  103. {
  104. if($one)
  105. {
  106. $one = false;
  107. $man->decrease_energy(10);
  108. }
  109. }
  110.  
  111. if(getWeight() < 60000)
  112. {
  113. if($two)
  114. {
  115. $two = false;
  116. $man->decrease_energy(15);
  117. }
  118. }
  119.  
  120. if(getWeight() < 80000)
  121. {
  122. if($tree)
  123. {
  124. $tree = false;
  125. $man->decrease_energy(15);
  126. }
  127. }
  128.  
  129. if(getWeight() > 100000)
  130. {
  131. if($man->get_energy() < 10)
  132. {
  133. $man->dead();
  134. }
  135. }
  136. }
Add Comment
Please, Sign In to add comment