Show State.php syntax highlighted
<?php
/**
* @internal
* Quantum Game Library
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the text file LICENSE located in the root
* directory of this library.
* It is also available through the internet at this URL:
* http://doc.astrumfutura.com/license.html
*
* If you did not receive a copy of the license and are unable to
* obtain it through the internet, please send an email
* to license@astrumfutura.com so we can send you a copy.
*
* @package State
* @category AI
* @copyright Copyright (c) 2007 The QGL Group (refer to COPYRIGHT file)
* @version $Id: State.php 210 2007-02-03 02:55:49Z santosj $
* @license http://doc.astrumfutura.com/license.html New BSD License
*/
/** Quantum_State_Abstract */
require_once 'Quantum/State/Abstract.php';
/**
* The cutesy way of managing States, for a more sane method, use the
* Quantum_State_Abstract and extend it for your finite states.
*
* @package State
* @category AI
* @author Jacob Santos (http://www.santosj.name)
*/
class Quantum_State
extends Quantum_State_Abstract
{
private $states = array();
private function __clone()
{
// Forbid cloning
}
public function append(Quantum_State_Transition $transition)
{
$name = $transition->getState();
$this->states[$name] = $transition;
}
/**
* process() - Processing will stop at the first completed action.
*
* If you need to handle more than one condition, then you'll need to be
* more specific in what classes you use.
*
*/
public function process()
{
foreach($this->states as $transition)
{
if($transition->execute($this->value) === true)
{
break;
}
}
}
}
See more files for this project here