Skip to content

Commit 3d45020

Browse files
committed
Add a game dynamic that first one which reach 10 points win
1 parent 7908036 commit 3d45020

3 files changed

Lines changed: 68 additions & 11 deletions

File tree

assets/css/style.css

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
ul {
2323
margin: 2rem 0;
2424
}
25+
2526
li {
2627
margin-left: 2rem;
2728
}
2829
}
2930

3031
.container-game {
3132
width: 30rem;
32-
margin: 0 auto;
33+
margin: 2rem auto;
3334

3435
p {
3536
font-size: 1.5rem;
@@ -60,20 +61,30 @@
6061

6162
.bouton-feu,
6263
.bouton-eau,
63-
.bouton-terre {
64+
.bouton-terre,
65+
.bouton-rejouer {
6466
border: none;
65-
background-color: lightskyblue;
6667
padding: 1rem 3rem;
6768
font-size: 2rem;
6869
font-weight: 600;
6970
}
7071

71-
7272
.bouton-feu {
7373
background-color: burlywood;
7474
}
7575

76+
.bouton-feu:disabled,
77+
.bouton-eau:disabled,
78+
.bouton-terre:disabled,
79+
.bouton-rejouer:disabled {
80+
pointer-events: none;
81+
cursor: not-allowed;
82+
background-color: #eee;
83+
color: gray;
84+
}
85+
7686
.bouton-feu:hover {
87+
cursor: pointer;
7788
background-color: orange;
7889
}
7990

@@ -82,6 +93,7 @@
8293
}
8394

8495
.bouton-eau:hover {
96+
cursor: pointer;
8597
background-color: lightskyblue;
8698
}
8799

@@ -90,15 +102,26 @@
90102
}
91103

92104
.bouton-terre:hover {
105+
cursor: pointer;
93106
background-color: gray;
94107
}
95108

109+
.bouton-rejouer {
110+
background-color: lightgreen;
111+
}
112+
113+
.bouton-rejouer:hover {
114+
background-color: greenyellow;
115+
cursor: pointer;
116+
}
117+
96118
.interractions {
97119
margin-top: 2rem;
98120
padding: 1rem;
99121
width: 100%;
122+
height: 8rem;
100123
background-color: #EEE;
101124
color: black;
102125
font-size: 1rem;
103126
font-weight: 400;
104-
}
127+
}

assets/js/script.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function testWinner(choice1, choice2) {
4949
const boutonFeu = document.querySelector(".bouton-feu");
5050
const boutonEau = document.querySelector(".bouton-eau");
5151
const boutonTerre = document.querySelector(".bouton-terre");
52+
const boutonRejouer = document.querySelector(".bouton-rejouer");
5253

5354
/* Recupere zone d'interractions */
5455

@@ -66,6 +67,10 @@ let partiesPerdues = 0;
6667

6768
let computerChoice = powerPc();
6869

70+
boutonRejouer.disabled = true;
71+
interractions.textContent = "Choisissez un élément...";
72+
73+
6974
function theWinnerIs(userChoice) {
7075
let str = `Ordinateur : ${tabName[computerChoice]}\nVous : ${tabName[userChoice]}\nResultat : `;
7176

@@ -83,7 +88,6 @@ function theWinnerIs(userChoice) {
8388
/* Update interraction section */
8489

8590
interractions.textContent = str;
86-
interractions.textContent += "\nEssayez encore...";
8791

8892
partiesJouer++;
8993

@@ -92,7 +96,20 @@ function theWinnerIs(userChoice) {
9296
nombreGagnees.textContent = partiesGagnes.toString();
9397
nombrePerdues.textContent = partiesPerdues.toString();
9498

95-
computerChoice = powerPc();
99+
if ((partiesPerdues === 10) || (partiesGagnes === 10)) {
100+
boutonEau.disabled = true;
101+
boutonFeu.disabled = true;
102+
boutonTerre.disabled = true;
103+
boutonRejouer.disabled = false;
104+
if (partiesGagnes === 10)
105+
interractions.textContent += "\nVous aves gagné la manche."
106+
else
107+
interractions.textContent += "\nVous avez perdu la manche."
108+
}
109+
else {
110+
computerChoice = powerPc();
111+
interractions.textContent += "\nEssayez encore...";
112+
}
96113
}
97114

98115
boutonFeu.addEventListener("click", () => {
@@ -108,4 +125,20 @@ boutonEau.addEventListener("click", () => {
108125
boutonTerre.addEventListener("click", () => {
109126
// console.log("Terre clicked");
110127
theWinnerIs(2);
111-
});
128+
});
129+
130+
boutonRejouer.addEventListener("click", () => {
131+
// console.log("Rejouer clicked");
132+
partiesJouer = 0;
133+
partiesGagnes = 0;
134+
partiesPerdues = 0;
135+
136+
computerChoice = powerPc();
137+
138+
boutonEau.disabled = false;
139+
boutonFeu.disabled = false;
140+
boutonTerre.disabled = false;
141+
boutonRejouer.disabled = true;
142+
143+
interractions.textContent = "Choisissez un élément...";
144+
})

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ <h2>Regles du jeu :</h2>
2020
<li>- La **terre** bat l'**eau**</li>
2121
<li>- Egalité si le joueur et l'ordinateur ont le même pouvoir</li>
2222
</ul>
23+
<p>Le premier qui arrive à 10 victoires remporte la manche.</p>
2324
</div>
2425

2526
<div class="container-game">
26-
<p>A toi de jouer :</p>
27-
2827
<div class="container-scores">
2928
<div>Parties : <span class="partie-number">0</span></div>
3029
<div>Vous : <span class="score-user">0</span></div>
@@ -36,9 +35,11 @@ <h2>Regles du jeu :</h2>
3635
<button class="bouton-eau">eau</button>
3736
<button class="bouton-terre">terre</button>
3837
</div>
39-
38+
4039
<pre class="interractions">
4140
</pre>
41+
42+
<button class="bouton-rejouer">Rejouer...</button>
4243
</div>
4344
</body>
4445

0 commit comments

Comments
 (0)