From f9069e24ba9c693bb5d182c7510ea5ec0c5a8537 Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 15 May 2026 13:24:20 +0300 Subject: [PATCH] version 4, game board and score added --- Project/index.html | 32 ++++++++++++++++++++++++++------ Project/main.js | 44 ++++++++++++++++++++++++++++++-------------- Project/style.css | 41 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 93 insertions(+), 24 deletions(-) diff --git a/Project/index.html b/Project/index.html index a318f42..07fcb5a 100644 --- a/Project/index.html +++ b/Project/index.html @@ -8,20 +8,40 @@

Вас приветствует игра "Камень, Ножницы, Бумага"

-
-
- +
+ +
+
-
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
-
- +
+
+
+
+ \ No newline at end of file diff --git a/Project/main.js b/Project/main.js index 466ef16..69a075b 100644 --- a/Project/main.js +++ b/Project/main.js @@ -12,17 +12,29 @@ function save() { localStorage.setItem("stats", JSON.stringify(stats)); } -console.log(npc); -console.log(hum); +function updateScore() { + document.getElementById("score").textContent = + "Ваши победы-" + stats.wins + + ", Ваши проигрыши-" + stats.looses + + ", Ваши ничьи-" + stats.draws; +} -const Stone = { num: 3, Name: 'камень' }; +const images = ["", "бумага", "ножницы", "камушек"]; + +const Stone = { num: 3, Name: 'камушек' }; const Scissors = { num: 2, Name: 'ножницы' }; const Paper = { num: 1, Name: 'бумага' }; function game(hum) { + document.getElementById("result-img").src = ""; + let npc = Math.floor(Math.random() * 3) + 1; + document.getElementById("player-img").src = "img/" + images[hum] + ".png"; + + document.getElementById("npc-img").src = "img/" + images[npc] + ".png"; + if (npc === 1 && hum === 3) { npc = 4 } @@ -31,24 +43,28 @@ function game(hum) { } if (npc > hum) { + document.getElementById("result-img").src = "img/знак меньше.png"; console.log("Вы проиграли"); - alert("Вы проиграли"); stats.looses++; - save() - } else if (npc === hum) { + save(); + updateScore(); + } + else if (npc === hum) { + document.getElementById("result-img").src = "img/знак равно.png"; console.log("Ничья"); - alert("Ничья"); stats.draws++; - save() - } else if (npc < hum) { + save(); + updateScore(); + } + else if (npc < hum) { + document.getElementById("result-img").src = "img/знак больше.png"; console.log("Вы выиграли"); - alert("Вы выиграли"); stats.wins++; - save() - } else { - console.log("Пользователь написал какую-то фигню"); + save(); + updateScore(); } } -console.log("wins-" + stats.wins + ",looses-" + stats.looses + ",draws-" + stats.draws); \ No newline at end of file +updateScore(); +console.log("wins-" + stats.wins + ",looses-" + stats.looses + ",draws-" + stats.draws); diff --git a/Project/style.css b/Project/style.css index 62ac176..97cd4cc 100644 --- a/Project/style.css +++ b/Project/style.css @@ -1,19 +1,52 @@ +h1 { + text-align: center; +} + +#score { + text-align: center; + font-size: 30px; +} + + .game-board { + display: flex; + justify-content: space-between; + align-items: center; + + width: 600px; + margin: 20px auto; +} + +.box { + width: 200px; + height: 250px; + + border: 5px solid black; + display: flex; justify-content: center; - gap: 20px; - flex-wrap: wrap; + align-items: center; +} + +.box img { + width: 150px; } .card-img { width: 200px; height: 200px; - overflow: hidden; } .card-img img { width: 100%; height: 100%; - object-fit: cover; + object-fit: contain; } + +.card-imgs { + display: flex; + flex-direction: row; + justify-content: center; + gap: 20px; +} \ No newline at end of file