Juego tenis

canvas.width = 800;
canvas.height = 600;

let paddleWidth = 10, paddleHeight = 100, ballSize = 10;
let playerY = (canvas.height - paddleHeight) / 2;
let aiY = (canvas.height - paddleHeight) / 2;
let ballX = canvas.width / 2 - ballSize / 2;
let ballY = canvas.height / 2 - ballSize / 2;
let ballSpeedX = 5, ballSpeedY = 5;
let playerScore = 0, aiScore = 0;
let level = 1;

function drawRect(x, y, w, h, color) {
context.fillStyle = color;
context.fillRect(x, y, w, h);
}

function drawCircle(x, y, r, color) {
context.fillStyle = color;
context.beginPath();
context.arc(x, y, r, 0, Math.PI * 2, false);
context.closePath();
context.fill();
}

function drawText(text, x, y, color) {
context.fillStyle = color;
context.font = "32px Arial";
context.fillText(text, x, y);
}

function resetBall() {
ballX = canvas.width / 2 - ballSize / 2;
ballY = canvas.height / 2 - ballSize / 2;
ballSpeedX = 5 * (Math.random() > 0.5 ? 1 : -1);
ballSpeedY = 5 * (Math.random() > 0.5 ? 1 : -1);
level += 1;
ballSpeedX += level;
ballSpeedY += level;
}

function game() {
update();
render();
}

function update() {
// Move the ball
ballX += ballSpeedX;
ballY += ballSpeedY;

// AI Paddle movement
if (aiY + paddleHeight / 2 = canvas.height) {
ballSpeedY = -ballSpeedY;
}

// Ball collision with paddles
if (ballX playerY && ballY = canvas.width - paddleWidth) {
if (ballY > aiY && ballY {
alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
});
} else {
document.exitFullscreen();
}
});