Improve Pong mode selection and ball physics

This commit is contained in:
2026-07-27 11:30:24 +09:00
parent 604080749b
commit 5b8c0048b5
2 changed files with 64 additions and 5 deletions
+27
View File
@@ -26,6 +26,21 @@ test('pong bot can miss when its reaction is delayed', () => {
assert.equal(game.rightY, 6);
});
test('pong paddle contact changes trajectory by hit position', () => {
const game = new PongGame(false);
game.leftY = 4; game.ballX = 2; game.ballY = 4; game.vx = -1; game.vy = 0;
game.tick('left', 'stay');
assert.equal(game.vx, 1);
assert.ok(game.vy < 0, 'upper-edge contact should send the ball upward');
});
test('pong flat returns accelerate slightly', () => {
const game = new PongGame(false);
game.leftY = 4; game.ballX = 2; game.ballY = 5; game.vx = -1; game.vy = 0;
game.tick('left', 'stay');
assert.equal(game.vx, 1.25);
});
test('live flappy consumes Space and exits on q', () => {
let handler; let finished = ''; let writes = 0;
const service = new FlappyService({ addScore() {}, getLeaderboard() { return []; }, getPlayerBest() { return 0; } });
@@ -66,3 +81,15 @@ test('live pong consumes arrow keys and exits on q', () => {
handler('\x1b[A'); handler('\x1b[B'); handler('q');
assert.match(finished, /left/);
});
test('pong mode picker selects online with arrow keys and enter', () => {
let handler; let finished = ''; let screen = '';
const service = new PongService({ addScore() {}, getLeaderboard() { return []; }, getPlayerBest() { return 0; } });
const ctx = { username: 'visitor', channel: { destroyed: false, write(value) { screen = value; } }, tui: {
setInputHandler(value) { handler = value; }, finishLive(value) { finished = value; }
} };
assert.equal(service.chooseMode(ctx), '__LIVE__');
assert.match(screen, /BOT/); assert.match(screen, /ONLINE/);
handler('\x1b[B'); handler('\r');
assert.match(finished, /Waiting for another player/);
});