Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Human {
- var $heartBeat;// bool hearth beating (true -> live, false -> dead)
- var $weight;
- var $energy;
- var $dialyCalories;
- function __construct($heartBeat)
- {
- $this->heartBeat = $heartBeat;
- $this->weight = 3500; // weight when born
- $this->energy = 50; //energy
- $this->dialyCalories = 20;//statr calories
- }
- function is_alive()
- {
- return $this->heartBeat;
- }
- function dead()
- {
- $this->heartBeat = false;
- }
- function get_energy()
- {
- return $this->energy;
- }
- function eat()
- {
- $this->weight += 300;
- $this->dialyCalories += 700;
- $this->energy += 10;
- }
- function drink()
- {
- $this->weight += 200;
- $this->dialyCalories += 10;
- $this->energy += 5;
- }
- function sleep()
- {
- $this->weight -= 300;
- $this->dialyCalories -= 2000;
- $this->energy += 40;
- }
- function is_hungry()
- {
- return $this->dialyCalories;
- }
- function stress()
- {
- $this->energy -= 25;
- }
- function decrease_energy($decreaseFactor)
- {
- $this->energy -= $decreaseFactor;
- }
- function work()
- {
- $this->weight -= 300;
- $this->dialyCalories -= 500;
- $this->energy -= 30;
- }
- function getWeight()
- {
- return $this->weight;
- }
- }
- $one = true;
- $two = true;
- $tree = true;
- $man = new Human(true);
- while ($man->is_alive())
- {
- if($man->is_hungry() < 2500)
- {
- $man->eat();
- $man->drink();
- }
- else
- {
- $man->sleep();
- $man->eat();
- $man->drink();
- }
- $man->work();
- $man->stress();
- if(getWeight() < 40000)
- {
- if($one)
- {
- $one = false;
- $man->decrease_energy(10);
- }
- }
- if(getWeight() < 60000)
- {
- if($two)
- {
- $two = false;
- $man->decrease_energy(15);
- }
- }
- if(getWeight() < 80000)
- {
- if($tree)
- {
- $tree = false;
- $man->decrease_energy(15);
- }
- }
- if(getWeight() > 100000)
- {
- if($man->get_energy() < 10)
- {
- $man->dead();
- }
- }
- }
Add Comment
Please, Sign In to add comment