-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgamew.js
More file actions
54 lines (47 loc) · 2.03 KB
/
gamew.js
File metadata and controls
54 lines (47 loc) · 2.03 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
// Get the game ID from the URL query parameters
const params = new URLSearchParams(window.location.search);
const gameId = params.get('gameId');
// Load the corresponding game content based on the game ID
if (gameId === '1') {
// Load game content for game ID 1
document.querySelector('.game-content').innerHTML = '<iframe class="game-iframe" src="play/1/index.html"></iframe>';
} else if (gameId === '2') {
// Load game content for game ID 2
document.querySelector('.game-content').innerHTML = '<iframe class="game-iframe" src="play/1v1/index.html"></iframe>';
} else {
// Invalid game ID
alert('Invalid game ID');
}
// Handle click events for game controls
document.querySelector('.game-control.fullscreen').addEventListener('click', function() {
// Toggle fullscreen mode for the game window
const gameWindow = document.querySelector('.game-window');
if (gameWindow.requestFullscreen) {
gameWindow.requestFullscreen();
} else if (gameWindow.webkitRequestFullscreen) {
gameWindow.webkitRequestFullscreen();
} else if (gameWindow.msRequestFullscreen) {
gameWindow.msRequestFullscreen();
}
// Add the fullscreen class to the game window
gameWindow.classList.add('fullscreen');
});
document.querySelector('.game-control.minimize').addEventListener('click', function() {
// Exit fullscreen mode and minimize the game window
const gameWindow = document.querySelector('.game-window');
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
// Remove the fullscreen class from the game window
gameWindow.classList.remove('fullscreen');
// Display the game window at its default size
gameWindow.style.display = 'block';
});
document.querySelector('.game-control.home').addEventListener('click', function() {
// Navigate back to the homepage
window.location.href = '/';
});