-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnector.html
More file actions
128 lines (111 loc) · 2.62 KB
/
Copy pathconnector.html
File metadata and controls
128 lines (111 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Connect the Dots</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="game-container">
<canvas id="canvas"></canvas>
</div>
<script src="script.js">
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Set canvas width and height to match the viewport
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Initialize game variables
let dots = [];
let lines = [];
let gameOver = false;
// Add event listener to canvas to detect clicks
canvas.addEventListener('click', handleClick);
// Main game loop
function loop() {
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw the glowing circle
ctx.beginPath();
ctx.arc(canvas.width / 2, canvas.height / 2, canvas.width / 4, 0, 2 * Math.PI);
ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';
ctx.shadowBlur = 50;
ctx.shadowColor = 'white';
ctx.fill();
ctx.closePath();
// Draw the dots
dots.forEach(dot => dot.draw());
// Draw the lines
lines.forEach(line => line.draw());
// Check for game over
if (gameOver) {
ctx.font = '48px Arial';
ctx.fillStyle = 'red';
ctx.textAlign = 'center';
ctx.fillText('Game Over', canvas.width / 2, canvas.height / 2);
} else if (dots.length === 0) {
ctx.font = '48px Arial';
ctx.fillStyle = 'green';
ctx.textAlign = 'center';
ctx.fillText('You Win!', canvas.width / 2, canvas.height / 2);
} else {
requestAnimationFrame(loop);
}
}
// Dot class
class Dot {
constructor(x, y) {
this.x = x;
this.y = y;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, 10, 0, 2 * Math.PI);
ctx.fillStyle = 'white';
ctx.fill();
ctx.closePath();
}
}
// Line class
class Line {
constructor(dot1, dot2) {
this.dot1 = dot1;
this.dot2 = dot2;
}
draw() {
ctx.beginPath();
ctx.moveTo(this.dot1.x, this.dot1.y);
ctx.lineTo(this.dot2.x, this.dot2.y);
ctx.strokeStyle = 'white';
ctx.lineWidth = 2;
ctx.stroke();
ctx.closePath();
}
}
// Function to handle clicks on canvas
function handleClick(event) {
if (!gameOver) {
const rect = canvas.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
}}
// Find the closest dot to the click
let
</script>
<style>
body {
margin: 0;
padding: 0;
}
.game-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
canvas {
border: 1px solid black;
}
</style>
</body>
</html>