Bismillah Irr rehman nir raheem
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let snake = [{x: 10, y: 10}];
let apple = {x: 5, y: 5};
let score = 0;
ctx.fillStyle = 'green';
ctx.fillRect(snake[0].x, snake[0].y, 10, 10);
ctx.fillStyle = 'red';
ctx.fillRect(apple.x, apple.y, 10, 10);
document.addEventListener('keydown', (event) => {
switch (event.code) {
case 'ArrowLeft':
// Move snake left
break;
case 'ArrowRight':
// Move snake right
break;
case 'ArrowUp':
// Move snake up
break;
case 'ArrowDown':
// Move snake down
break;
}
});
if (snake[0].x === apple.x && snake[0].y === apple.y) {
score += 1;
apple.x = Math.floor(Math.random() * canvas.width / 10) * 10;
apple.y = Math.floor(Math.random() * canvas.height / 10) * 10;
}
const nft = {
id: 1,
name: 'Apple NFT',
image: 'https://example.com/apple.png',
owner: '',
};
if (snake[0].x === apple.x && snake[0].y === apple.y) {
score += 1;
const newApple = {
x: Math.floor(Math.random() * canvas.width / 10) * 10,
y: Math.floor(Math.random() * canvas.height / 10) * 10,
nft: nft,
};
apple = newApple;
}
Ramu Babu
Founder&C.E.O of #AtoZ_SnS @a2zservicesandsolutions
Digital Creator A Degree in Engineering & Enterpreneurship
अधिक जानकारी के लिए गूगल पर सर्च करें।
Ramu Babu
टिप्पणियाँ