Skip to content

Commit

Permalink
Updates some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmv30 committed Apr 30, 2024
1 parent 8cfa70f commit 7718960
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 10,120 deletions.
2,469 changes: 0 additions & 2,469 deletions files.txt

Large diffs are not rendered by default.

254 changes: 155 additions & 99 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

<head>
<title>TWSG Lobby</title>
<div>
</head>


<div>Commit hash: b60a28affdd6137e3acda3e31683dc3ecd079c41 </div>
<div id="Basic_info">
<h1>TWSG Lobby</h1>
<label for="username">Username:</label>
Expand Down Expand Up @@ -99,7 +100,7 @@ <h2>Leaderboard</h2>
</tr>
</table>
</div>
<div id="timer">1:00</div>
<div id="timer">3:00</div>

<div id = "ValidWords_list" style="width: 200px;">
<h2>List of valid Words</h2>
Expand Down Expand Up @@ -146,7 +147,6 @@ <h2>List of valid Words</h2>
constructor()
{
this.LB = null;
this.sortedScore = null;
}
}

Expand Down Expand Up @@ -186,47 +186,21 @@ <h2>List of valid Words</h2>
var no_clicks = 0; //No. of clicks done by user
var selected_letters = []; //The letters clicked on and letters between those two selected letters

var sent_status = 0;
var selected_word = null;
var button = null;
var number = 1;
var array_list = null;
var timerInterval;
var state_timer = false;
var words = "";
var grid_test = null;
var times = 0;

var leaderboard_list = [];
var Player_table = document.getElementById("PlayersAndWords");
for (var i = 0; i < 20; i++)
{
var buttonTable = document.getElementById("Grid");
var row = buttonTable.insertRow();
for (var j = 1; j < 21; j++)
{
var cell = row.insertCell();
var button = document.createElement("button");
button.textContent = "?";
button.id = number;

button.style.border = "none";
button.style.backgroundColor = "transparent";
button.style.boxShadow = "none";
button.style.margin = "0";
button.style.outline = "none";
button.style.cursor = "pointer";
button.style.fontSize = "20px";
button.style.width = "20px";
button.style.height = "20px";
button.style.lineHeight = "0";
(function(i, j) {
button.addEventListener("click", function() {
button_click(i, j);
});
})(i, j);

cell.appendChild(button);
number+=1;
}
}
var buttonTable = document.getElementById("Grid");


connection = new WebSocket(serverUrl);

Expand All @@ -239,7 +213,7 @@ <h2>List of valid Words</h2>
{
console.log("close");
}

