-
-
diff --git a/html/index_1.html b/html/index_1.html
new file mode 100644
index 0000000..162b24d
--- /dev/null
+++ b/html/index_1.html
@@ -0,0 +1,430 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
Leaderboard
+
+
+
+ Rank |
+ Nickname |
+ Score |
+
+
+
+
+
+
+
+
+
+
+
Timer: 30 seconds
+
+
+
+
+
+
+
+
diff --git a/html/lobby.js b/html/lobby.js
new file mode 100644
index 0000000..a5b4c60
--- /dev/null
+++ b/html/lobby.js
@@ -0,0 +1,75 @@
+document.addEventListener("DOMContentLoaded", function() {
+ const socket = new WebSocket("ws://" + window.location.hostname + ":9105");
+ const gameSelect = document.getElementById("gameSelect");
+ const modeSelect = document.getElementById("modeSelect");
+ const confirmButton = document.getElementById("confirmButton");
+ const startButton = document.getElementById("startButton");
+ const leaveButton = document.getElementById("leaveButton");
+ const refreshButton = document.getElementById("refreshButton");
+ const gameTable = document.getElementById("gameListSection");
+
+ socket.onopen = function() {
+ console.log("WebSocket connection opened.");
+ requestGameList();
+ };
+
+ socket.onmessage = function(event) {
+ const data = JSON.parse(event.data);
+ if (data.type === "gameListUpdate") {
+ updateGameList(data.games);
+ }
+ };
+
+ socket.onerror = function(error) {
+ console.error("WebSocket error:", error);
+ };
+
+ socket.onclose = function() {
+ console.log("WebSocket connection closed.");
+ };
+
+ confirmButton.addEventListener('click', function() {
+ const gameIndex = gameSelect.selectedIndex;
+ const modeIndex = modeSelect.selectedIndex;
+ if (gameIndex >= 0 && modeIndex >= 0) {
+ joinGame(gameSelect.value, modeSelect.options[modeSelect.selectedIndex].text);
+ } else {
+ alert('Please select both a game and a mode.');
+ }
+ });
+
+ refreshButton.addEventListener('click', function() {
+ requestGameList();
+ });
+
+ function requestGameList() {
+ socket.send(JSON.stringify({ type: "requestGameList" }));
+ }
+
+ function joinGame(gameId, mode) {
+ const message = {
+ type: "joinGame",
+ gameId: gameId,
+ mode: mode
+ };
+ socket.send(JSON.stringify(message));
+ }
+
+ function updateGameList(games) {
+ while (gameTable.rows.length > 1) {
+ gameTable.deleteRow(1);
+ }
+
+ // Add new rows for each game
+ games.forEach(function(game) {
+ let row = gameTable.insertRow();
+ let nameCell = row.insertCell(0);
+ let joinCell = row.insertCell(1);
+ let playersCell = row.insertCell(2);
+
+ nameCell.textContent = game.name;
+ joinCell.innerHTML = `
`;
+ playersCell.textContent = game.players.join(", ");
+ });
+ }
+});
diff --git a/html/welcome.js b/html/welcome.js
new file mode 100644
index 0000000..1f82d72
--- /dev/null
+++ b/html/welcome.js
@@ -0,0 +1,65 @@
+document.addEventListener("DOMContentLoaded", function() {
+ const nickInput = document.getElementById("nickInput");
+ const nickForm = document.getElementById("nickForm");
+ const errorElement = document.getElementById("error");
+ const welcomeContainer = document.getElementById("welcomeContainer");
+ const lobbyContainer = document.getElementById("lobbyContainer");
+
+ // Setup WebSocket connection
+ const connection = new WebSocket("ws://" + window.location.hostname + ":9105");
+
+ connection.onopen = function () {
+ console.log('WebSocket connection established!');
+ };
+
+ connection.onerror = function (error) {
+ console.error('WebSocket Error:', error);
+ };
+
+ connection.onmessage = function (e) {
+ console.log('Server:', e.data);
+ const response = JSON.parse(e.data);
+ handleServerResponse(response);
+ };
+
+ nickForm.addEventListener('submit', function(event) {
+ event.preventDefault();
+ validateNickname(nickInput.value.trim());
+ });
+
+ function validateNickname(nickname) {
+ if (!nickname) {
+ showError("Please enter a nickname.");
+ return;
+ }
+
+ let message = {
+ screen: "welcome",
+ type: "validateNickname",
+ nickname: nickname
+ };
+
+ // Send the message object as a string via WebSocket
+ connection.send(JSON.stringify(message));
+ }
+
+ function handleServerResponse(response) {
+ if (response.type === "validateNicknameResponse") {
+ if (response.isValid) {
+ enterLobby();
+ } else {
+ showError("Your nick is already taken, please reenter.");
+ }
+ }
+ }
+
+ function enterLobby() {
+ welcomeContainer.style.display = 'none';
+ lobbyContainer.style.display = 'block';
+ }
+
+ function showError(message) {
+ errorElement.textContent = message;
+ errorElement.style.display = 'block';
+ }
+});
From 981f40598acb234c3bb3ec073536bdd3fd51ef0a Mon Sep 17 00:00:00 2001
From: ThiML10 <157675695+ThiML10@users.noreply.github.com>
Date: Fri, 26 Apr 2024 21:49:35 +0000
Subject: [PATCH 2/9] index
---
html/index.html | 330 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 330 insertions(+)
diff --git a/html/index.html b/html/index.html
index 1b2fb45..162b24d 100644
--- a/html/index.html
+++ b/html/index.html
@@ -98,3 +98,333 @@
Timer: 30 seconds