Пример #1
0
 public function setUp()
 {
     parent::setUp();
     // Prepare a universe with one planet.
     // 1) an terrestrial planet
     $universeEntity = new UniverseEntity();
     $universeEntity->setMaxCelestialBodies(1);
     $universeEntity->setMaxSystems(1);
     $universeEntity->setMinCelestialBodies(1);
     $universeEntity->setMinSystems(1);
     $this->em->persist($universeEntity);
     $galaxyEntity = new GalaxyEntity();
     $galaxyEntity->setNumber(0);
     $galaxyEntity->setUniverse($universeEntity);
     $this->em->persist($galaxyEntity);
     $systemEntity = new SystemEntity();
     $systemEntity->setGalaxy($galaxyEntity);
     $systemEntity->setNumber(0);
     $this->em->persist($systemEntity);
     $terrestrialPlanetEntity = new TerrestrialPlanetEntity();
     $terrestrialPlanetEntity->setNumber(0);
     $terrestrialPlanetEntity->setSystem($systemEntity);
     $this->em->persist($terrestrialPlanetEntity);
     $this->em->flush();
     $this->celestialBody = $terrestrialPlanetEntity;
     /* @var $configBuilder \Codeception\Specify\ConfigBuilder */
     $configBuilder = $this->specifyConfig();
     $configBuilder->shallowClone();
 }
Пример #2
0
 public function testGetTerrestrialPlanetForNewPlayer()
 {
     // Ensure there is one free asteroid in the universe
     // It should be chosen as the new player's planet and thereby be transformed
     // into a terrestrial planet.
     // chaos galaxy
     $galaxyEntity0 = new GalaxyEntity();
     $galaxyEntity0->setNumber(0);
     $galaxyEntity0->setUniverse($this->universeEntity);
     $this->em->persist($galaxyEntity0);
     // normal galaxy
     $galaxyEntity1 = new GalaxyEntity();
     $galaxyEntity1->setNumber(1);
     $galaxyEntity1->setUniverse($this->universeEntity);
     $this->em->persist($galaxyEntity1);
     $systemEntity = new SystemEntity();
     $systemEntity->setGalaxy($galaxyEntity1);
     $systemEntity->setNumber(0);
     $this->em->persist($systemEntity);
     $asteroidEntity = new AsteroidEntity();
     $asteroidEntity->setNumber(0);
     $asteroidEntity->setSystem($systemEntity);
     $this->em->persist($asteroidEntity);
     $this->em->flush();
     $celestialBodyRepository = $this->em->getRepository(CelestialBodyEntity::class);
     $celestialBodySpecialtyRepository = $this->em->getRepository(CelestialBodySpecialtyEntity::class);
     $model = new Universe($this->em, $this->universeEntity, $celestialBodyRepository, $celestialBodySpecialtyRepository);
     $asteroidId = $asteroidEntity->getId();
     $this->specify('Getting a celestial body for a new player.', function () use($model, $asteroidId) {
         $terrestrialPlanetModel = $model->getTerrestrialPlanetForNewPlayer();
         expect('celestial body is a terrestrial planet', $terrestrialPlanetModel instanceof TerrestrialPlanetModel)->true();
         expect('celestial body did not change its id', $terrestrialPlanetModel->getId())->equals($asteroidId);
     });
 }
Пример #3
0
 /**
  * @param SystemEntity $systemEntity
  * @return \common\entities\CelestialBody
  * @throws \yii\base\InvalidValueException
  */
 private function createCelestialBody(SystemEntity $systemEntity)
 {
     $galaxyModel = new GalaxyModel($systemEntity->getGalaxy());
     $allowedCelestialBodyTypes = $galaxyModel->getAllowedCelestialBodyTypes();
     $celestialBodyTypeIndex = rand(0, count($allowedCelestialBodyTypes) - 1);
     $celestialBodyType = $allowedCelestialBodyTypes[$celestialBodyTypeIndex];
     switch ($celestialBodyType) {
         case CelestialBodyEntity::DISCR_ASTEROID:
             $celestialBody = new AsteroidEntity();
             break;
         case CelestialBodyEntity::DISCR_ELECTRICITY_STORM:
             $celestialBody = new ElectricityStormEntity();
             break;
         case CelestialBodyEntity::DISCR_GAS_GIANT:
             $celestialBody = new GasGiantEntity();
             break;
         case CelestialBodyEntity::DISCR_GRAVIMETRIC_ANOMALY:
             $celestialBody = new GravimetricAnomalyEntity();
             break;
         case CelestialBodyEntity::DISCR_ICE_GIANT:
             $celestialBody = new IceGiantEntity();
             break;
         case CelestialBodyEntity::DISCR_ION_STORM:
             $celestialBody = new IonStormEntity();
             break;
         case CelestialBodyEntity::DISCR_SPATIAL_DISTORTION:
             $celestialBody = new SpatialDistortionEntity();
             break;
         case CelestialBodyEntity::DISCR_TERRESTRIAL_PLANET:
             $celestialBody = new TerrestrialPlanetEntity();
             break;
         case CelestialBodyEntity::DISCR_VOID:
             $celestialBody = new VoidEntity();
             break;
         default:
             throw new \yii\base\InvalidValueException("Can't create celestial body of type '{$celestialBodyType}'.");
     }
     return $celestialBody;
 }
