Advertisement
RenabaReD

Untitled

Oct 21st, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <script type="text/javascript">
  3. function shuffle(array) {
  4.     var counter = array.length, temp, index;
  5.  
  6.     while (counter > 0) {
  7.         index = Math.floor(Math.random() * counter);
  8.  
  9.         counter--;
  10.  
  11.         temp = array[counter];
  12.         array[counter] = array[index];
  13.         array[index] = temp;
  14.     }
  15.  
  16.     return array;
  17. }
  18.  
  19. var joueur = [];
  20. var joueurs = parseInt(prompt("Nombre de joueurs"),10);
  21.  
  22. for (i = 0 ; i < joueurs ; i++)
  23. {
  24.     joueur[i] = prompt("Joueur " + (i+1));
  25. }
  26.  
  27. var liste = shuffle(joueur);
  28.  
  29. for (i = 0 ; i < joueurs ; i++)
  30. {
  31.     liste[liste.length + i] = liste[i];
  32. }
  33.  
  34.  
  35. var tours = joueurs + 1;
  36. alert("Tours : " + tours);
  37. for (i = 0 ; i < tours ; i++)
  38. {
  39.     document.write(1 + ". " + liste[(i+0)%joueurs+1] + "<br />");
  40.     document.write(2 + ". " + liste[(i+1)%joueurs+1] + "<br />");
  41.     document.write(3 + ". " + liste[(i+2)%joueurs+1] + "<br />");
  42.     document.write(4 + ". " + liste[(i+3)%joueurs+1] + "<br />");
  43.     document.write(5 + ". " + liste[(i+4)%joueurs+1] + "<br /><br /><br />");
  44. }
  45.  
  46.  
  47. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement