class_BaseShip.php

Go to the documentation of this file.
00001 <?php
00024 class BaseShip extends BaseSimulator {
00025         // Name des Shipes
00026         private $shipName   = "Unbekanntes Schiff";
00027 
00028         // Anzahl Anker
00029         private $numAnchor  = 0;
00030 
00031         // Tiefgang in Meter
00032         private $draught    = 0;
00033 
00034         // Besatzung-Objekte
00035         private $crewList   = null;
00036 
00037         // Aufbauten-Objekte
00038         private $structures = null;
00039 
00040         // Namenloses Ship generieren
00041         protected function __construct($className) {
00042                 // Call parent constructor
00043                 parent::__construct($className);
00044 
00045                 // Prepare array object for all structures
00046                 $this->createStructuresArray();
00047 
00048                 // Clean-up a little
00049                 $this->removePartInstance();
00050         }
00051 
00052         // Array-Objekt anlegen
00053         private function createStructuresArray () {
00054                 $this->structures = new FrameworkArrayObject("FakedShipStructures");
00055         }
00056 
00057         // Schiffsteil generieren (kann alles sein)
00058         // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!)
00059         // partClass = Das zu konstruierende Schiffsteil
00060         public function createShipPart (ConstructableShipPart $buildInstance, $partClass) {
00061                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> erh&auml;lt ein neues Schiffsteil (%s).",
00062                         __CLASS__,
00063                         __LINE__,
00064                         $this->getShipName(),
00065                         $partClass
00066                 ));
00067 
00068                 // Ist die gewuenschte Klasse vorhanden?
00069                 if (!class_exists($partClass)) {
00070                         // Nicht vorhanden, dann Ausnahme werfen!
00071                         throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND);
00072                 } // END - if
00073 
00074                 // Get an instance back from our object factory
00075                 $partInstance = ObjectFactory::createObjectByName($partClass);
00076 
00077                 // Das Einbauen versuchen...
00078                 try {
00079                         $partInstance->addShipPartToShip($this, $buildInstance);
00080                 } catch (MotorShipMismatchException $e) {
00081                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Motor erhalten! Grund: <strong>%s</strong>",
00082                                 __CLASS__,
00083                                 __LINE__,
00084                                 $this->getShipName(),
00085                                 $e->getMessage()
00086                         ));
00087                         return false;
00088                 } catch (RoomShipMismatchException $e) {
00089                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keinen Maschinenraum erhalten! Grund: <strong>%s</strong>",
00090                                 __CLASS__,
00091                                 __LINE__,
00092                                 $this->getShipName(),
00093                                 $e->getMessage()
00094                         ));
00095                         return false;
00096 
00097                 } catch (StructureShipMismatchException $e) {
00098                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Aufbauten erhalten! Grund: <strong>%s</strong>",
00099                                 __CLASS__,
00100                                 __LINE__,
00101                                 $this->getShipName(),
00102                                 $e->getMessage()
00103                         ));
00104                         return false;
00105                 } catch (CabinShipMismatchException $e) {
00106                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat keine Kabine erhalten! Grund: <strong>%s</strong>",
00107                                 __CLASS__,
00108                                 __LINE__,
00109                                 $this->getShipName(),
00110                                 $e->getMessage()
00111                         ));
00112                         return false;
00113                 } catch (DeckShipMismatchException $e) {
00114                         if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff <strong>%s</strong> hat kein Deck erhalten! Grund: <strong>%s</strong>",
00115                                 __CLASS__,
00116                                 __LINE__,
00117                                 $this->getShipName(),
00118                                 $e->getMessage()
00119                         ));
00120                         return false;
00121                 }
00122 
00123                 // Instanz im Aufbauten-Array vermerken
00124                 $this->structures->append($partInstance);
00125 
00126                 // Alles klar!
00127                 return true;
00128         }
00129 
00130         // Getter-Methode fuer Strukturen-Array
00131         public final function getStructuresArray () {
00132                 return $this->structures;
00133         }
00134 
00135         // STUB: Getter-Methode Anzahl Betten
00136         public function calcTotalBeds () {
00137                 $this->partialStub("Please implement this stub in your ship!");
00138         }
00139 
00140         // Setter-Methode fuer Schiffsnamen
00141         public final function setShipName ($shipName) {
00142                 $this->shipName = (string) $shipName;
00143         }
00144 
00145         // Getter-Methode fuer Schiffsnamen
00146         public final function getShipName () {
00147                 return $this->shipName;
00148         }
00149 
00150         // Setter-Methode fuer Tiefgang
00151         public final function setDraught ($draught) {
00152                 $this->draught = (int) $draught;
00153         }
00154 
00155         // Getter-Methode fuer Tiefgang
00156         public final function getDraught() {
00157                 return $this->draught;
00158         }
00159 
00160         // Setter-Methode fuer Anzahl Anker
00161         public final function setNumAnchor ($numAnchor) {
00162                 $this->numAnchor = (int) $numAnchor;
00163         }
00164 }
00165 
00166 // [EOF]
00167 ?>

Generated on Mon Dec 8 01:06:44 2008 for Ship-Simulator by  doxygen 1.5.6