Пример #4
0
 public function setUp()
 {
     parent::setUp();
     $this->clearDb();
     // Prepare a universe with
     // - 2 galaxies (0: chaos, 1: normal)
     // - chaos galaxy has 1 system with one free planet
     // - normal galaxy has 2 systems
     // -- 0: system with 1 free planet but a nebula
     // -- 1: system with 1 free planet and 1 planet with an outpost
     $universeEntity = new UniverseEntity();
     $universeEntity->setMaxCelestialBodies(2);
     $universeEntity->setMaxSystems(2);
     $universeEntity->setMinCelestialBodies(1);
     $universeEntity->setMinSystems(1);
     $this->em->persist($universeEntity);
     // --- chaos galaxy -------------------------------------------------------
     $g_0 = new GalaxyEntity();
     $g_0->setNumber(0);
     $g_0->setUniverse($universeEntity);
     $this->em->persist($g_0);
     $s_0_0 = new SystemEntity();
     $s_0_0->setGalaxy($g_0);
     $s_0_0->setNumber(0);
     $this->em->persist($s_0_0);
     $cb_0_0_0 = new AsteroidEntity();
     $cb_0_0_0->setNumber(0);
     $cb_0_0_0->setSystem($s_0_0);
     $this->em->persist($cb_0_0_0);
     // --- normal galaxy ------------------------------------------------------
     $g_1 = new GalaxyEntity();
     $g_1->setNumber(1);
     $g_1->setUniverse($universeEntity);
     $this->em->persist($g_1);
     // --- system with nebula -------------------------------------------------
     $redNebula = new SystemWideModifierEntity();
     $redNebula->setLabel('roter Nebel');
     $redNebula->setNebulaColor(hexdec('FF0000'));
     $this->em->persist($redNebula);
     $s_1_0 = new SystemEntity();
     $s_1_0->setGalaxy($g_1);
     $s_1_0->setModifier($redNebula);
     $s_1_0->setNumber(0);
     $this->em->persist($s_1_0);
     $cb_1_0_0 = new IceGiantEntity();
     $cb_1_0_0->setNumber(0);
     $cb_1_0_0->setSystem($s_1_0);
     $this->em->persist($cb_1_0_0);
     // --- system without nebula ----------------------------------------------
     $s_1_1 = new SystemEntity();
     $s_1_1->setGalaxy($g_1);
     $s_1_1->setNumber(1);
     $this->em->persist($s_1_1);
     $cb_1_1_0 = new VoidEntity();
     $cb_1_1_0->setNumber(0);
     $cb_1_1_0->setSystem($s_1_1);
     $this->em->persist($cb_1_1_0);
     $cb_1_1_1 = new TerrestrialPlanetEntity();
     $cb_1_1_1->setNumber(1);
     $cb_1_1_1->setSystem($s_1_1);
     $this->em->persist($cb_1_1_1);
     $user = new UserEntity();
     $user->setName('Someone');
     $this->em->persist($user);
     $outpostEntity = new OutpostEntity();
     $outpostEntity->setCelestialBody($cb_1_1_1);
     $outpostEntity->setName("Someone's outpost");
     $outpostEntity->setOwner($user);
     $this->em->persist($outpostEntity);
     $this->em->flush();
     // $cb_1_1_0 is the only celestial body suitable for a new player.
     // all other celestial bodies are in a chaos galaxy, in a system with
     // nebula, or have an outpost
     $this->celestialBodyForNewPlayer = $cb_1_1_0;
     $this->repo = $this->em->getRepository(CelestialBodyEntity::class);
     /* @var $configBuilder \Codeception\Specify\ConfigBuilder */
     $configBuilder = $this->specifyConfig();
     $configBuilder->shallowClone();
 }