Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Created by cladlink on 20/01/17.
- */
- var joueur = 1;
- var tour = 1;
- var tourRestant = 20;
- var isPartieFinie = false;
- var voisins = [
- [],
- [2, 3],
- [1, 3, 4, 5],
- [1, 2, 5, 6],
- [2, 5, 7, 8],
- [2, 3, 4, 6, 8, 9],
- [3, 5, 9, 10],
- [4, 8, 11, 12],
- [4, 5, 7, 9, 12, 13],
- [5, 6, 8, 10, 13, 14],
- [6, 9, 14, 15],
- [7, 12, 16, 17],
- [7, 8, 11, 13, 17, 18],
- [8, 9, 12, 14, 18, 19],
- [9, 10, 13, 15, 19, 20],
- [10, 14, 20, 21],
- [11, 17],
- [11, 12, 16, 18],
- [12, 13, 17, 19],
- [13, 14, 18, 19],
- [14, 15, 19, 21],
- [15, 20]
- ];
- //dresser la liste des voisins. cf java pour pas trop se faire chier en fin de partie
- function nextTurn(bloc)
- {
- if( document.getElementById("bloc"+bloc).textContent == "." && !isPartieFinie)
- {
- document.getElementById("bloc"+bloc).textContent = tour.toString();
- if (joueur == 1)
- {
- joueur = 2;
- document.getElementById('bloc'+bloc).style.background = '#22a';
- document.getElementById("joueurTour").textContent = "C'est aux rouges de jouer !";
- document.getElementById("joueurTour").style.background = '#a22';
- }
- else
- {
- tour++;
- joueur = 1;
- document.getElementById('bloc'+bloc).style.background = '#a22';
- document.getElementById("joueurTour").textContent = "C'est aux bleus de jouer !";
- document.getElementById("joueurTour").style.background = '#22a';
- }
- tourRestant--;
- if (tourRestant == 0)
- {
- finPartie();
- isPartieFinie = true;
- }
- }
- }
- function finPartie()
- {
- var i, j;
- var pointsJoueurBlue = 0;
- var pointsJoueurRouge = 0;
- for (i = 1; i<= 21; i++)
- {
- if (document.getElementById("bloc"+i).textContent == ".")
- {
- for (j = 0; j< voisins[i].length; j++)
- {
- if(document.getElementById("bloc"+voisins[i][j]).style.background == 'rgb(170, 34, 34)')
- pointsJoueurRouge += parseInt(document.getElementById("bloc"+voisins[i][j]).textContent);
- else
- pointsJoueurBlue += parseInt(document.getElementById("bloc"+voisins[i][j]).textContent);
- }
- break;
- }
- }
- if (pointsJoueurBlue < pointsJoueurRouge)
- alert("joueur bleu a gagné la partie :" + pointsJoueurBlue + "/" + pointsJoueurRouge + " !");
- if (pointsJoueurBlue > pointsJoueurRouge)
- alert("joueur rouge a gagné la partie :" + pointsJoueurRouge + "/" + pointsJoueurBlue+ " !");
- if (pointsJoueurBlue == pointsJoueurRouge)
- alert("exequo " + pointsJoueurRouge + "/" + pointsJoueurBlue + " !");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement