Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. /**
  2. Created by cladlink on 20/01/17.
  3. */
  4.  
  5. var joueur = 1;
  6. var tour = 1;
  7. var tourRestant = 20;
  8. var isPartieFinie = false;
  9. var voisins = [
  10. [],
  11. [2, 3],
  12. [1, 3, 4, 5],
  13. [1, 2, 5, 6],
  14. [2, 5, 7, 8],
  15. [2, 3, 4, 6, 8, 9],
  16. [3, 5, 9, 10],
  17. [4, 8, 11, 12],
  18. [4, 5, 7, 9, 12, 13],
  19. [5, 6, 8, 10, 13, 14],
  20. [6, 9, 14, 15],
  21. [7, 12, 16, 17],
  22. [7, 8, 11, 13, 17, 18],
  23. [8, 9, 12, 14, 18, 19],
  24. [9, 10, 13, 15, 19, 20],
  25. [10, 14, 20, 21],
  26. [11, 17],
  27. [11, 12, 16, 18],
  28. [12, 13, 17, 19],
  29. [13, 14, 18, 19],
  30. [14, 15, 19, 21],
  31. [15, 20]
  32. ];
  33. //dresser la liste des voisins. cf java pour pas trop se faire chier en fin de partie
  34. function nextTurn(bloc)
  35. {
  36.  
  37. if( document.getElementById("bloc"+bloc).textContent == "." && !isPartieFinie)
  38. {
  39. document.getElementById("bloc"+bloc).textContent = tour.toString();
  40. if (joueur == 1)
  41. {
  42. joueur = 2;
  43. document.getElementById('bloc'+bloc).style.background = '#22a';
  44. document.getElementById("joueurTour").textContent = "C'est aux rouges de jouer !";
  45. document.getElementById("joueurTour").style.background = '#a22';
  46. }
  47. else
  48. {
  49. tour++;
  50. joueur = 1;
  51. document.getElementById('bloc'+bloc).style.background = '#a22';
  52. document.getElementById("joueurTour").textContent = "C'est aux bleus de jouer !";
  53. document.getElementById("joueurTour").style.background = '#22a';
  54. }
  55. tourRestant--;
  56.  
  57. if (tourRestant == 0)
  58. {
  59. finPartie();
  60. isPartieFinie = true;
  61. }
  62. }
  63.  
  64. }
  65. function finPartie()
  66. {
  67. var i, j;
  68. var pointsJoueurBlue = 0;
  69. var pointsJoueurRouge = 0;
  70. for (i = 1; i<= 21; i++)
  71. {
  72. if (document.getElementById("bloc"+i).textContent == ".")
  73. {
  74. for (j = 0; j< voisins[i].length; j++)
  75. {
  76. if(document.getElementById("bloc"+voisins[i][j]).style.background == 'rgb(170, 34, 34)')
  77. pointsJoueurRouge += parseInt(document.getElementById("bloc"+voisins[i][j]).textContent);
  78. else
  79. pointsJoueurBlue += parseInt(document.getElementById("bloc"+voisins[i][j]).textContent);
  80. }
  81. break;
  82. }
  83. }
  84. if (pointsJoueurBlue < pointsJoueurRouge)
  85. alert("joueur bleu a gagné la partie :" + pointsJoueurBlue + "/" + pointsJoueurRouge + " !");
  86. if (pointsJoueurBlue > pointsJoueurRouge)
  87. alert("joueur rouge a gagné la partie :" + pointsJoueurRouge + "/" + pointsJoueurBlue+ " !");
  88. if (pointsJoueurBlue == pointsJoueurRouge)
  89. alert("exequo " + pointsJoueurRouge + "/" + pointsJoueurBlue + " !");
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement