1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
| <?php
abstract class building
{
var $id;
var $name;
var $description;
var $cost;
var $city_id;
var $cityHandler;
function addAction($id)
{
// Action : Nom, Description, Ce qui est affiché, Conditions, Pour qui ?
}
abstract function onConstructionStarted(); // A faire dans la ville quand construction commencée
abstract function onConstructionFinished(); // A faire dans la ville quand construction terminée
abstract function onDestruction();
}
class bank extends building
{
function __construct($id, $city_id)
{
$this->id = $id;
$this->city_id = $city_id;
$this->name = "Banque";
$this->description = "Une superbe banque";
$this->cost['pts'] = 100;
$this->cityHandler = cityHandler::getInstance();
}
function onConstructionStarted()
{
return;
}
function onConstructionFinished()
{
print('Banque construite !');
}
function onDestruction()
{
return;
}
}
class city
{
var $id;
var $name;
var $action; // Actions possible dans la ville, liées à la ville ?
var $offres; // Emplois
var $_events; // Flux d'informations ?
var $_buildings; // Batiments
var $_hooks; // Hooks
function __construct($id)
{
$this->id = $id;
$this->load();
$this->updateBuildings();
}
function load()
{
global $db;
$qry_loadHooks = $db->prepare("SELECT * FROM city_hooks");
$qry_loadHooks->execute();
while($row = $qry_loadHooks->fetch(PDO::FETCH_ASSOC))
{
$this->_hooks[$row['category']][] = $row['name'];
}
// Buildings
/*$qry_loadBuildings = $db->prepare("SELECT * FROM city_buildings");
$qry_loadBuildings->execute();
while($row = $qry_loadBuildings->fetch(PDO::FETCH_ASSOC))
{
//buildingManager::getBuildingClass($building_id)
}*/
$this->_buildings[] = new bank(1, $this->id);
}
function addEvent($text)
{
$this->_events[] = $text;
}
function isConstructionFinished()
{
return true;
}
function updateBuildings()
{
foreach($this->_buildings as $building)
{
foreach ($this->_hooks['buildings'] as $hookName)
{
if(is_callable(array($building, 'on'.$hookName)) && is_callable(array($this, 'is'.$hookName)))
{
if(call_user_func(array($this, 'is'.$hookName)) == true)
{
call_user_func(array($building, 'on'.$hookName));
}
}
}
}
}
}
class cityHandler
{
/**
* @var Singleton
* @access private
* @static
*/
private static $instance = null;
static $cities = null;
private function __construct()
{
global $db;
if(self::$instance == null)
{
$query_load = $db->prepare("SELECT id FROM city");
$query_load->execute();
while($row = $query_load->fetch(PDO::FETCH_ASSOC))
{
$this->cities[$row['id']] = new city($row['id']);
}
}
}
public static function getInstance()
{
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
}
public function addEvent($text, $city_id)
{
$this->cities[$city_id]->addEvent($text);
}
public function getCity($city_id)
{
return $this->cities[$city_id];
}
public function __clone()
{
trigger_error('Tentative de clonage', E_USER_ERROR);
}
}
?> |
Partager