From d23413a2d72f1354f6a58e2e4a8103962eab55c9 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 15 Nov 2016 20:10:17 +0100 Subject: [PATCH] Continued a bit: - added class/interface for game options (like pause/unpause flag, et cetera) - maybe also gaming difficulty will come, if computable? - added missing database "tables" Signed-off-by: Roland Haeder --- .../database/frontend/game_options/.htaccess | 1 + .../class_CityGameOptionsDatabaseWrapper.php | 60 ++++++++++ .../city/classes/manager/game/.htaccess | 1 + .../manager/game/class_GameManager.php | 110 ++++++++++++++++++ .../database/frontend/game_options/.htaccess | 1 + .../class_CityGameOptionsWrapper.php | 28 +++++ db/city_section/.htaccess | 1 + db/game_options/.htaccess | 1 + 8 files changed, 203 insertions(+) create mode 100644 application/city/classes/database/frontend/game_options/.htaccess create mode 100644 application/city/classes/database/frontend/game_options/class_CityGameOptionsDatabaseWrapper.php create mode 100644 application/city/classes/manager/game/.htaccess create mode 100644 application/city/classes/manager/game/class_GameManager.php create mode 100644 application/city/interfaces/database/frontend/game_options/.htaccess create mode 100644 application/city/interfaces/database/frontend/game_options/class_CityGameOptionsWrapper.php create mode 100644 db/city_section/.htaccess create mode 100644 db/game_options/.htaccess diff --git a/application/city/classes/database/frontend/game_options/.htaccess b/application/city/classes/database/frontend/game_options/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/classes/database/frontend/game_options/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/classes/database/frontend/game_options/class_CityGameOptionsDatabaseWrapper.php b/application/city/classes/database/frontend/game_options/class_CityGameOptionsDatabaseWrapper.php new file mode 100644 index 0000000..f0a42f8 --- /dev/null +++ b/application/city/classes/database/frontend/game_options/class_CityGameOptionsDatabaseWrapper.php @@ -0,0 +1,60 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015, 2016 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class CityGameOptionsDatabaseWrapper extends BaseDatabaseWrapper implements CityGameOptionsWrapper, Registerable { + // Constants for database table names + const DB_TABLE_GAME_OPTION_INFORMATION = 'game_options'; + + // Constants for database column names + const DB_COLUMN_GAME_OPTION_ID = 'game_id'; + const DB_COLUMN_GAME_OPTION_USER_ID = 'game_user_id'; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this database wrapper by a provided user class + * + * @return $wrapperInstance An instance of the created wrapper class + */ + public static final function createCityGameOptionsDatabaseWrapper () { + // Get a new instance + $wrapperInstance = new CityGameOptionsDatabaseWrapper(); + + // Set (primary!) table name + $wrapperInstance->setTableName(self::DB_TABLE_GAME_OPTION_INFORMATION); + + // Return the instance + return $wrapperInstance; + } +} + +// [EOF] +?> diff --git a/application/city/classes/manager/game/.htaccess b/application/city/classes/manager/game/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/classes/manager/game/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/classes/manager/game/class_GameManager.php b/application/city/classes/manager/game/class_GameManager.php new file mode 100644 index 0000000..7e109cd --- /dev/null +++ b/application/city/classes/manager/game/class_GameManager.php @@ -0,0 +1,110 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015, 2016 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class RegionManager extends BaseManager implements ManageableRegion { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $managerInstance An instance of a ManageableRegion class + */ + public final static function createRegionManager () { + // Get new instance + $managerInstance = new RegionManager(); + + // Get database wrapper + $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('region_info_db_wrapper_class'); + + // And set it here + $managerInstance->setWrapperInstance($wrapperInstance); + + // Return the prepared instance + return $managerInstance; + } + + /** + * Checks whether the current user has already founded a region + * + * @return $isFounded Whether the current user has already founded a region + */ + public function ifUserHasCreatedRegion () { + // Check if the currently set user has already founded a region + $isFounded = $this->getWrapperInstance()->ifUserHasCreatedRegion(); + + // Return result + return $isFounded; + } + + /** + * Checks whether the given region name is already taken + * + * @para $regionName Name of region + * @return $isTaken Whether the given region name is already taken + */ + public function ifRegionNameExists ($regionName) { + // Check if the given region name is taken + $isTaken = $this->getWrapperInstance()->ifRegionExists($regionName); + + // Return result + return $isTaken; + } + + /** + * Founds the first region. A dummy region will also be created + * + * @return $resultInstance Found result after creating it + */ + public function createFirstRegion () { + // Dummy name + // @TODO Move to language system + $regionName = 'Region 1'; + + // Some pre-checks + assert(!$this->ifUserHasCreatedRegion()); + assert(!$this->ifRegionNameExists($regionName)); + + // First region can now be created + $this->getWrapperInstance()->createRegionByName($regionName); + + // Then try to find it + assert($this->ifRegionNameExists($regionName)); + + // Get result instance + $resultInstance = $this->getResultInstance(); + + // And return it + return $resultInstance; + } +} + +// [EOF] +?> diff --git a/application/city/interfaces/database/frontend/game_options/.htaccess b/application/city/interfaces/database/frontend/game_options/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/database/frontend/game_options/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/database/frontend/game_options/class_CityGameOptionsWrapper.php b/application/city/interfaces/database/frontend/game_options/class_CityGameOptionsWrapper.php new file mode 100644 index 0000000..f02197b --- /dev/null +++ b/application/city/interfaces/database/frontend/game_options/class_CityGameOptionsWrapper.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015, 2016 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface CityGameOptionsWrapper extends DatabaseWrapper { +} + +// [EOF] +?> diff --git a/db/city_section/.htaccess b/db/city_section/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/db/city_section/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/db/game_options/.htaccess b/db/game_options/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/db/game_options/.htaccess @@ -0,0 +1 @@ +Deny from all -- 2.39.5