Ganz einfach! Mit diesem PHP-Script!
< ?php /** * Kitchen.php * * PHP version 5 * * @category Dopshouse * @package Kitchen * @subpackage None * @author Michael Streb <kontakt@michael-streb.de> * @copyright 2010 Michael Streb * @license commercial http://www.michael-streb.de * @version not versioned * @link http://www.michael-streb.com */ /** * Dopshouse_Kitchen * * @category Dopshouse * @package Kitchen * @subpackage None * @author Michael Streb <kontakt @michael-streb.de> * @copyright 2010 Michael Streb * @license commercial http://www.michael-streb.de * @version not versioned * @link http://www.michael-streb.com */ class Dopshouse_Kitchen { /** * The user who uses the kitchen. * * @var Dopshouse_User */ protected $_user; /** * Is the the kitchen in use? * * @var boolean */ protected $_inUse = false; /** * The constructor is loaded when a user enters the kitchen. * * @param Dopshouse_User $user */ public function __construct(Dopshouse_User $user) { $this->_user = $user; $this->_inUse = true; } /** * The destructor is called when the user leaves the kitchen. */ public function __destruct() { $this->checkStatus(); $this->_inUse = false; } /** * Enables the user to prepare fresh coffee. * * @return boolean */ public function prepareCoffee() { // Get coffee machine instance. $coffeeMachine = Dopshouse_Kitchen_Factory::getCoffeeMachineInstance(); // Check the status of the coffee machine. foreach ($coffeeMachine->getStatusArray() as $statusId => $status) { switch ($status) { case 'emptyWaterBucket': $coffeeMachine->fillUpWater($this->_user, Dopshouse_Facility::getWater(1.5)); break; case 'emptyCoffeeBeanBunker': $coffeeMachine->fillUpCoffeeBeans($this->_user, Dopshouse_Facility::getCoffeeBeans(300)); break; default: $coffeCup = Dopshouse_Kitchen_Factory::getCup(); } // Insert cup into coffee machine $coffeeMachine->insertCup($this->_user, $coffeCup); // Push the button of the wiched coffee $coffeeMachine->pushButton($this->_user, $this->_user->getMood()); // Take the cup out of the machine $coffeeMachine->removeCup($this->_user); } return true; } /** * Enables the user to get delicious tea. * * @return boolean */ public function prepareTea() { // Get instance of water boiler $waterBoiler = Dopshouse_Kitchen_Factory::getWaterBoiler(); // Get a cup $teaCup = Dopshouse_Kitchen_Factory::getCup(); // Check if enogth water is in the boiler if ($waterBoiler->fillUpStatus < ($teaCup->getSize() + 100)) { $waterBoiler->fillUpWater($this->_user, Dopshouse_Facility::getWater($teaCup->getSize() + 100)); } // Switch on the boiler $waterBoiler->start(); // Do some other stuff while the water is comming to boile. while ($waterBoiler->isBoiling()) { $this->checkStatus(); } // Insert a tea bag into the cup. $teaCup->insertTeabag($this->_user, Dopshouse_Kitchen_Factory::getTeaBag($this->_user->getMood())); $teaCup->insertWater($this->_user, $waterBoiler->getWater()); return true; } /** * Match the kitchen against the prototype (the image above). * * @return boolen */ public function checkStatus() { if ($this !== Dopshouse_Facility::getKitchenPrototype()) { $this->cleanUp(); } return true; } /** * Cleans up the kitchen and makes it look like the prototype. * * @return true */ public function cleanUp() { // Get lug instance. $lug = Dopshouse_Facility::getLug(); // Cleanup liquids. $lug->removeLiquids($this->_user); // Cleanup crumbs. $lug->removeCrumbs($this->_user); // Cleanup other stuff that could not be defined any more. $lug->cleanupResidualWaste($this->_user); // Check the kitchen status again. $this->checkStatus(); } } ?> </kontakt>
(Der Code stammt von (Michael Streb)