Your browser must have JavaScript enabled in order to view this page.
 >  >
 
Welcome Guest#215 Login/register    Go to Bottom
Go to Top

Source for file DpDrink.php

Documentation is available at DpDrink.php

  1. <?php
  2. /**
  3.  * A common drink which can be turned into beers, wine, etc.
  4.  *
  5.  * DutchPIPE version 0.4; PHP version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
  8.  * If you did not receive a copy of the DutchPIPE license, you can obtain one at
  9.  * http://dutchpipe.org/license/1_0.txt or by sending a note to
  10.  * license@dutchpipe.org, in which case you will be mailed a copy immediately.
  11.  *
  12.  * @package    DutchPIPE
  13.  * @subpackage dpuniverse_std
  14.  * @author     Lennert Stock <ls@dutchpipe.org>
  15.  * @copyright  2006, 2007 Lennert Stock
  16.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  17.  * @version    Subversion: $Id: DpDrink.php 278 2007-08-19 22:52:25Z ls $
  18.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  19.  * @see        DpObject
  20.  */
  21.  
  22. /**
  23.  * Builts upon the standard DpObject class
  24.  */
  25. inherit(DPUNIVERSE_STD_PATH 'DpObject.php');
  26.  
  27. /**
  28.  * A common drink which can be turned into beers, wine, etc.
  29.  *
  30.  * Creates the following DutchPIPE properties:<br />
  31.  *
  32.  * - boolean <b>isFull</b> - Set to TRUE
  33.  * - boolean <b>isDrink</b> - Set to TRUE
  34.  * - boolean <b>isNoSell</b> - Set to TRUE
  35.  * - string <b>emptyTitle</b> - Title for empty drink
  36.  * - string <b>emptyTitleDefinite</b> - Definite title for empty drink
  37.  * - string <b>emptyTitleIndefinite</b> - Indefinite title for empty drink
  38.  * - string <b>emptyTitleImg</b> - Image for empty drink
  39.  * - array <b>emptyIds</b> - Id strings for empty drink
  40.  * - array <b>origIds</b> - Id strings for filled drink
  41.  * - string <b>origTitle</b> - Title for filled drink
  42.  * - string <b>origTitleImg</b> - Image for filled drink
  43.  * - string <b>origBody</b> - Body for filled drink
  44.  *
  45.  * @package    DutchPIPE
  46.  * @subpackage dpuniverse_std
  47.  * @author     Lennert Stock <ls@dutchpipe.org>
  48.  * @copyright  2006, 2007 Lennert Stock
  49.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  50.  * @version    Release: 0.2.1
  51.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  52.  * @see        DpObject
  53.  */
  54. final class DpDrink extends DpObject
  55. {
  56.     /**
  57.      * Creates this drink object
  58.      *
  59.      * Called by DpDrink when this object is created. Adds standard actions
  60.      * which can be performed on this object.
  61.      *
  62.      * Calls {@link createDpDrink()} in the inheriting class.
  63.      *
  64.      * @access     private
  65.      * @see        createDpDrink()
  66.      */
  67.     final function createDpObject()
  68.     {
  69.         $this->addId(dp_text('bottle'));
  70.  
  71.         $this->isFull new_dp_property(TRUE);
  72.         $this->isDrink new_dp_property(TRUE);
  73.         $this->isNoSell new_dp_property(TRUE);
  74.         $this->emptyTitle new_dp_property(dp_text('empty bottle'));
  75.         $this->emptyTitleDefinite new_dp_property(
  76.             dp_text('the empty bottle'));
  77.         $this->emptyTitleIndefinite new_dp_property(
  78.             dp_text('an empty bottle'));
  79.         $this->emptyTitleImg new_dp_property(NULL);
  80.         $this->emptyIds =
  81.             new_dp_property(explode('#'dp_text('bottle#empty bottle')));
  82.         $this->emptyBody new_dp_property($this->emptyTitleIndefinite);
  83.  
  84.         $this->origIds new_dp_property(NULL);
  85.         $this->origTitle new_dp_property(NULL);
  86.         $this->origTitleImg new_dp_property(NULL);
  87.         $this->origBody new_dp_property(NULL);
  88.  
  89.         $this->addAction(dp_text('drink')dp_text('drink')'actionDrink',
  90.             DP_ACTION_AUTHORIZED_ALLDP_ACTION_SCOPE_ALL);
  91.  
  92.         if (WEIGHT_TYPE_NONE !== WEIGHT_TYPE{
  93.             $this->coinherit(DPUNIVERSE_STD_PATH 'mass.php');
  94.             if (WEIGHT_TYPE_ABSTRACT === WEIGHT_TYPE{
  95.                 $this->weight 1;
  96.             elseif (WEIGHT_TYPE_METRIC === WEIGHT_TYPE{
  97.                 $this->weight 100/* Grams */
  98.             elseif (WEIGHT_TYPE_USA === WEIGHT_TYPE{
  99.                 $this->weight 3.5/* Ounces */
  100.             }
  101.         }
  102.  
  103.         if (VOLUME_TYPE_NONE !== VOLUME_TYPE{
  104.             $this->coinherit(DPUNIVERSE_STD_PATH 'mass.php');
  105.             if (VOLUME_TYPE_ABSTRACT === VOLUME_TYPE{
  106.                 $this->volume 1;
  107.             elseif (VOLUME_TYPE_METRIC === VOLUME_TYPE{
  108.                 $this->volume 33;
  109.             elseif (VOLUME_TYPE_USA === VOLUME_TYPE{
  110.                 $this->volume 11.3;
  111.             }
  112.         }
  113.  
  114.         $this->value 10;
  115.         $this->createDpDrink();
  116.     }
  117.  
  118.     /**
  119.      * Sets this drink object up at the time it is created
  120.      *
  121.      * An empty function which can be redefined by the drink object extending on
  122.      * DpDrink. When the object is created, it has no title, HTML body, et
  123.      * cetera, so in this method methods like {@link DpObject::setTitle()} are
  124.      * called.
  125.      *
  126.      * @see        resetDpDrink()
  127.      */
  128.     function createDpDrink()
  129.     {
  130.     }
  131.  
  132.     /**
  133.      * Resets this drink object
  134.      *
  135.      * Called by DpObject at regular intervals as defined in dpuniverse-ini.php.
  136.      * Calls the method 'resetDpDrink' in this drink object. You can redefine
  137.      * that function to periodically do stuff such as alter the state of this
  138.      * drink object.
  139.      *
  140.      * @access     private
  141.      * @see        resetDpDrink()
  142.      */
  143.     final function resetDpObject()
  144.     {
  145.         $this->resetDpDrink();
  146.     }
  147.  
  148.     /**
  149.      * Resets this drink object
  150.      *
  151.      * Called by this drink object at regular intervals as defined in
  152.      * dpuniverse-ini.php. An empty function which can be redefined by the
  153.      * drink object extending on DpDrink. To be used to periodically do stuff
  154.      * such as alter the state of the drink object.
  155.      *
  156.      * @see        createDpDrink()
  157.      */
  158.     function resetDpDrink()
  159.     {
  160.     }
  161.  
  162.  
  163.     /**
  164.      * Fill or empty the drink
  165.      *
  166.      * Adjusts the drink's appearance and behaviour. Without an argument,
  167.      * fills the drink. Drink objects are filled by default after being created.
  168.      *
  169.      * Drink objects which are filled have the property "isFull" set to TRUE in
  170.      * them.
  171.      *
  172.      * @param      string    $isFull     TRUE to fill, FALSE to empty drink
  173.      */
  174.     public function setFull($isFull TRUE)
  175.     {
  176.         if (FALSE === $isFull{
  177.             $this->setIds($this->emptyIds);
  178.             $this->setTitle($this->emptyTitle);
  179.             $this->setTitleDefinite($this->emptyTitleDefinite);
  180.             $this->setTitleIndefinite($this->emptyTitleIndefinite);
  181.             $this->setTitleImg($this->emptyTitleImg);
  182.             $this->setBody($this->emptyBody);
  183.             $this->isFull FALSE;
  184.             $this->isNoSell FALSE;
  185.         else {
  186.             $this->setIds($this->origIds);
  187.             $this->setTitle($this->origTitle);
  188.             $this->setTitleDefinite($this->origTitleDefinite);
  189.             $this->setTitleIndefinite($this->origTitleIndefinite);
  190.             $this->setTitleImg($this->origTitleImg);
  191.             $this->setBody($this->origBody);
  192.             $this->isFull TRUE;
  193.             $this->isNoSell TRUE;
  194.         }
  195.     }
  196.  
  197.     /**
  198.      * Makes a living object drink this object
  199.      *
  200.      * Drinks the drink if $noun is a valid id for this drink and the drink is
  201.      * "full".
  202.      *
  203.      * @param   string  $verb       the action, "drink"
  204.      * @param   string  $noun       what to drink, could be empty
  205.      * @return  boolean TRUE for action completed, FALSE otherwise
  206.      */
  207.     public function actionDrink($verb$noun)
  208.     {
  209.         $user get_current_dpobject();
  210.         if (empty($noun)) {
  211.             $user->setActionFailure(
  212.                 dp_text('What do you want to drink?<br />'));
  213.             return FALSE;
  214.         }
  215.  
  216.         if (FALSE !== ($env $this->getEnvironment())
  217.                 && $env->isPresent($noun!== $this{
  218.             $user->setActionFailure(sprintf(dp_text("You can't drink: %s<br />"),
  219.                 $noun));
  220.             return FALSE;
  221.         }
  222.  
  223.         if ($env !== $user{
  224.             $user->tell(dp_text('You must pick it up first.<br />'));
  225.             return TRUE;
  226.         }
  227.         if (FALSE === $this->isFull{
  228.             $user->tell(ucfirst(sprintf(dp_text('%s is empty.<br />'),
  229.                 $this->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE))));
  230.             return TRUE;
  231.         }
  232.  
  233.         $this->origIds $this->getIds();
  234.         $this->origTitle $this->getTitle();
  235.         $this->origTitleImg $this->getTitleImg();
  236.         $this->origBody $this->getBody();
  237.  
  238.         if (FALSE !== ($env $user->getEnvironment())) {
  239.             $env->tell(ucfirst(sprintf(dp_text('%s drinks %s.<br />'),
  240.                 $user->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE),
  241.                 $this->getTitle(DPUNIVERSE_TITLE_TYPE_INDEFINITE))),
  242.                 $user);
  243.             $env->tell('<window autoclose="2500" styleclass="dpwindow_drink">'
  244.                 . '<h1>' dp_text('BUUUUUUUUUUUUUURRRP!''</h1></window>',
  245.                 $user);
  246.         }
  247.  
  248.         $user->tell(sprintf(dp_text('You drink %s.<br />'),
  249.             $this->getTitle(DPUNIVERSE_TITLE_TYPE_INDEFINITE)));
  250.         $user->tell('<window autoclose="2500" styleclass="dpwindow_drink">'
  251.             . '<h1>' dp_text('BUUUUUUUUUUUUUURRRP!''</h1></window>');
  252.         $this->setFull(FALSE);
  253.         $env->tell(array('abstract' =>
  254.             '<changeDpElement id="'
  255.             . $this->getUniqueId('">'
  256.             . $this->getAppearance(1FALSE'</changeDpElement>',
  257.             'graphical' => '<changeDpElement id="'
  258.             . $this->getUniqueId('">'
  259.             . $this->getAppearance(1FALSE$this'graphical')
  260.             . '</changeDpElement>'));
  261.         return TRUE;
  262.     }
  263.  
  264.     /**
  265.      * Prevents insertion into containers, not used yet
  266.      *
  267.      * @return  boolean     TRUE if this drink can't be inserted, FALSE to allow
  268.      *                       insertion
  269.      * @ignore
  270.      */
  271.     function preventInsert()
  272.     {
  273.         if (FALSE === $this->isFull{
  274.             return FALSE;
  275.         }
  276.  
  277.         if (get_current_dpobject()) {
  278.             get_current_dpobject()->tell(
  279.                 dp_text('You would spill it out.<br />'));
  280.         }
  281.         return TRUE;
  282.     }
  283. }
  284.  
  285. ?>

Documentation generated on Mon, 03 Sep 2007 22:19:14 +0200 by phpDocumentor 1.3.0RC6

Click me!
Guest#215
 
 
 
  Go to Top
 
 
Input Field OptionsClose Input Field Go to Top
 
Legal Notices | Copyright © 2006, 2007 Lennert Stock. All rights reserved. Last update: Mon Sep 03 2007, 21:50 CET.