-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
111 lines (79 loc) · 3.27 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
let score = JSON.parse(localStorage.getItem('score'));
if (!score) {
score = {
victoire: 0,
defaite: 0,
egalite: 0
};
}
updatescore();
function playgame(objetchoisi) {
let resultat = '';
let mouvementDeIa = choixIa();
if (objetchoisi === 'ciseaux') {
if (mouvementDeIa === 'pierre') {
resultat = 'perdue';
} else if (mouvementDeIa === 'papier') {
resultat = 'gagnez';
}
else if (mouvementDeIa === 'ciseaux') {
resultat = 'egalite';
//ciseaux ---------------------------------------------
}
} if (objetchoisi === 'papier') {
if (mouvementDeIa === 'pierre') {
resultat = 'gagnez';
} else if (mouvementDeIa === 'papier') {
resultat = 'egalite';
}
else if (mouvementDeIa === 'ciseaux') {
resultat = 'perdue';
//papier ---------------------------------------------
}
} else if (objetchoisi === 'pierre') {
if (mouvementDeIa === 'pierre') {
resultat = 'egalite';
} else if (mouvementDeIa === 'papier') {
resultat = 'perdue';
}
else if (mouvementDeIa === 'ciseaux') {
resultat = 'gagnez';
}
//pierre ---------------------------------------------
}
if (resultat === 'gagnez') {
score.victoire += 1
}
else if (resultat === 'perdue') {
score.defaite += 1
}
else if (resultat === 'egalite') {
score.egalite += 1
}
localStorage.setItem('score', JSON.stringify(score));
updatescore();
document.querySelector(".js-result").innerHTML
= resultat;
document.querySelector(".js-moves").innerHTML
= `Vous <img src="images/${objetchoisi}-emoji.png" class="move-icon">
<img src="images/${mouvementDeIa}-emoji.png" class="move-icon"> IA`;
// alert(`tu as choisi le ${objetchoisi} et l'IA a choisi ${mouvementDeIa}. ${resultat}//
// victoire: ${score.victoire} defaite: ${score.defaite} egalite: ${score.egalite} `); //
}
function updatescore() {
document.querySelector(".js-score").innerHTML
= `victoire: ${score.victoire} defaite: ${score.defaite} egalite: ${score.egalite}`;
}
function choixIa() {
let mouvementDeIa = '';
const randomnumbers = Math.random();
if (randomnumbers >= 0 && randomnumbers < 1 / 3) {
mouvementDeIa = 'pierre';
} else if (randomnumbers >= 1 / 3 && randomnumbers < 2 / 3) {
mouvementDeIa = 'papier';
}
else if (randomnumbers >= 2 / 3 && randomnumbers < 1) {
mouvementDeIa = 'ciseaux';
}
return mouvementDeIa;
}