-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
148 lines (129 loc) · 4.07 KB
/
app.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const kagitBtn = document.querySelector("#kagit");
const tasBtn = document.querySelector("#tas");
const makasBtn = document.querySelector("#makas");
const baslat = document.querySelector(".baslat");
const reset = document.querySelector(".reset");
const oyuncuSkor = document.querySelector("#oyuncuSkor");
const bilgisayarSkor = document.querySelector("#bilgisayarSkor");
//Inputlar Seçiliyor
kagitBtn.addEventListener("click", resDegistir);
makasBtn.addEventListener("click", resDegistir);
tasBtn.addEventListener("click", resDegistir);
let oyuncuHamle;
let bilgisayarHamle;
let oyuncuCount = 0;
let bilgisayarCount = 0;
//Oyuncu Hamlesini Seçiyor
function resDegistir(e) {
let oyuncuResim = document.getElementById("oyuncuResim");
var degisenResim = e.target.value;
if (degisenResim === "tas") {
oyuncuResim.src = "img/tas.png";
} else if (degisenResim === "kagit") {
oyuncuResim.src = "img/kagit.png";
} else if (degisenResim === "makas") {
oyuncuResim.src = "img/makas.png";
}
oyuncuHamle = degisenResim;
}
//Bilgisayar Hamlesini Seçiyor ve Oyun Başlıyor
baslat.addEventListener("click", bilgisayarHamleSec);
function bilgisayarHamleSec() {
if (!oyuncuHamle) {
addItem("warning", "Lütfen Seçim Yapınız!!");
return;
}
let bilgisayarResim = document.getElementById("bilgisayarResim");
var res = [
{
name: "tas",
src: "img/tas.png",
},
{
name: "kagit",
src: "img/kagit.png",
},
{
name: "makas",
src: "img/makas.png",
},
];
index = 0;
index = Math.floor(Math.random() * res.length);
bilgisayarResim.src = res[index].src;
bilgisayarHamle = res[index].name;
kazanmaDurumu();
}
//Kazanma Durumu Denetleme
function kazanmaDurumu() {
if (oyuncuHamle == bilgisayarHamle) {
addItem("warning", "Berabere");
} else if (oyuncuHamle === "tas") {
if (bilgisayarHamle === "kagit") {
addItem("danger", "Kaybettin!");
skorUpdate("bilgisayar");
} else if (bilgisayarHamle === "makas") {
addItem("success", "Kazandın!");
skorUpdate("oyuncu");
}
} else if (oyuncuHamle === "kagit") {
if (bilgisayarHamle === "tas") {
addItem("success", "Kazandın!");
skorUpdate("oyuncu");
} else if (bilgisayarHamle === "makas") {
addItem("danger", "Kaybettin!");
skorUpdate("bilgisayar");
}
} else if (oyuncuHamle === "makas") {
if (bilgisayarHamle === "tas") {
addItem("danger", "Kaybettin!");
skorUpdate("bilgisayar");
} else if (bilgisayarHamle === "kagit") {
addItem("success", "Kazandın!");
skorUpdate("oyuncu");
}
}
}
//Sıfırlanıyor
reset.addEventListener("click", resetle);
function resetle() {
let bilgisayarResim = document.getElementById("bilgisayarResim");
bilgisayarResim.src = "img/soru.png";
oyuncuSkor.innerHTML = "Skor : 0";
bilgisayarSkor.innerHTML = "Skor : 0";
oyuncuCount = 0;
bilgisayarCount = 0;
}
//Alert Oluşturuluyor
let alert = document.querySelector("#alertAlani");
function addItem(type, message) {
var divDom = document.createElement("div");
divDom.innerHTML = `
<div class="alert alert-${type}" role="alert">
${
oyuncuHamle
? "Oyuncu :" +
oyuncuCount +
" vs " +
"Bilgisayar :" +
bilgisayarCount +
"<br>"
: ""
}
<strong>${message}</strong>
</div>
`;
divDom.classList.add("col-sm-12", "col-md-12", "col-lg-10");
alert.append(divDom);
setTimeout(function () {
divDom.remove();
}, 3000);
}
// Skorlar
function skorUpdate(whoSkor) {
if (whoSkor === "oyuncu") {
oyuncuSkor.innerHTML = "Skor : " + ++oyuncuCount;
} else {
bilgisayarSkor.innerHTML = "Skor : " + ++bilgisayarCount;
}
}