TR
games/doom-jumphp / tests / GameFlowTest.php · commit 8e1cb9f
<?phpnamespace Tests;use App\Scene\PlayScene;use App\Scene\TitleScene;use JumPHP\Testing\GameTestCase;/** The game played through its scenes, frame by frame. */final class GameFlowTest extends GameTestCase{    public function testNewGameFromTheTitleStartsTheFirstLevel(): void    {        $this->game->start(TitleScene::class);        $this->game->press('confirm');      // NEW GAME        $this->game->run(5);        $this->game->press('confirm');      // BRING IT ON        $this->game->run(40);        $scene = $this->game->scene();        self::assertInstanceOf(PlayScene::class, $scene);        self::assertSame('HANGAR 7', $scene->world()->level->name);        $this->game->shot('first-level');    }    public function testThePlayerWalksAndShootsInTheFirstLevel(): void    {        $this->game->start(PlayScene::class, ['level' => 'm1']);        $world = $this->game->scene()->world();        $y0 = $world->player->mo->y;        $this->game->hold('up', 60);        self::assertGreaterThan($y0 + 100, $world->player->mo->y);        $this->game->hold('fire', 20);        self::assertLessThan(50, $world->player->ammo['bullets']);        $this->game->shot('walk-and-shoot');    }    public function testTheDemoBotFightsInTheHall(): void    {        $this->game->start(PlayScene::class, ['level' => 'm1', 'demo' => true, 'at' => [7, 16, 90]]);        $this->game->run(60 * 12);        $world = $this->game->scene()->world();        self::assertGreaterThan(0, $world->player->kills, 'the bot killed something');        $this->game->shot('demo');    }    public function testTheTitleOffersTheGraphicsModeWhenThereIsAGpu(): void    {        $this->game->start(TitleScene::class);        $labels = array_map(fn (array $i) => $i[0], $this->game->scene()->menuItems());        $gl = $this->game->engine->gl()->isAvailable();        self::assertSame($gl, in_array('GRAPHICS', $labels, true));        self::assertSame('retro', \App\Game\Graphics::mode($this->game->engine));    }}