|
@@ -0,0 +1,120 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+declare(strict_types=1);
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Commands;
|
|
|
|
|
+
|
|
|
|
|
+use App\Services\GalaxyFactory;
|
|
|
|
|
+use App\Services\GameFactory;
|
|
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
+use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
|
|
+use Symfony\Component\Console\Command\Command;
|
|
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
+use Symfony\Component\Console\Input\InputOption;
|
|
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
+use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
|
+
|
|
|
|
|
+#[AsCommand(
|
|
|
|
|
+ name: 'astra:make:game',
|
|
|
|
|
+ description: 'Génère une nouvelle partie'
|
|
|
|
|
+)]
|
|
|
|
|
+class MakeGameCommand extends Command
|
|
|
|
|
+{
|
|
|
|
|
+ public function __construct(
|
|
|
|
|
+ private readonly GameFactory $gameFactory,
|
|
|
|
|
+ private readonly EntityManagerInterface $entityManager
|
|
|
|
|
+ ) {
|
|
|
|
|
+ parent::__construct();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ protected function configure(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this
|
|
|
|
|
+ ->addOption(
|
|
|
|
|
+ 'sectors',
|
|
|
|
|
+ 's',
|
|
|
|
|
+ InputOption::VALUE_OPTIONAL,
|
|
|
|
|
+ 'Nombre de secteurs à générer pour la galaxie',
|
|
|
|
|
+ 1000
|
|
|
|
|
+ )
|
|
|
|
|
+ ->addOption(
|
|
|
|
|
+ 'name',
|
|
|
|
|
+ null,
|
|
|
|
|
+ InputOption::VALUE_OPTIONAL,
|
|
|
|
|
+ 'Nom du jeu et de la galaxie à générer',
|
|
|
|
|
+ 'New Game'
|
|
|
|
|
+ )
|
|
|
|
|
+ ->setHelp('Créé une nouvelle partie de Astra Corp');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
|
+ {
|
|
|
|
|
+ $io = new SymfonyStyle($input, $output);
|
|
|
|
|
+
|
|
|
|
|
+ $sectors = (int) $input->getOption('sectors');
|
|
|
|
|
+ $name = $input->getOption('name');
|
|
|
|
|
+
|
|
|
|
|
+ if (!$name) {
|
|
|
|
|
+ $io->error('Le nom du jeu est requis. Utilisez l\'option --name');
|
|
|
|
|
+ return Command::FAILURE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($sectors <= 0) {
|
|
|
|
|
+ $io->error('Le nombre de secteurs doit être supérieur à 0');
|
|
|
|
|
+ return Command::FAILURE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Vérifier si une galaxie avec ce nom existe déjà
|
|
|
|
|
+ $existingGalaxy = $this->entityManager->getRepository(\App\Entity\Galaxy::class)
|
|
|
|
|
+ ->findOneBy(['name' => $name]);
|
|
|
|
|
+
|
|
|
|
|
+ if ($existingGalaxy) {
|
|
|
|
|
+ $io->error(sprintf('Une galaxie avec le nom "%s" existe déjà', $name));
|
|
|
|
|
+ return Command::FAILURE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $io->title('Génération de la galaxie');
|
|
|
|
|
+ $io->text(sprintf('Nom : %s', $name));
|
|
|
|
|
+ $io->text(sprintf('Nombre de secteurs : %d', $sectors));
|
|
|
|
|
+
|
|
|
|
|
+ // Créer la galaxie
|
|
|
|
|
+ $game = $this->gameFactory->createGame($name, $sectors);
|
|
|
|
|
+ $galaxy = $game->getGalaxy();
|
|
|
|
|
+
|
|
|
|
|
+ // Sauvegarder en base de données
|
|
|
|
|
+ $io->text('Sauvegarde en base de données...');
|
|
|
|
|
+
|
|
|
|
|
+ $this->entityManager->persist($galaxy);
|
|
|
|
|
+ $this->entityManager->flush();
|
|
|
|
|
+
|
|
|
|
|
+ $io->success(sprintf(
|
|
|
|
|
+ 'Galaxie "%s" générée avec succès ! %d secteurs créés avec %d systèmes au total.',
|
|
|
|
|
+ $name,
|
|
|
|
|
+ $galaxy->getSectors()->count(),
|
|
|
|
|
+ $galaxy->getSectors()->count() * GalaxyFactory::SYSTEMS_PER_SECTOR
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ // Statistiques détaillées
|
|
|
|
|
+ $totalSystems = 0;
|
|
|
|
|
+ $totalPlanets = 0;
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($galaxy->getSectors() as $sector) {
|
|
|
|
|
+ $totalSystems += $sector->getSystems()->count();
|
|
|
|
|
+ foreach ($sector->getSystems() as $system) {
|
|
|
|
|
+ $totalPlanets += $system->getPlanets()->count();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $io->section('Statistiques de génération');
|
|
|
|
|
+ $io->table(
|
|
|
|
|
+ ['Élément', 'Quantité'],
|
|
|
|
|
+ [
|
|
|
|
|
+ ['Secteurs', $galaxy->getSectors()->count()],
|
|
|
|
|
+ ['Systèmes', $totalSystems],
|
|
|
|
|
+ ['Planètes', $totalPlanets],
|
|
|
|
|
+ ['ID de la galaxie', $galaxy->getId()],
|
|
|
|
|
+ ]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ return Command::SUCCESS;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|