1: 2:
3: class Yogi extends Bear {
4: public $hasBasket;
5: public $rangerVisible;
6:
7: public function __construct() {
8: parent::__construct('Yogi');
9: $this->hasBasket = false;
10: $this->rangerVisible = true;
11: }
12:
13: public function act() {
14: if($this->hasBasket) {
15: while($this->rangerVisible === true) {
16: $this->run();
17: }
18: $this->eat('Basket');
19: } else {
20: if($this->rangerVisible === false) {
21: $this->shit();
22: }
23: $this->searchBasket();
24: }
25: }
26:
27: private function run() {
28: if(rand(0, 2) == 1) {
29: $this->rangerVisible = false;
30: }
31: }
32:
33: private function searchBasket() {
34: if(rand(0, 10) == 1) {
35: $this->hasBasket = true;
36: }
37: }
38: } 39:
40: class Bear {
41: private $name;
42: private $stomach;
43:
44: public function __construct($name) {
45: $this->name = &$name;
46: $this->stomach = array();
47: }
48:
49: protected function eat($what) {
50: $this->stomach[] = &$what;
51: }
52:
53: protected function shit() {
54: array_shift($this->stomach);
55: }
56:
57: protected function spew() {
58: array_pop($this->stomach);
59: }
60: }