diff --git a/Lekcja_04/index.html b/Lekcja_04/index.html index f0f4bcd..35439fe 100644 --- a/Lekcja_04/index.html +++ b/Lekcja_04/index.html @@ -86,6 +86,19 @@ #message { text-align: center; } + + .timer { + display: flex; + justify-content: space-between; + } + + .timer>p { + font-size: 1.5em; + } + + .timer>p:last-child { + font-weight: bold; + } @@ -112,6 +125,10 @@
+
+

Twój czas:

+

0:00

+
@@ -132,6 +149,11 @@ let polozono_miny = false let odkryte_pola = 0 + let czas_startu; + let czas_obecny; + let ms_gry; + let interwal; + // tablica z polami let plansza = [] // tablice obiektów (pól) { x: int, y: int, mina: true/false, sasiednie_miny: int } const kolorki = ["red", "green", "blue", "darkseagreen", "cornflowerblue", "beige", "orange", "navy"] @@ -154,18 +176,36 @@ let y = btn.dataset.y if (!polozono_miny) { + czas_startu = new Date(); + + if (interwal != undefined) { clearInterval(interwal); } + interwal = setInterval(() => { + czas_obecny = new Date(); + + ms_gry = czas_obecny.getTime() - czas_startu.getTime(); + + let min = Math.floor(ms_gry / (60000)); + let sec = Math.floor((ms_gry % 60000) / 1000); + + let piekny_string = min + ":" + (sec > 9 ? sec : `0${sec}`); + + document.getElementById("timer-time").innerText = piekny_string; + }, 500); // mniej niż sekunda bo moze sie zdarzyć, że interwał potrwa więcej niż sekundę + // i wtedy zegar nam przeskoczy o dwie sekundy i to by było brzydkie dość + losuj_miny(x, y) polozono_miny = true } if (!gra) { return } if (plansza[y][x].flaga) { return } - if (document.getElementById(`p${x}${y}`).classList.contains("odkryte-pole")) { return } + if (document.getElementById(`p${x}-${y}`).classList.contains("odkryte-pole")) { return } if (plansza[y][x].mina) { alert("Koniec gry, przegrana!") - document.getElementById(`p${x}${y}`).style.backgroundColor = "red"; + document.getElementById(`p${x}-${y}`).style.backgroundColor = "red"; gra = false + clearInterval(interwal); } else { btn.classList.remove("nieodkryte-pole") btn.classList.add("odkryte-pole") @@ -177,6 +217,7 @@ if (odkryte_pola == (w * h) - m) { alert("Koniec gry, wygrana!") gra = false + clearInterval(interwal); } } @@ -186,16 +227,16 @@ let j = x - 1; if (i >= 0 && i < h && j >= 0 && j < w) { - if (document.getElementById(`p${j}${i}`).classList.contains("nieodkryte-pole")) { - klik(document.getElementById(`p${j}${i}`)) + if (document.getElementById(`p${j}-${i}`).classList.contains("nieodkryte-pole")) { + klik(document.getElementById(`p${j}-${i}`)) } } j += 2; if (i >= 0 && i < h && j >= 0 && j < w) { - if (document.getElementById(`p${j}${i}`).classList.contains("nieodkryte-pole")) { - klik(document.getElementById(`p${j}${i}`)) + if (document.getElementById(`p${j}-${i}`).classList.contains("nieodkryte-pole")) { + klik(document.getElementById(`p${j}-${i}`)) } } @@ -203,16 +244,16 @@ i = y - 1; if (i >= 0 && i < h && j >= 0 && j < w) { - if (document.getElementById(`p${j}${i}`).classList.contains("nieodkryte-pole")) { - klik(document.getElementById(`p${j}${i}`)) + if (document.getElementById(`p${j}-${i}`).classList.contains("nieodkryte-pole")) { + klik(document.getElementById(`p${j}-${i}`)) } } i += 2; if (i >= 0 && i < h && j >= 0 && j < w) { - if (document.getElementById(`p${j}${i}`).classList.contains("nieodkryte-pole")) { - klik(document.getElementById(`p${j}${i}`)) + if (document.getElementById(`p${j}-${i}`).classList.contains("nieodkryte-pole")) { + klik(document.getElementById(`p${j}-${i}`)) } } } @@ -231,11 +272,14 @@ n_html += '' for (let j = 0; j < w; j++) { plansza[i].push({ x: j, y: i, mina: false, sasiednie_miny: 0, flaga: false }) - n_html += `` + n_html += `` } n_html += '' } plansza_table.innerHTML += n_html + + document.getElementById("timer-wrapper").style.marginBottom = ".5em"; + document.getElementById("timer-time").innerText = "0:00"; } function losuj_miny(unikaj_x = 0, unikaj_y = 0) { diff --git a/Lekcja_06/index.html b/Lekcja_06/index.html new file mode 100644 index 0000000..16057ad --- /dev/null +++ b/Lekcja_06/index.html @@ -0,0 +1,111 @@ + + + + + + + Ćwiczenia daty + + + + Otwórz konsolę + + + + \ No newline at end of file