Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- socket = io();
- socket.on("gotoroom",gotoroom);
- socket.on("cards",cards);
- socket.on("equal",equal);
- socket.on("win",win);
- socket.on("wrongroom",wrongroom);
- socket.on("startGame",startGame);
- var reqq = window.location.hash
- var choice = undefined;
- // 1 => p, 2 => f, 0 => c
- var sign = 0;
- function equal(){
- document.getElementById("wonThing").innerHTML = "Nobody wins !";
- setTimeout(function(){
- document.getElementsByClassName("selector")[0].style.display = "block";
- document.getElementById("textMenu").style.display = "none";
- document.getElementById("textThing").innerHTML = "";
- document.getElementById("wonThing").innerHTML = "";
- },3000);
- }
- function wrongroom(){
- alert("The game code is invalid");
- }
- function win(data){
- console.log(data);
- if (parseInt(data) == sign) {
- document.getElementById("wonThing").innerHTML = "You won ! ";
- }else{
- document.getElementById("wonThing").innerHTML = "You lost ! ";
- }
- setTimeout(function(){
- document.getElementsByClassName("selector")[0].style.display = "block";
- document.getElementById("textMenu").style.display = "none";
- document.getElementById("textThing").innerHTML = "";
- document.getElementById("wonThing").innerHTML = "";
- },3000);
- }
- function choiceString(nb){
- if (nb == 1) {
- return "Pierre"
- }
- if (nb == 2) {
- return "Feuille"
- }
- if (nb == 0) {
- return "Ciseaux"
- }
- }
- function gotoroom(data){
- document.getElementById("joinCodeMenu").style.display = "block";
- document.getElementById("playMenu").style.display = "none";
- document.getElementById("urlInput").value = window.location.origin+"/#"+data;
- }
- if(reqq.charAt(0) == "#"){
- socket.emit("joinroom",reqq.substr(1));
- sign = 1;
- }
- function createroom(){
- socket.emit("createroom");
- }
- function cards(data){
- if (sign == 0) {
- document.getElementById("textThing").innerHTML = "You chose : "+choiceString(data[0])+", he chose : "+choiceString(data[1]);
- } else {
- document.getElementById("textThing").innerHTML = "You chose : "+choiceString(data[1])+", he chose : "+choiceString(data[0]);
- }
- }
- function joinroom(){
- socket.emit("joinroom",prompt("Enter game id"));
- sign = 1;
- }
- function startGame(){
- document.getElementsByClassName("selector")[0].style.display = "block";
- document.getElementById("playMenu").style.display = "none";
- document.getElementById("joinCodeMenu").style.display = "none";
- }
- function choose(nb){
- choice = nb;
- document.getElementsByClassName("selector")[0].style.display = "none";
- document.getElementById("textMenu").style.display = "block";
- document.getElementById("textThing").innerHTML = "You chose : "+choiceString(nb);
- socket.emit("choice",choice)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement