<?phpnamespace Tests;use App\Game\Duel;use App\Scene\DuelScene;use JumPHP\Testing\GameTestCase;/** The star duel against the bot: the two peers connect, the player moves, stars are caught and scored, the round ends and starts again. */final class DuelTest extends GameTestCase{ public function testTheBotConnectsPeerToPeer(): void { $this->game->start(DuelScene::class, ['mode' => 'bot', 'seed' => 3]); $this->game->run(20); self::assertSame('connected', $this->game->peek('state')); $this->game->run(60); self::assertNotNull($this->game->peek('rtt'), 'a ping came back'); $bot = $this->game->peek('other'); self::assertNotEquals([270, 90], $bot, 'the bot moved, and its position came through the data channel'); } public function testThePlayerMovesWithTheArrows(): void { $this->game->start(DuelScene::class, ['mode' => 'bot', 'seed' => 3]); $this->game->run(20); $x = $this->game->peek('me')[0]; $this->game->hold('right', 30); self::assertGreaterThan($x + 40, $this->game->peek('me')[0]); } public function testCatchingAStarScores(): void { $this->game->start(DuelScene::class, ['mode' => 'bot', 'demo' => true, 'seed' => 5]); $this->game->run(60 * 8); $duel = $this->game->peek('duel'); self::assertGreaterThan(0, $duel->scores[0] + $duel->scores[1]); $this->game->shot('duel'); } public function testTheRoundEndsThenStartsAgain(): void { $this->game->start(DuelScene::class, ['mode' => 'bot', 'seed' => 9]); $this->game->run(20); $duel = $this->game->peek('duel'); $duel->left = 0.05; $this->game->run(5); self::assertTrue($duel->over); $this->game->shot('duel-over'); $this->game->press('confirm'); $this->game->run(2); self::assertFalse($duel->over); self::assertGreaterThan(Duel::SECONDS - 1, $duel->left, "a new round, its clock full"); } public function testAStarTouchedByASquareIsCaught(): void { self::assertTrue(Duel::touches([100, 50], [105, 55])); self::assertTrue(Duel::touches([100, 50], [113, 55])); self::assertFalse(Duel::touches([100, 50], [120, 55])); $duel = new Duel(1); $star = $duel->stars[0]; $duel->step(0.1, [$star[0] - 5, $star[1] - 5], [0, 170]); self::assertSame([1, 0], $duel->scores); }}