text stringlengths 0 1.19k |
|---|
for (let i = 0; i <= GRID; i++) { |
ctx.beginPath(); |
ctx.moveTo(i * CELL, 0); ctx.lineTo(i * CELL, canvas.height); |
ctx.stroke(); |
ctx.beginPath(); |
ctx.moveTo(0, i * CELL); ctx.lineTo(canvas.width, i * CELL); |
ctx.stroke(); |
} |
// food — pulsing node |
const foodPulse = 2 + Math.sin(Date.now() / 180) * 1.5; |
ctx.fillStyle = '#ffb454'; |
ctx.shadowColor = '#ffb454'; |
ctx.shadowBlur = 12; |
const fx = food.x * CELL + CELL / 2; |
const fy = food.y * CELL + CELL / 2; |
ctx.beginPath(); |
ctx.arc(fx, fy, CELL / 3 + foodPulse * 0.4, 0, Math.PI * 2); |
ctx.fill(); |
ctx.shadowBlur = 0; |
// snake |
snake.forEach((seg, i) => { |
const t = 1 - i / snake.length; |
const isHead = i === 0; |
ctx.fillStyle = isHead ? '#b9ffe0' : `rgba(62, 242, 160, ${0.45 + t * 0.5})`; |
ctx.shadowColor = '#3ef2a0'; |
ctx.shadowBlur = isHead ? 10 : 4; |
const pad = isHead ? 1 : 1.5; |
ctx.fillRect(seg.x * CELL + pad, seg.y * CELL + pad, CELL - pad * 2, CELL - pad * 2); |
}); |
ctx.shadowBlur = 0; |
if (pulse > 0) pulse--; |
} |
function restartTimer() { |
clearInterval(timer); |
timer = setInterval(step, tickMs); |
} |
function loop() { |
draw(); |
requestAnimationFrame(loop); |
} |
startBtn.addEventListener('click', () => { |
reset(); |
overlay.classList.remove('show'); |
restartTimer(); |
}); |
reset(); |
draw(); |
loop(); |
})(); |
</script> |
</body> |
</html> |
Write any game using HTML/CSS- |
Please provide the code for each language: C, C++, and C#. about the different things you choose-I'll give you three small programs — one per language — each demonstrating some characteristic features of that language, so you can compare their style side by side. |
## C |
```c |
#include <stdio.h> |
#include <stdlib.h> |
// C is procedural: no classes, manual memory management. |
typedef struct { |
char name[32]; |
int age; |
} Person; |
void greet(const Person *p) { |
printf("Hello, %s! You are %d years old.\n", p->name, p->age); |
} |
int main(void) { |
// Manual allocation on the heap |
Person *people = malloc(2 * sizeof(Person)); |
if (!people) return 1; |
snprintf(people[0].name, sizeof(people[0].name), "Alice"); |
people[0].age = 30; |
snprintf(people[1].name, sizeof(people[1].name), "Bob"); |
people[1].age = 25; |
for (int i = 0; i < 2; i++) { |
greet(&people[i]); |
} |
free(people); // must free manually — no garbage collector |
return 0; |
} |
``` |
## C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.