connection.onmessage = function(event)
{
//Store the data
Expand All @@ -248,11 +222,31 @@ <h2>List of valid Words</h2>

//Assign each server to a userid
if (!isNaN(receivedData))
{
console.log("entered empty");
userid = parseInt(receivedData);
{
if (times === 0)
{
console.log("entered empty");
userid = parseInt(receivedData);
times+=1;
}
else
{
grid_test = parseInt(receivedData);
times = 0;
create_grid();
}

}
else if (JSON.parse(event.data)==="approved")
{
sent_status = 1;
join();
}
else if (JSON.parse(event.data)==="disapproved")
{
sent_status = -1;
join();
}

//Checks if it is a waiting list
else if (Array.isArray(JSON.parse(event.data)))
{
Expand Down Expand Up @@ -341,9 +335,9 @@ <h2>List of valid Words</h2>

//Assign the grid with each letter
var number = 1;
for (var i = 0; i < 20; i++)
for (var i = 0; i < grid_test; i++)
{
for (var k = 0; k < 20; k++)
for (var k = 0; k < grid_test; k++)
{
var button = document.getElementById(number);

Expand All @@ -355,7 +349,7 @@ <h2>List of valid Words</h2>
//Go through the letters to highlight if it is there
for (var i = 0; i < userevent.letters.length; i++)
{
var buttonId = userevent.letters[i].row * 20 + userevent.letters[i].col;
var buttonId = userevent.letters[i].row * grid_test + userevent.letters[i].col;
button = document.getElementById(buttonId);
button.style.backgroundColor = userevent.color;
}
Expand Down Expand Up @@ -471,69 +465,96 @@ <h2>List of valid Words</h2>


}
function update()
{
U = new UserEvent();
U.Handle = username;
U.GameType = gametype;



function update() {
var radioButton = document.getElementById("ready");

console.log(radioButton);
if (radioButton.checked)
{
U.ready = 1;
var number = 1;
for (var i = 0; i < 20; i++)
{
for (var k = 0; k < 20; k++)
{
var button = document.getElementById(number);
button.style.backgroundColor = "transparent";
number++;
}
}
state_timer = false;
}
else
{
U.ready = -1;

if (radioButton.checked) {
U = new UserEvent();
U.Handle = username;
U.GameType = gametype;
U.ready = 1;

// Clear the color of all buttons
for (var i = 1; i <= 400; i++) {
var button = document.getElementById(i);
if (button) {
button.style.backgroundColor = "transparent";
}
}

state_timer = false;
} else {
U = new UserEvent();
U.Handle = username;
U.GameType = gametype;
U.ready = -1;
}



connection.send(JSON.stringify(U));
console.log(JSON.stringify(U));
}
console.log(JSON.stringify(U));
}


function join()
{
username = document.getElementById("username").value;
var gameTypeRadios = document.getElementsByName("game_type");
if (username.trim() !== "")
if (username.trim() !== "")
{
for (var i = 0; i < gameTypeRadios.length; i++)
{
if (gameTypeRadios[i].checked)
{
gametype = gameTypeRadios[i].value;
}
}

U = new UserEvent();
U.Handle = username;
U.GameType = gametype;
U.ready = -1;
U.game = null;
U.Uid = userid;
U.letters = [];

connection.send(JSON.stringify(U));
console.log(JSON.stringify(U));

console.log("I am showing the lobby and hiding basic info") ;
// Show the lobby form
document.getElementById("Lobby").style.display = "block";
// Hide the basic info form
document.getElementById("Basic_info").style.display = "none";
}


if (sent_status === 0)
{
U = new UserEvent();
U.Handle = username;
U.ready = -2;

connection.send(JSON.stringify(U));
}
else if (sent_status === 1)
{


var gameTypeRadios = document.getElementsByName("game_type");


for (var i = 0; i < gameTypeRadios.length; i++)
{
if (gameTypeRadios[i].checked)
{
gametype = gameTypeRadios[i].value;
}
}

U = new UserEvent();
U.Handle = username;
U.GameType = gametype;
U.ready = -1;
U.game = null;
U.Uid = userid;
U.letters = [];

connection.send(JSON.stringify(U));
console.log(JSON.stringify(U));

console.log("I am showing the lobby and hiding basic info");
// Show the lobby form
document.getElementById("Lobby").style.display = "block";
// Hide the basic info form
document.getElementById("Basic_info").style.display = "none";


}
else
{
alert("Username already taken.");
sent_status = 0;
}
}

else
{
Expand All @@ -560,7 +581,7 @@ <h2>List of valid Words</h2>

if (no_clicks === 1)
{
var buttonId = row * 20 + column;
var buttonId = row * grid_test + column;
button = document.getElementById(buttonId);
button.style.backgroundColor = "#f2f2f2";
}
Expand Down Expand Up @@ -637,9 +658,9 @@ <h2>List of valid Words</h2>

function startGameTimer()
{
var threeMinutes = 60 * 1, // 3 minutes in seconds
var threeMinutes = 60 * 3, // 3 minutes in seconds
display = document.querySelector('#timer');
startTimer(30, display);
startTimer(threeMinutes, display);
}

function sendMessage()
Expand All @@ -653,6 +674,41 @@ <h2>List of valid Words</h2>
document.getElementById("chat-input").value = "";
}

function create_grid()
{

for (var i = 0; i < grid_test; i++)
{

var row = buttonTable.insertRow();
for (var j = 1; j < (grid_test+1); j++)
{
var cell = row.insertCell();
var button = document.createElement("button");
button.textContent = "?";
button.id = number;

button.style.border = "none";
button.style.backgroundColor = "transparent";
button.style.boxShadow = "none";
button.style.margin = "0";
button.style.outline = "none";
button.style.cursor = "pointer";
button.style.fontSize = "20px";
button.style.width = "20px";
button.style.height = "20px";
button.style.lineHeight = "0";
(function(i, j) {
button.addEventListener("click", function() {
button_click(i, j);
});
})(i, j);

cell.appendChild(button);
number+=1;
}
}
}

</script>

Expand Down
Loading

0 comments on commit 7718960

Please sign in to comment.