X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=application%2Fship-simu%2Fmain%2Fships%2Fclass_BaseShip.php;h=51f1559d947e4b9ed1f7c300d8b9dee68230187c;hp=6e0ef56d26b545a3a71e5cc2794c65f4e5027dd2;hb=efba981c9bf18c733dfde945b09111ff4b6007ce;hpb=2fd5f8ecd793f9ec3004cf53629cc7b2c52522cc diff --git a/application/ship-simu/main/ships/class_BaseShip.php b/application/ship-simu/main/ships/class_BaseShip.php index 6e0ef56..51f1559 100644 --- a/application/ship-simu/main/ships/class_BaseShip.php +++ b/application/ship-simu/main/ships/class_BaseShip.php @@ -4,9 +4,9 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,9 +38,9 @@ class BaseShip extends BaseSimulator { private $structures = null; // Namenloses Ship generieren - protected function __construct($class) { + protected function __construct($className) { // Call parent constructor - parent::__construct($class); + parent::__construct($className); // Set object description $this->setObjectDescription("Allgemeines Schiff"); @@ -55,14 +55,14 @@ class BaseShip extends BaseSimulator { // Array-Objekt anlegen private function createStructuresArray () { - $this->structures = new FrameworkArrayObject(); + $this->structures = new FrameworkArrayObject("FakedShipStructures"); } // Schiffsteil generieren (kann alles sein) // buildInstance = Das was in das Schiffsteil evtl. eingebaut werden soll (null = kein besonderes Teil einbauen!) // partClass = Das zu konstruierende Schiffsteil public function createShipPart (ConstructableShipPart $buildInstance, $partClass) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff %s erhält ein neues Schiffsteil (%s).
\n", + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s erhält ein neues Schiffsteil (%s).", __CLASS__, __LINE__, $this->getShipName(), @@ -71,20 +71,8 @@ class BaseShip extends BaseSimulator { // Ist die gewuenschte Klasse vorhanden? if (class_exists($partClass)) { - // Befehl zusammenbauen - $eval = sprintf("\$partInstance = %s::create%s();", - $partClass, $partClass - ); - - // Debug-Meldung ausgeben - if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung:
%s

\n", - __CLASS__, - __LINE__, - htmlentities($eval) - )); - - // ... und ausfuehren - eval($eval); + // Get an instance back from our object factory + $partInstance = ObjectFactory::createObjectByName($partClass); } else { // Nicht vorhanden, dann Ausnahme werfen! throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND); @@ -94,7 +82,7 @@ class BaseShip extends BaseSimulator { try { $partInstance->addShipPartToShip($this, $buildInstance); } catch (MotorShipMismatchException $e) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff %s hat keinen Motor erhalten! Grund: %s
\n", + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keinen Motor erhalten! Grund: %s", __CLASS__, __LINE__, $this->getShipName(), @@ -102,7 +90,7 @@ class BaseShip extends BaseSimulator { )); return false; } catch (RoomShipMismatchException $e) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff %s hat keinen Maschinenraum erhalten! Grund: %s
\n", + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keinen Maschinenraum erhalten! Grund: %s", __CLASS__, __LINE__, $this->getShipName(), @@ -111,7 +99,7 @@ class BaseShip extends BaseSimulator { return false; } catch (StructureShipMismatchException $e) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff %s hat keine Aufbauten erhalten! Grund: %s
\n", + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keine Aufbauten erhalten! Grund: %s", __CLASS__, __LINE__, $this->getShipName(), @@ -119,7 +107,7 @@ class BaseShip extends BaseSimulator { )); return false; } catch (CabinShipMismatchException $e) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff %s hat keine Kabine erhalten! Grund: %s
\n", + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat keine Kabine erhalten! Grund: %s", __CLASS__, __LINE__, $this->getShipName(), @@ -127,34 +115,20 @@ class BaseShip extends BaseSimulator { )); return false; } catch (DeckShipMismatchException $e) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff %s hat kein Deck erhalten! Grund: %s
\n", + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat kein Deck erhalten! Grund: %s", __CLASS__, __LINE__, $this->getShipName(), $e->getMessage() )); return false; - } catch (ExceptionNotChangedException $e) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht geändert. Details: %s
\n", - __CLASS__, - __LINE__, - $e->getMessage() - )); - return false; - } catch (ExceptionNotFoundException $e) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Eine Exception wurde nicht gefunden. Details: %s
\n", - __CLASS__, - __LINE__, - $e->getMessage() - )); - return false; } // Instanz im Aufbauten-Array vermerken $this->structures->append($partInstance); // Debug-Meldung ausgeben - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff %s hat das Schiffsteil %s eingebaut bekommen.
\n", + if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiff %s hat das Schiffsteil %s eingebaut bekommen.", __CLASS__, __LINE__, $this->getShipName(), @@ -172,69 +146,31 @@ class BaseShip extends BaseSimulator { // STUB: Getter-Methode Anzahl Betten public function calcTotalBeds () { - $this->getDebugInstance()->output("[%s:%d] Stub! Anzahl Betten erreicht.
\n"); - return 0; + $this->partialStub("Please implement this stub in your ship!"); } // Setter-Methode fuer Schiffsnamen public final function setShipName ($shipName) { - // Cast the string - $shipName = (string) $shipName; - - // Debug message - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das neue Schiff vom Typ %s wird auf den Namen %s getauft.
\n", - __CLASS__, - __LINE__, - $this->__toString(), - $shipName - )); - - // Set ship name - $this->shipName = $shipName; + $this->shipName = (string) $shipName; } // Getter-Methode fuer Schiffsnamen public final function getShipName () { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das %s ist auf den Namen %s getauft worden.
\n", - __CLASS__, - __LINE__, - $this->__toString(), - $this->shipName - )); return $this->shipName; } // Setter-Methode fuer Tiefgang public final function setDraught ($draught) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das %s mit dem Namen %s hat einen Tiefgang von %sm.
\n", - __CLASS__, - __LINE__, - $this->__toString(), - $this->shipName, - $draught - )); $this->draught = (int) $draught; } // Getter-Methode fuer Tiefgang public final function getDraught() { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Der Tiefgang des Schiffes %s wurde angefordert.
\n", - __CLASS__, - __LINE__, - $this->shipName - )); return $this->draught; } // Setter-Methode fuer Anzahl Anker public final function setNumAnchor ($numAnchor) { - if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das %s mit dem Namen %s hat %s Anker.
\n", - __CLASS__, - __LINE__, - $this->__toString(), - $this->shipName, - $numAnchor - )); $this->numAnchor = (int) $numAnchor; } }