Advertisement
Guest User

Untitled

a guest
May 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1.  
  2. socket = io();
  3. socket.on("gotoroom",gotoroom);
  4. socket.on("cards",cards);
  5. socket.on("equal",equal);
  6. socket.on("win",win);
  7. socket.on("wrongroom",wrongroom);
  8. socket.on("startGame",startGame);
  9. var reqq = window.location.hash
  10.  
  11. var choice = undefined;
  12. // 1 => p, 2 => f, 0 => c
  13. var sign = 0;
  14.  
  15. function equal(){
  16. document.getElementById("wonThing").innerHTML = "Nobody wins !";
  17. setTimeout(function(){
  18. document.getElementsByClassName("selector")[0].style.display = "block";
  19. document.getElementById("textMenu").style.display = "none";
  20. document.getElementById("textThing").innerHTML = "";
  21. document.getElementById("wonThing").innerHTML = "";
  22. },3000);
  23. }
  24.  
  25. function wrongroom(){
  26. alert("The game code is invalid");
  27. }
  28.  
  29. function win(data){
  30. console.log(data);
  31. if (parseInt(data) == sign) {
  32. document.getElementById("wonThing").innerHTML = "You won ! ";
  33. }else{
  34. document.getElementById("wonThing").innerHTML = "You lost ! ";
  35. }
  36. setTimeout(function(){
  37. document.getElementsByClassName("selector")[0].style.display = "block";
  38. document.getElementById("textMenu").style.display = "none";
  39. document.getElementById("textThing").innerHTML = "";
  40. document.getElementById("wonThing").innerHTML = "";
  41. },3000);
  42. }
  43.  
  44. function choiceString(nb){
  45. if (nb == 1) {
  46. return "Pierre"
  47. }
  48. if (nb == 2) {
  49. return "Feuille"
  50. }
  51. if (nb == 0) {
  52. return "Ciseaux"
  53. }
  54. }
  55. function gotoroom(data){
  56. document.getElementById("joinCodeMenu").style.display = "block";
  57. document.getElementById("playMenu").style.display = "none";
  58. document.getElementById("urlInput").value = window.location.origin+"/#"+data;
  59. }
  60. if(reqq.charAt(0) == "#"){
  61. socket.emit("joinroom",reqq.substr(1));
  62. sign = 1;
  63. }
  64. function createroom(){
  65. socket.emit("createroom");
  66. }
  67. function cards(data){
  68. if (sign == 0) {
  69. document.getElementById("textThing").innerHTML = "You chose : "+choiceString(data[0])+", he chose : "+choiceString(data[1]);
  70. } else {
  71. document.getElementById("textThing").innerHTML = "You chose : "+choiceString(data[1])+", he chose : "+choiceString(data[0]);
  72. }
  73. }
  74. function joinroom(){
  75. socket.emit("joinroom",prompt("Enter game id"));
  76. sign = 1;
  77. }
  78. function startGame(){
  79. document.getElementsByClassName("selector")[0].style.display = "block";
  80. document.getElementById("playMenu").style.display = "none";
  81. document.getElementById("joinCodeMenu").style.display = "none";
  82.  
  83. }
  84. function choose(nb){
  85. choice = nb;
  86. document.getElementsByClassName("selector")[0].style.display = "none";
  87. document.getElementById("textMenu").style.display = "block";
  88. document.getElementById("textThing").innerHTML = "You chose : "+choiceString(nb);
  89. socket.emit("choice",choice)
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement