Skip to content

Commit

Permalink
Added additional comments to help explain functionality and what need…
Browse files Browse the repository at this point in the history
…s to be implemented still
  • Loading branch information
andy-tieu committed Aug 5, 2024
1 parent 5c0f6a2 commit adeb6f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ <h4>Please type in a username</h4>
<!-- <button type = "button">Join lobby</button> -->
</div>
<div class = "left" id = "howTo">
<!-- This div is just text explaining how the game works -->
<h2>How to play:</h2><br>
<p>The user must decide between guessing letters or solving the word(s).</p><br>
<p>If the user guesses a letter correctly, they are allowed a spin on the wheel.</p><br>
<p>If the user guesses a word correctly, they are awarded the word's length x 100 points.</p>
</div>
</div>
<div class = "right">
<!-- This is the all-time leaderboard of all players that have connected -->
<h2 class = "leaderboardTitle">Leaderboard</h2><br>
<p class = "player">1.</p><br>
<p class = "player">2.</p><br>
Expand Down Expand Up @@ -133,6 +135,7 @@ <h1>user inputs should be here</h1>
</div>
</div>
<div class = "right">
<!-- This is the leaderboard for the current ongoing game only -->
<h2 class = "leaderboardTitle">Leaderboard</h2><br>
<p class = "player">1. John - 1500</p><br>
<p class = "player">2. Bob - 700</p><br>
Expand Down
41 changes: 29 additions & 12 deletions html/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// global variables and necessary classes to send JSON data to backend are stored here
var id = -1;
var lobbyId = -1;
var lobbyPlayerCount = -1;
Expand Down Expand Up @@ -66,21 +67,29 @@ connection.onmessage = function (evt) {
}
} */
}

// nameSubmit() takes the text value given by the user, saves it using the same structure as Player class, and
// then sending it to the backend to save the user's information
function nameSubmit() {
var usernameInput = document.getElementById("username").value;
console.log(usernameInput);
//alert(usernameInput);

P = new Player();
P.playerName = usernameInput;
P.playerID = id;
P.points = 0;
if(usernameInput) {
P = new Player();
P.playerName = usernameInput;
P.playerID = id;
P.points = 0;

connection.send(JSON.stringify(P));
console.log(JSON.stringify(P));
connection.send(JSON.stringify(P));
console.log(JSON.stringify(P));
}
else {
// add message here to send to user when username is invalid
}
}

// gameStart() works by hiding the lobby screen and then enabling the game screen to become visible
// The start also only works when the amount of players is valid (need to add/change function to do this for all
// players once one person starts or let other players know when someone else has started)
function gameStart() {
var lobbyScreen = document.getElementById("lobbyScreen");
var gameScreen = document.getElementById("gameScreen");
Expand All @@ -94,23 +103,23 @@ function gameStart() {
console.log("Game has been started with " + lobbyPlayerCount + " players");
}
}

// gameStartTest() is a temporary function to allow testing the game without the need of a second player
function gameStartTest() {
var lobbyScreen = document.getElementById("lobbyScreen");
var gameScreen = document.getElementById("gameScreen");

lobbyScreen.style.display = "none";
gameScreen.style.display = "flex";
}

// sendUserGuess() takes user input to allow for the game to happen (validity checking needs to be added)
function sendUserGuess() {
var userGuess = document.getElementById("userGuess").value;

UG = new UserGuess();

UG.playerID = id;
UG.userGuess = userGuess;

// The input is only sent if the input is not empty or (valid; needs to be implemented)
if(userGuess) {
document.getElementById("userFeedback").innerHTML = "";
connection.send(JSON.stringify(UG));
Expand All @@ -119,4 +128,12 @@ function sendUserGuess() {
else {
document.getElementById("userFeedback").innerHTML = "Please enter a valid character or word(s)";
}
}
}

/*
IMPORTANT!: TO DO
- NEED TO IMPLEMENT FUNCTIONALITY TO SHOW LETTERS AS VALID GUESSES OCCUR
- NEED TO HAVE A WAY TO SHOW ROUND # AND TO SWITCH TO A NEW ROUND
- HAVE TO SEND ROUND UPDATES TO ALL PLAYERS
- (MAY NEED TO WORK ON BOTH FRONTEND AND BACKEND TO IMPLEMENT THESE OR ONE INDIVIDUALLY)
*/

0 comments on commit adeb6f9

Please sign in to comment.