Skip to content

Commit cf278b0

Browse files
Changes made
1 parent a919b13 commit cf278b0

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

html/game.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ <h1 class="win2" style="display: none"></h1> <!--// Cre
5555
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.8/sweetalert2.min.js"></script>
5656
<!-- // End JS imports -->
5757
<script>
58+
var demoMode = true;
59+
if (demoMode) {
60+
$(".words").css({ "border": "10px solid red"})
61+
}
5862
var fruits = [
5963
{
6064
name: "Lemon",
@@ -170,13 +174,15 @@ <h1 class="win2" style="display: none"></h1> <!--// Cre
170174
}).then(function (name) { // Then when user clicks submit
171175
$.post("/add-score/", {name: name, score: (correct - incorrect)}, function (data) { // Then when that data is successfully sent
172176
console.info(data);
173-
$.get("/get-score/", function (d) { // Download the updated scoreboard
174-
var arr = JSON.parse(d); // Parse what we've been given
175-
$(".leaderboard").html("") // Remove old scores
176-
for (var i = 0; i < arr.length ; i++) { // Go through all the top 20 scores
177-
$(".leaderboard").append("<li class='list-group-item'> " + arr[i].name + " - " + arr[i].score + " </li>") // And add them to the leaderboard
178-
}
179-
})
177+
setTimeout(function () {
178+
$.get("/get-score/", function (d) { // Download the updated scoreboard
179+
var arr = JSON.parse(d); // Parse what we've been given
180+
$(".leaderboard").html("") // Remove old scores
181+
for (var i = 0; i < arr.length ; i++) { // Go through all the top 20 scores
182+
$(".leaderboard").append("<li class='list-group-item'> " + arr[i].name + " - " + arr[i].score + " </li>") // And add them to the leaderboard
183+
}
184+
})
185+
}, 500)
180186
})
181187
});
182188
document.onkeyup = function () {}; // Finally, set the "onkeyup" function to empty so that users can't continue playing

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var app = require('express')();
22
var http = require('http').Server(app); // Import HTTP library and init it with web framework
33
const fs = require('fs'); // Import FileSystem to save leaderboards
44
var bodyParser = require('body-parser')
5+
var request = require('request');
56

67
app.use(bodyParser.json());
78
app.use(bodyParser.urlencoded({
@@ -27,10 +28,14 @@ function getTopLeaderboard(callback1){
2728
)
2829
}
2930
function saveToLeaderboard(name, score){ // Saves a name and score to leaderboard
30-
getLeaderboard(function(data){ // First gets leaderboard
31-
data.push({"name": name, "score": score}) // Then adds an object with {name: "Jay", score: 69}
32-
console.log(data) // Logs for troubleshooting
33-
saveLeaderboard(data) // Saves the data
31+
request('http://www.purgomalum.com/service/json?text=' + name.replace(" ", "+"), function (error, response, body) {
32+
console.log(body)
33+
var censord = JSON.parse(body).result
34+
getLeaderboard(function(data){ // First gets leaderboard
35+
data.push({"name": censord, "score": score}) // Then adds an object with {name: "Jay", score: 69}
36+
console.log(data) // Logs for troubleshooting
37+
saveLeaderboard(data) // Saves the data
38+
})
3439
})
3540
}
3641

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dependencies": {
2020
"body-parser": "^1.17.2",
2121
"express": "^4.15.2",
22+
"request": "^2.81.0",
2223
"socket.io": "^2.0.3"
2324
}
2425
}

storage/leaderboard.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"name":"Dankest guy in town","score":42036069420},{"name":"sareh","score":28},{"name":"JayWilliams","score":5},{"name":"11111111111111111111111111222222222211111111111121122222222222221211222222222222222222222222","score":-17}]
1+
[]

0 commit comments

Comments
 (0)