openfree commited on
Commit
eb47dc6
Β·
verified Β·
1 Parent(s): 70d8fe0

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +10 -24
index.html CHANGED
@@ -40,18 +40,26 @@
40
  <div id="score">Score: 0</div>
41
  <div id="moves">Moves: 30</div>
42
  </div>
 
 
 
43
  </div>
44
 
45
  <script>
46
  const canvas = document.getElementById('gameCanvas');
47
  const ctx = canvas.getContext('2d');
 
48
  const GRID_SIZE = 8;
49
  const CELL_SIZE = 70;
50
  const ANIMATION_SPEED = 0.15;
51
-
 
 
 
 
 
52
  canvas.width = GRID_SIZE * CELL_SIZE;
53
  canvas.height = GRID_SIZE * CELL_SIZE;
54
-
55
  const GEMS = {
56
  RUBY: {color: '#ff0000', highlight: '#ff6666'},
57
  SAPPHIRE: {color: '#0000ff', highlight: '#6666ff'},
@@ -60,14 +68,12 @@ const GEMS = {
60
  TOPAZ: {color: '#ffff00', highlight: '#ffff66'},
61
  AMETHYST: {color: '#ff00ff', highlight: '#ff66ff'}
62
  };
63
-
64
  let score = 0;
65
  let moves = 30;
66
  let board = [];
67
  let selectedGem = null;
68
  let animations = [];
69
  let isAnimating = false;
70
-
71
  class Gem {
72
  constructor(type, row, col) {
73
  this.type = type;
@@ -80,7 +86,6 @@ class Gem {
80
  this.scale = 1;
81
  this.alpha = 1;
82
  }
83
-
84
  draw() {
85
  ctx.save();
86
  ctx.globalAlpha = this.alpha;
@@ -101,7 +106,6 @@ class Gem {
101
 
102
  ctx.restore();
103
  }
104
-
105
  update() {
106
  if(this.x !== this.targetX) {
107
  this.x += (this.targetX - this.x) * ANIMATION_SPEED;
@@ -111,7 +115,6 @@ class Gem {
111
  }
112
  }
113
  }
114
-
115
  function initBoard() {
116
  for(let row = 0; row < GRID_SIZE; row++) {
117
  board[row] = [];
@@ -122,7 +125,6 @@ function initBoard() {
122
  }
123
  }
124
  }
125
-
126
  function draw() {
127
  ctx.clearRect(0, 0, canvas.width, canvas.height);
128
 
@@ -134,7 +136,6 @@ function draw() {
134
  }
135
  }
136
  }
137
-
138
  // Draw selected gem highlight
139
  if(selectedGem) {
140
  ctx.strokeStyle = '#fff';
@@ -146,10 +147,8 @@ function draw() {
146
  CELL_SIZE
147
  );
148
  }
149
-
150
  requestAnimationFrame(draw);
151
  }
152
-
153
  function update() {
154
  for(let row = 0; row < GRID_SIZE; row++) {
155
  for(let col = 0; col < GRID_SIZE; col++) {
@@ -159,10 +158,8 @@ function update() {
159
  }
160
  }
161
  }
162
-
163
  function handleClick(e) {
164
  if(isAnimating) return;
165
-
166
  const rect = canvas.getBoundingClientRect();
167
  const x = e.clientX - rect.left;
168
  const y = e.clientY - rect.top;
@@ -185,7 +182,6 @@ function handleClick(e) {
185
  }
186
  }
187
  }
188
-
189
  function swapGems(gem1, gem2) {
190
  const tempX = gem1.targetX;
191
  const tempY = gem1.targetY;
@@ -210,10 +206,8 @@ function swapGems(gem1, gem2) {
210
 
211
  setTimeout(checkMatches, 300);
212
  }
213
-
214
  function checkMatches() {
215
  let matches = [];
216
-
217
  // Check horizontal matches
218
  for(let row = 0; row < GRID_SIZE; row++) {
219
  let matchCount = 1;
@@ -238,7 +232,6 @@ function checkMatches() {
238
  }
239
  }
240
  }
241
-
242
  // Check vertical matches
243
  for(let col = 0; col < GRID_SIZE; col++) {
244
  let matchCount = 1;
@@ -263,12 +256,10 @@ function checkMatches() {
263
  }
264
  }
265
  }
266
-
267
  if(matches.length > 0) {
268
  removeMatches(matches);
269
  }
270
  }
271
-
272
  function removeMatches(matches) {
273
  isAnimating = true;
274
 
@@ -280,7 +271,6 @@ function removeMatches(matches) {
280
  board[row][col] = null;
281
  }
282
  });
283
-
284
  // Drop remaining gems
285
  for(let col = 0; col < GRID_SIZE; col++) {
286
  let emptySpaces = 0;
@@ -306,20 +296,16 @@ function removeMatches(matches) {
306
  board[row][col] = newGem;
307
  }
308
  }
