Skip to content

Commit

Permalink
refactor: Update game URL parameters for Start Game and Join/Create Room
Browse files Browse the repository at this point in the history
- Updated home.ejs:
  - Refactored Start Game Classic event listener to use URL parameters for game mode.
  - Replaced URL structure `/game/classic/${playerCount}` with `/game?type=queue&gameMode=${gameMode}`.

- Updated rooms.ejs:
  - Refactored Join Room event listener to use URL parameters for room ID.
  - Replaced URL structure `/game/custom/${roomId}` with `/game?type=join&roomId=${roomId}`.
  - Refactored Create Room event listener to use URL parameters for game mode.
  - Replaced URL structure `/game/custom/${gameMode}/${playerCount}` with `/game?type=create&gameMode=${gameMode}`.
  • Loading branch information
TKanX committed Jul 31, 2024
1 parent 7f8904b commit 646a1e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion views/pages/home.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
// Handle Start Game Classic
document.getElementById('start-game-classic').addEventListener('click', () => {
const playerCount = document.getElementById('player-count').value;
window.location.href = `/game/classic/${playerCount}`;
let gameMode;
if (playerCount === '3p') {
gameMode = 'classic-3p';
} else if (playerCount === '4p') {
gameMode = 'classic-4p';
}
window.location.href = `/game?type=queue&gameMode=${gameMode}`;
});
</script>
</body>
Expand Down
14 changes: 11 additions & 3 deletions views/pages/rooms.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@
// Handle Join Room
document.getElementById('join-room').addEventListener('click', () => {
const roomId = document.getElementById('room-id').value;
window.location.href = `/game/custom/${roomId}`;
window.location.href = `/game?type=join&roomId=${roomId}`;
});
// Handle Create Room
document.getElementById('create-room').addEventListener('click', () => {
const gameMode = document.getElementById('game-mode').value;
const selectedGameMode = document.getElementById('game-mode').value;
const playerCount = document.getElementById('player-count').value;
window.location.href = `/game/custom/${gameMode}/${playerCount}`;
let gameMode;
if (selectedGameMode === "classic") {
if (playerCount === "3p") {
gameMode = "classic-3p";
} else if (playerCount === "4p") {
gameMode = "classic-4p";
}
}
window.location.href = `/game?type=create&gameMode=${gameMode}`;
});
</script>
</body>
Expand Down

0 comments on commit 646a1e2

Please sign in to comment.