Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
//================================================================================
// Node Initialization
//================================================================================
const fs = require('fs');
var express = require('express');
var app = express();
var server = require('http').createServer(app);
app.get('/',function(req, res) {
res.sendFile(__dirname + '/client/higherlower.html');
});
app.use('/client',express.static(__dirname + '/client'));
var io = require('socket.io')(server);
//================================================================================
// Variables
//================================================================================
SOCKET_LIST = {};
SHOW_MEMBER_DICT = {};
var synopses = [
["Fox boy becomes greatest ninja in the world", "Naruto"],
["Guy kills people with notebook", "Death Note"],
["Boy who fights giant naked men becomes a giant naked man", "Shingeki no Kyojin"],
["Tin man and his brother search for human bodies", "Fullmetal Alchemist: Brotherhood"],
["Epic gamer trapped inside RPG", "Sword Art Online"],
["Bald guy works out", "One Punch Man"],
["Boy becomes number one hero", "Boku no Hero Academia"],
["Organ transplant turns kid into monster", "Tokyo Ghoul"],
["Freaky Friday the anime", "Kimi no Na wa."],
["Scientist time travels with a microwave", "Steins;Gate"],
["12 year old looks for his dad", "Hunter x Hunter (2011)"],
["Gamer siblings go to a gaming world", "No Game No Life"],
["Boy keeps his sister in a box", "Kimetsu no Yaiba"],
["Guy frees Japan with giant robots", "Code Geass: Hangyaku no Lelouch"],
["Boy falls in love with short, abusive neighbor", "Toradora!"],
["Troubled teens meet in Heaven", "Angel Beats!"],
["God does work for coins", "Noragami"],
["Incel restarts every time he dies", "Re:Zero kara Hajimeru Isekai Seikatsu"],
["Kid reads the future with his phone", "Mirai Nikki (TV)"],
["Depressed pianist goes deaf", "Shigatsu wa Kimi no Uso"],
["Bully gets bullied", "Koe no Katachi"],
["Legendary fighters are wanted from government", "Nanatsu no Taizai"],
["Assassin group overthrows tyranny", "Akame ga Kill!"],
["Epic gamer trapped again, this time inside FPS", "Sword Art Online II"],
["Delinquent finds out he’s the son of Satan", "Ao no Exorcist"],
["Man time travels to stop serial killer", "Boku dake ga Inai Machi"],
["Rubber pirate looks for treasure", "One Piece"],
["Pervert brings Goddess to fantasy world", "Kono Subarashii Sekai ni Shukufuku wo!"],
["Students try to kill their teacher", "Ansatsu Kyoushitsu"],
["Girl uses keys to defeat enemies", "Fairy Tail"],
["Esper deflates people’s egos", "Mob Psycho 100"],
["High school boy hunts down spirits", "Bleach"],
["Guy defends himself with his talking hand", "Kiseijuu: Sei no Kakuritsu"],
["Half naked girl fights clothes with clothes", "Kill la Kill"],
["Girl’s parents are turned to pigs", "Sen to Chihiro no Kamikakushi"],
["Bounty hunters in space", "Cowboy Bebop"],
["Short kid plays volleyball", "Haikyuu!!"],
["Dead people play games", "Death Parade"],
["Ghost classmate kills people", "Another"],
["Edgy kid eats souls", "Soul Eater"],
["Police arrest people before they become criminals", "Psycho-Pass"],
["Kid fights the world with a drill", "Tengen Toppa Gurren Lagann"],
["Food so good it makes people naked", "Shokugeki no Souma"],
["Deadbeat dad makes son fight in giant robot", "Neon Genesis Evangelion"]
["Monster girl kills people then gets amnesia", "Elfen Lied"],
["Traumatized girl writes letters", "Violet Evergarden"],
["Guy summons historical figure to fight in battle royale", "Fate/Zero"],
["Boy fights in dungeon for Greek Goddess", "Dungeon ni Deai wo Motomeru no wa Machigatteiru Darou ka"],
["Boy fights in giant robot with dinosaur spaceship waifu", "Darling in the FranXX"],
["Boy eats cursed fingers", "Jujutsu Kaisen (TV)"],
["Genius rebuilds society from scratch", "Dr. Stone"],
["Mask turns people into vampires", "JoJo no Kimyou na Bouken (TV)"],
["Pervert wakes up with a dragon in his arm", "High School DxD"],
["Powerful wizard and magicless friend compete", "Black Clover"],
["Strong guy searches for balls", "Dragon Ball Z"],
["Boy becomes a viking to seek revenge", "Vinland Saga"],
["Girl falls into well and is saved by dog", "InuYasha"],
["Magical girl saves the planet", "Bishoujo Senshi Sailor Moon"],
["Kid leaves house to capture monsters", "Pokemon"]
];
var redImage = "https://i.imgur.com/PDnFIbB.jpg";
var blueImage = "https://i.imgur.com/odW4NuH.jpg";
//================================================================================
// Socket Functions
//================================================================================
io.sockets.on('connection', function(socket){
console.log('new user!');
var socketId = Math.random();
SOCKET_LIST[socketId] = socket;
var score = 0;
var highScore = 0;
var highScoreRating = 0;
var highScoreSynopsis = 0;
var show1 = ["", "", "", ""];
var show1title;
var show2 = ["", "", "", ""];
var show2title;
var curGame = 0;
socket.on('newGame',function(data, scores){
score = 0;
highScore = scores[1];
highScoreRating = scores[2];
highScoreSynopsis = scores[3];
if (data != 0) {
curGame = data;
}
if (curGame == 3) {
// Synopsis Mode
var randInt = Math.floor(Math.random() * synopses.length);
var title = synopses[randInt][1];
show1title = title;
var idx = SHOW_MEMBER_DICT[title];
show1 = [synopses[randInt][0], showMembers[idx], redImage, redImage];
var randInt2 = Math.floor(Math.random() * synopses.length);
while (randInt == randInt2) {
randInt2 = Math.floor(Math.random() * synopses.length);
}
title = synopses[randInt2][1];
show2title = title;
idx = SHOW_MEMBER_DICT[title];
show2 = [synopses[randInt2][0], showMembers[idx], blueImage, blueImage];
socket.emit('newHighScore', highScoreSynopsis);
var newShowTitles = ["", ""];
newShowTitles[0] = show1title;
newShowTitles[1] = show2title;
socket.emit('startGame', show1, show2, newShowTitles);
} else {
var randInt = Math.floor(Math.random() * (numShows + 1));
while (showScores[randInt] == "N/A") {
randInt = Math.floor(Math.random() * (numShows + 1));
}
show1 = [showTitles[randInt], showMembers[randInt], showImages[randInt], showSmallImages[randInt]];
var randInt2 = Math.floor(Math.random() * (numShows + 1));
while ((randInt == randInt2) || (showScores[randInt2] == "N/A")) {
randInt2 = Math.floor(Math.random() * (numShows + 1));
}
show2 = [showTitles[randInt2], showMembers[randInt2], showImages[randInt2], showSmallImages[randInt2]];
if (curGame == 2) {
show1[1] = showScores[randInt];
show2[1] = showScores[randInt2];
socket.emit('newHighScore', highScoreRating);
socket.emit('startGameRating', show1, show2);
} else {
socket.emit('newHighScore', highScore);
var newShowTitles = ["0", "0"];
socket.emit('startGame', show1, show2, newShowTitles);
}
}
});
socket.on('nextRound',function(gameMode, firstShow, secondShow, showTitlesData, scores){
if (curGame == 0) {
curGame = gameMode;
show1 = firstShow;
show2 = secondShow;
show1title = showTitlesData[0];
show2title = showTitlesData[1];
score = scores[0];
highScore = scores[1];
highScoreRating = scores[2];
highScoreSynopsis = scores[3];
}
if (curGame == 3) {
// Synopsis
var randInt = Math.floor(Math.random() * synopses.length);
while (synopses[randInt][0] == show2[0]) {
randInt = Math.floor(Math.random() * synopses.length);
}
show1[0] = show2[0];
show1[1] = show2[1];
show1[2] = redImage;
show1[3] = redImage;
var title = synopses[randInt][1];
show1title = show2title;
show2title = title;
var idx = SHOW_MEMBER_DICT[title];
show2 = [synopses[randInt][0], showMembers[idx], blueImage, blueImage];
var newShowTitles = ["", ""];
newShowTitles[0] = show1title;
newShowTitles[1] = show2title;
socket.emit('newShow', show1, show2, newShowTitles);
} else {
var randInt = Math.floor(Math.random() * (numShows + 1));
while ((showTitles[randInt] === show2[0]) || (showScores[randInt] == "N/A")) {
randInt = Math.floor(Math.random() * (numShows + 1));
}
show1[0] = show2[0];
show1[1] = show2[1];
show1[2] = show2[2];
show1[3] = show2[3];
show2 = [showTitles[randInt], showMembers[randInt], showImages[randInt], showSmallImages[randInt]];
if (curGame == 2) {
show2[1] = showScores[randInt];
}
var newShowTitles = ["0", "0"];
socket.emit('newShow', show1, show2, newShowTitles);
}
});
socket.on('sendGuess',function(data, gameMode, firstShow, secondShow, showTitlesData, scores){
if (curGame == 0) {
curGame = gameMode;
show1 = firstShow;
show2 = secondShow;
show1title = showTitlesData[0];
show2title = showTitlesData[1];
score = scores[0];
highScore = scores[1];
highScoreRating = scores[2];
highScoreSynopsis = scores[3];
}
//console.log("Data: " + data + ", show1: " + show1[1] + ", show2: " + show2[1]);
var s1 = parseFloat(show1[1].replace(/,/g, ''));
var s2 = parseFloat(show2[1].replace(/,/g, ''));
//console.log(s1 + ", " + s2);
if (((data == 0) && (s2 >= s1)) ||
((data == 1) && (s2 <= s1))) {
score += 1;
//console.log("Correct!");
socket.emit('guessRight', score);
if (curGame == 1) {
if (score > highScore) {
highScore = score;
socket.emit('newHighScore', highScore);
}
} else if (curGame == 2) {
if (score > highScoreRating) {
highScoreRating = score;
socket.emit('newHighScore', highScoreRating);
}
} else {
if (score > highScoreSynopsis) {
highScoreSynopsis = score;
socket.emit('newHighScore', highScoreSynopsis);
}
var idx = SHOW_MEMBER_DICT[show1title];
socket.emit('updateBackground', showImages[idx], showSmallImages[idx]);
}
} else {
//console.log("Wrong!");
socket.emit('guessWrong');
if (curGame == 3) {
var idx1 = SHOW_MEMBER_DICT[show1title];
var idx2 = SHOW_MEMBER_DICT[show2title];
var leftShow = [0, 0, showImages[idx1], showSmallImages[idx1]];
var rightShow = [0, 0, showImages[idx2], showSmallImages[idx2]];
socket.emit('updateBackgrounds', leftShow, rightShow);
}
}
});
socket.on('disconnect',function(){
console.log("user disconnected");
delete SOCKET_LIST[socket.id];
});
});
//================================================================================
// Normal Functions
//================================================================================
//================================================================================
// Function Calls
//================================================================================
var showTitles = fs.readFileSync('/home/jason/popularanime.txt').toString().split(/\n|\r/g);
var showMembers = fs.readFileSync('/home/jason/animemembers.txt').toString().split(/\n|\r/g);
var showImages = fs.readFileSync('/home/jason/popularanimepictures.txt').toString().split(/\n|\r/g);
var showScores = fs.readFileSync('/home/jason/animescores.txt').toString().split(/\n|\r/g);
var showSmallImages = fs.readFileSync('/home/jason/smallanimepictures.txt').toString().split(/\n|\r/g);
var numShows = showTitles.length - 1;
for (var i = 0; i < (numShows + 1); i++) {
SHOW_MEMBER_DICT[showTitles[i]] = i;
}
server.listen(8080);
console.log("Server up!");