309
-
310
  setTimeout(() => {
311
  isAnimating = false;
312
  checkMatches();
313
  }, 500);
314
  }
315
-
316
  canvas.addEventListener('click', handleClick);
317
-
318
  function gameLoop() {
319
  update();
320
  requestAnimationFrame(gameLoop);
321
  }
322
-
323
  initBoard();
324
  gameLoop();
325
  draw();
 
40
  <div id="score">Score: 0</div>
41
  <div id="moves">Moves: 30</div>
42
  </div>
43
+ <audio id="bgMusic" loop>
44
+ <source src="music1.mp3" type="audio/mpeg">
45
+ </audio>
46
  </div>
47
 
48
  <script>
49
  const canvas = document.getElementById('gameCanvas');
50
  const ctx = canvas.getContext('2d');
51
+ const bgMusic = document.getElementById('bgMusic');
52
  const GRID_SIZE = 8;
53
  const CELL_SIZE = 70;
54
  const ANIMATION_SPEED = 0.15;
55
+ // Start background music
56
+ window.addEventListener('load', () => {
57
+ bgMusic.play().catch(error => {
58
+ console.log("Audio autoplay failed:", error);
59
+ });
60
+ });
61
  canvas.width = GRID_SIZE * CELL_SIZE;
62
  canvas.height = GRID_SIZE * CELL_SIZE;
 
63
  const GEMS = {
64
  RUBY: {color: '#ff0000', highlight: '#ff6666'},
65
  SAPPHIRE: {color: '#0000ff', highlight: '#6666ff'},
 
68
  TOPAZ: {color: '#ffff00', highlight: '#ffff66'},
69
  AMETHYST: {color: '#ff00ff', highlight: '#ff66ff'}
70
  };
 
71
  let score = 0;
72
  let moves = 30;
73
  let board = [];
74
  let selectedGem = null;
75
  let animations = [];
76
  let isAnimating = false;
 
77
  class Gem {
78
  constructor(type, row, col) {
79
  this.type = type;
 
86
  this.scale = 1;
87
  this.alpha = 1;
88
  }
 
89
  draw() {
90
  ctx.save();
91
  ctx.globalAlpha = this.alpha;
 
106
 
107
  ctx.restore();
108
  }
 
109
  update() {
110
  if(this.x !== this.targetX) {
111
  this.x += (this.targetX - this.x) * ANIMATION_SPEED;
 
115
  }
116
  }
117
  }
 
118
  function initBoard() {
119
  for(let row = 0; row < GRID_SIZE; row++) {
120
  board[row] = [];
 
125
  }
126
  }
127
  }
 
128
  function draw() {
129
  ctx.clearRect(0, 0, canvas.width, canvas.height);
130
 
 
136
  }
137
  }
138
  }
 
139
  // Draw selected gem highlight
140
  if(selectedGem) {
141
  ctx.strokeStyle = '#fff';
 
147
  CELL_SIZE
148
  );
149
  }
 
150
  requestAnimationFrame(draw);
151
  }
 
152
  function update() {
153
  for(let row = 0; row < GRID_SIZE; row++) {
154
  for(let col = 0; col < GRID_SIZE; col++) {
 
158
  }
159
  }
160
  }
 
161
  function handleClick(e) {
162
  if(isAnimating) return;
 
163
  const rect = canvas.getBoundingClientRect();
164
  const x = e.clientX - rect.left;
165
  const y = e.clientY - rect.top;
 
182
  }
183
  }
184
  }
 
185
  function swapGems(gem1, gem2) {
186
  const tempX = gem1.targetX;
187
  const tempY = gem1.targetY;
 
206
 
207
  setTimeout(checkMatches, 300);
208
  }
 
209
  function checkMatches() {
210
  let matches = [];
 
211
  // Check horizontal matches
212
  for(let row = 0; row < GRID_SIZE; row++) {
213
  let matchCount = 1;
 
232
  }
233
  }
234
  }
 
235
  // Check vertical matches
236
  for(let col = 0; col < GRID_SIZE; col++) {
237
  let matchCount = 1;
 
256
  }
257
  }
258
  }
 
259
  if(matches.length > 0) {
260
  removeMatches(matches);
261
  }
262
  }
 
263
  function removeMatches(matches) {
264
  isAnimating = true;
265
 
 
271
  board[row][col] = null;
272
  }
273
  });
 
274
  // Drop remaining gems
275
  for(let col = 0; col < GRID_SIZE; col++) {
276
  let emptySpaces = 0;
 
296
  board[row][col] = newGem;
297
  }
298
  }
 
299
  setTimeout(() => {
300
  isAnimating = false;
301
  checkMatches();
302
  }, 500);
303
  }
 
304
  canvas.addEventListener('click', handleClick);
 
305
  function gameLoop() {
306
  update();
307
  requestAnimationFrame(gameLoop);
308
  }
 
309
  initBoard();
310
  gameLoop();
311
  draw();