write a html tennis game
- User
write a html tennis game
Assistant
Here is a basic HTML tennis game:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <style> canvas { border:1px solid #d3d3d3; background-color: #f1f1f1; } </style> </head> <body> <canvas id="myCanvas" width="800" height="600"></canvas> <script> var canvas = document.getElementById('myCanvas'); var ctx = canvas.getContext('2d'); var ballRadius = 10; var paddleHeight = 100; var paddleWidth = 20; var paddleX = (canvas.width-paddleWidth)/2; var rightPressed = false; var leftPressed = false; var ballSpeedX = 5; var ballSpeedY = 5; var x = canvas.width/2; var y = canvas.height-30; var paddle1Y = (canvas.height-paddleHeight)/2; var paddle2Y = (canvas.height-paddleHeight)/2; var player1Score = 0; var player2Score = 0; var showingScore = true; function drawBall() { ctx.beginPath(); ctx.arc(x, y, ballRadius, 0, Math.PI*2); ctx.fillStyle = "#0095DD"; ctx.fill(); ctx.closePath(); } function drawPaddle() { ctx.beginPath(); ctx.rect(paddleX, paddle1Y, paddleWidth, paddleHeight); ctx.fillStyle = "#0095DD"; ctx.fill(); ctx.closePath(); } function drawPaddle2() { ctx.beginPath(); ctx.rect(canvas.width-paddleX-paddleWidth, paddle2Y, paddleWidth, paddleHeight); ctx.fillStyle = "#0095DD"; ctx.fill(); ctx.closePath(); } function drawNet() { for (var i = 0; i < canvas.height; i+=40) { ctx.beginPath(); ctx.rect(canvas.width/2-1,i,2,20); ctx
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.