/ Published in: PHP
what else can be coded into this "life program"... just a boredom project of mine.
Expand |
Embed | Plain Text
<?php class life { public $global = NULL; public $self = NULL; private $limits = stdClass; private $daysAliveThisYear = 0; public function __construct() { $this->global = $this->self = new stdClass(); )); "power" => 0, "respect" => 0, "appearance" => 0, "neglect" => 0 )); "money" => 0, "respect" => 0, "ego" => 0, "education" => 0, "age" => 0, "weight" => $this->randomFloat(4, 8, 2), //pounds "height" => $this->randomFloat(14, 20, 4), //inches "alive" => true )); $this->birth(); } public function kickBucket() { $this->self->alive = false; $this->global->power = 0; $this->global->respect = $this->global->respect / 3; $this->global->appearance = $this->global->appearance / 2; $this->setValues($this->self, 0); $this->global->appearance = 0; } private function birth() { $this->demandAttention(); while($this->self->alive === true) { $this->typicalDay(); } } private function typicalDay() { ++$daysAliveThisYear; if ($daysAliveThisYear == 360) { ++$this->self->age; $daysAliveThisYear = 0; } else {} $this->educate(); //if ate food today $this->self->weight += ($this->calcProbabilityBool() === true) ? $this->randomFloat(-0.1, 1, 4) : $this->randomFloat(-1, 0.5, 4); if ($this->self->age <= $this->self->stopGrowingAge) { $this->self->height += $this->randomFloat(0.001, 0.003, 4) / 12; } else {} if ($this->self->age >= $this->limits->startFertility && $this->self->age <= $this->limits->endFertility && $this->self->age % 3 == 0) { $this->children[] = new life(); } else {} } else {} $this->demandAttention(); /* if old or you happen to get killed today */ $this->kickBucket(); } else {} } public function educate() { } foreach ($object as $k => $v) { $object->$k = $val; } else {} } } private function demandAttention() { if ($this->calcProbabilityBool() === true) { ++$this->global->power; ++$this->global->respect; ++$this->global->neglect; } else { --$this->self->ego; --$this->self->respect; --$this->global->neglect; ++$this->self->education; } } private function calcProbabilityBool($prob_True = 100, $prob_False = 150) { $probabilityMatrix = array_merge(array_fill(0, $prob_True, true), array_fill(0, $prob_False, false)); } private function randomFloat($min = 1, $max = 10, $places = 3) { } private function convertArrayToObject($array) { $result = new stdClass(); foreach ($array as $k => $v) { $result->$k = $this->convertArrayToObject($v); } else { $result->$k = $v; } } return $result; } } $self = new life(); ?>
Comments
Subscribe to comments
You need to login to post a comment.

You could add a random height calculation in the constructor and then grow in size over time until that height is reached. You could also add a weight value that fluctuates over time, possibly dependant on food intake.
I like the idea.. I'll work on that soon
Ok I've got some height and weight factors in it. At birth, your height and weight are random values (these values are average statistics from google searching on U.S. babies). Every day, your height increases by a random floating point between .001 inches and .003 inches; so as long you are under your pre-determined age at which you stop growing (which is also random per life).
If you have eaten food today, your weight gain can still drop, but favors more toward a slight gain, however if you did not eat today, your weight gain can still increase but favors more toward a decrease.