menambahkan kesalahan
This commit is contained in:
parent
8d8cdc5974
commit
224980d232
460
Sudoku.html
460
Sudoku.html
@ -2,31 +2,15 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Sudoku</title>
|
<title>Sudoku</title>
|
||||||
<style>
|
<style>
|
||||||
/*PENGATURAN WARNA DENGAN HURUF*/
|
|
||||||
:root {
|
:root {
|
||||||
/*Warna Utama*/
|
|
||||||
--primary-color: dodgerblue;
|
--primary-color: dodgerblue;
|
||||||
|
|
||||||
/*Warna Latar Belakang*/
|
|
||||||
--bg-color: whitesmoke;
|
--bg-color: whitesmoke;
|
||||||
|
|
||||||
/*Warna Papan*/
|
|
||||||
--board-bg: white;
|
--board-bg: white;
|
||||||
|
|
||||||
/* Warna Garis */
|
|
||||||
--border-color: lightgray;
|
--border-color: lightgray;
|
||||||
--thick-border: darkslategray;
|
--thick-border: darkslategray;
|
||||||
|
|
||||||
/*Warna Teks*/
|
|
||||||
--text-color: black;
|
--text-color: black;
|
||||||
|
|
||||||
/*Warna Sorot Angka Sama*/
|
|
||||||
--same-highlight: lightblue;
|
--same-highlight: lightblue;
|
||||||
|
|
||||||
/*Warna Kotak Terpilih*/
|
|
||||||
--selected-border: blue;
|
--selected-border: blue;
|
||||||
|
|
||||||
/*Warna Error/Salah*/
|
|
||||||
--error-bg: pink;
|
--error-bg: pink;
|
||||||
--error-text: red;
|
--error-text: red;
|
||||||
}
|
}
|
||||||
@ -44,7 +28,6 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*SCREEN CONTAINER*/
|
|
||||||
.screen {
|
.screen {
|
||||||
display: none;
|
display: none;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@ -57,23 +40,13 @@
|
|||||||
animation: fadeIn 0.3s ease-in-out;
|
animation: fadeIn 0.3s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.screen.active {
|
.screen.active { display: flex; }
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes fadeIn {
|
@keyframes fadeIn {
|
||||||
from {
|
from { opacity: 0; transform: translateY(10px); }
|
||||||
opacity: 0;
|
to { opacity: 1; transform: translateY(0); }
|
||||||
transform: translateY(10px);
|
|
||||||
}
|
|
||||||
|
|
||||||
to {
|
|
||||||
opacity: 1;
|
|
||||||
transform: translateY(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*MENU & LEVEL STYLES*/
|
|
||||||
.logo-img {
|
.logo-img {
|
||||||
width: 120px;
|
width: 120px;
|
||||||
height: 120px;
|
height: 120px;
|
||||||
@ -104,10 +77,7 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
.btn-main:hover { transform: scale(1.05); }
|
||||||
.btn-main:hover {
|
|
||||||
transform: scale(1.05);
|
|
||||||
}
|
|
||||||
|
|
||||||
.level-title {
|
.level-title {
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
@ -128,23 +98,11 @@
|
|||||||
transition: 0.2s;
|
transition: 0.2s;
|
||||||
box-shadow: 0 4px 6px lightgray;
|
box-shadow: 0 4px 6px lightgray;
|
||||||
}
|
}
|
||||||
|
.btn-level:hover { transform: translateY(-3px); }
|
||||||
|
|
||||||
.btn-level:hover {
|
.lvl-easy { background-color: limegreen; }
|
||||||
transform: translateY(-3px);
|
.lvl-medium { background-color: dodgerblue; }
|
||||||
}
|
.lvl-hard { background-color: red; }
|
||||||
|
|
||||||
/*Warna Tombol Level menggunakan HURUF*/
|
|
||||||
.lvl-easy {
|
|
||||||
background-color: limegreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lvl-medium {
|
|
||||||
background-color: dodgerblue;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lvl-hard {
|
|
||||||
background-color: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-cancel {
|
.btn-cancel {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
@ -157,14 +115,13 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*GAME STYLES*/
|
|
||||||
.game-header {
|
.game-header {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 380px;
|
max-width: 380px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 15px;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
@ -178,12 +135,31 @@
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header-center {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
#difficulty-label {
|
#difficulty-label {
|
||||||
font-size: 18px;
|
font-size: 16px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 1px;
|
}
|
||||||
|
|
||||||
|
#timer-label {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
font-family: monospace;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#mistake-label {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
#board-container {
|
#board-container {
|
||||||
@ -216,14 +192,8 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Garis Tebal menggunakan warna darkslategray*/
|
.tile-border-right { border-right: 2px solid var(--thick-border); }
|
||||||
.tile-border-right {
|
.tile-border-bottom { border-bottom: 2px solid var(--thick-border); }
|
||||||
border-right: 2px solid var(--thick-border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tile-border-bottom {
|
|
||||||
border-bottom: 2px solid var(--thick-border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tile-start {
|
.tile-start {
|
||||||
color: black;
|
color: black;
|
||||||
@ -232,25 +202,11 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile-user {
|
.tile-user { color: var(--primary-color); }
|
||||||
color: var(--primary-color);
|
.tile-highlight-same { background-color: var(--same-highlight) !important; }
|
||||||
}
|
.tile-selected { border: 3px solid var(--selected-border) !important; z-index: 10; }
|
||||||
|
.tile-error { background-color: var(--error-bg) !important; color: var(--error-text) !important; }
|
||||||
|
|
||||||
.tile-highlight-same {
|
|
||||||
background-color: var(--same-highlight) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tile-selected {
|
|
||||||
border: 3px solid var(--selected-border) !important;
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tile-error {
|
|
||||||
background-color: var(--error-bg) !important;
|
|
||||||
color: var(--error-text) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Numpad & Tools*/
|
|
||||||
#numpad-row {
|
#numpad-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
@ -274,27 +230,10 @@
|
|||||||
box-shadow: 0 2px 5px lightgray;
|
box-shadow: 0 2px 5px lightgray;
|
||||||
transition: transform 0.1s;
|
transition: transform 0.1s;
|
||||||
}
|
}
|
||||||
|
.number:active { transform: scale(0.95); background-color: aliceblue; }
|
||||||
.number:active {
|
.main-num { font-size: 22px; font-weight: bold; }
|
||||||
transform: scale(0.95);
|
.count-num { font-size: 10px; color: gray; margin-top: 2px; }
|
||||||
background-color: aliceblue;
|
.hidden-key { opacity: 0; pointer-events: none; }
|
||||||
}
|
|
||||||
|
|
||||||
.main-num {
|
|
||||||
font-size: 22px;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.count-num {
|
|
||||||
font-size: 10px;
|
|
||||||
color: gray;
|
|
||||||
margin-top: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hidden-key {
|
|
||||||
opacity: 0;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#tools-row {
|
#tools-row {
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
@ -321,24 +260,9 @@
|
|||||||
transition: 0.2s;
|
transition: 0.2s;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
.tool-btn:active { transform: scale(0.95); }
|
||||||
.tool-btn:active {
|
.btn-delete { color: red; border-color: pink; }
|
||||||
transform: scale(0.95);
|
.btn-hint { color: darkorange; border-color: orange; }
|
||||||
}
|
|
||||||
|
|
||||||
/*Tombol Hapus*/
|
|
||||||
.btn-delete {
|
|
||||||
color: red;
|
|
||||||
border-color: pink;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Tombol Bantuan*/
|
|
||||||
.btn-hint {
|
|
||||||
color: darkorange;
|
|
||||||
border-color: orange;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Style untuk tombol disabled (ketika bantuan habis) */
|
|
||||||
.btn-disabled {
|
.btn-disabled {
|
||||||
background-color: lightgray !important;
|
background-color: lightgray !important;
|
||||||
color: gray !important;
|
color: gray !important;
|
||||||
@ -348,50 +272,99 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#game-msg {
|
#game-msg {
|
||||||
height: 25px;
|
height: 20px;
|
||||||
color: green;
|
margin-bottom: 5px;
|
||||||
font-weight: bold;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
font-size: 16px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*FITUR MENANG*/
|
.modal-overlay {
|
||||||
#win-controls {
|
|
||||||
display: none;
|
display: none;
|
||||||
margin-top: 15px;
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
|
z-index: 100;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
animation: fadeIn 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-play-again {
|
.modal-content {
|
||||||
|
background-color: white;
|
||||||
|
width: 80%;
|
||||||
|
max-width: 300px;
|
||||||
|
padding: 30px;
|
||||||
|
border-radius: 20px;
|
||||||
|
text-align: center;
|
||||||
|
box-shadow: 0 10px 25px rgba(0,0,0,0.3);
|
||||||
|
animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-icon {
|
||||||
|
font-size: 50px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-title {
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-desc {
|
||||||
|
font-size: 14px;
|
||||||
|
color: gray;
|
||||||
|
margin-bottom: 25px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.win-stats {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
margin-bottom: 25px;
|
||||||
|
background-color: #f0f8ff;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
.stat-item { display: flex; flex-direction: column; }
|
||||||
|
.stat-label { font-size: 10px; color: gray; text-transform: uppercase; }
|
||||||
|
.stat-value { font-size: 18px; font-weight: bold; color: var(--primary-color); }
|
||||||
|
|
||||||
|
.btn-modal {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px 0;
|
||||||
|
border-radius: 25px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: bold;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
transition: 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary-modal {
|
||||||
background-color: var(--primary-color);
|
background-color: var(--primary-color);
|
||||||
color: white;
|
color: white;
|
||||||
padding: 15px 40px;
|
box-shadow: 0 4px 10px rgba(30, 144, 255, 0.4);
|
||||||
border: none;
|
|
||||||
border-radius: 30px;
|
|
||||||
font-size: 16px;
|
|
||||||
font-weight: bold;
|
|
||||||
cursor: pointer;
|
|
||||||
box-shadow: 0 4px 10px lightgray;
|
|
||||||
animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
|
||||||
}
|
}
|
||||||
|
.btn-secondary-modal {
|
||||||
.btn-play-again:hover {
|
background-color: white;
|
||||||
background-color: deepskyblue;
|
color: var(--primary-color);
|
||||||
|
border: 2px solid var(--primary-color);
|
||||||
|
}
|
||||||
|
.btn-grey-modal {
|
||||||
|
background-color: #e0e0e0;
|
||||||
|
color: #555;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes popIn {
|
@keyframes popIn {
|
||||||
from {
|
from { transform: scale(0.8); opacity: 0; }
|
||||||
transform: scale(0);
|
to { transform: scale(1); opacity: 1; }
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
to {
|
|
||||||
transform: scale(1);
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -405,20 +378,22 @@
|
|||||||
|
|
||||||
<div id="screen-level" class="screen">
|
<div id="screen-level" class="screen">
|
||||||
<div class="level-title">Pilih Tingkat Kesulitan</div>
|
<div class="level-title">Pilih Tingkat Kesulitan</div>
|
||||||
<button class="btn-level lvl-easy" onclick="startLevel('easy')">MUDAH<div
|
<button class="btn-level lvl-easy" onclick="startLevel('easy')">MUDAH<div style="font-size: 12px; font-weight: normal; margin-top: 5px;">Santai & Cepat</div></button>
|
||||||
style="font-size: 12px; font-weight: normal; margin-top: 5px;">Santai & Cepat</div></button>
|
<button class="btn-level lvl-medium" onclick="startLevel('medium')">MEDIUM<div style="font-size: 12px; font-weight: normal; margin-top: 5px;">Tantangan Standar</div></button>
|
||||||
<button class="btn-level lvl-medium" onclick="startLevel('medium')">MEDIUM<div
|
<button class="btn-level lvl-hard" onclick="startLevel('hard')">SULIT<div style="font-size: 12px; font-weight: normal; margin-top: 5px;">Butuh Logika Ekstra</div></button>
|
||||||
style="font-size: 12px; font-weight: normal; margin-top: 5px;">Tantangan Standar</div></button>
|
|
||||||
<button class="btn-level lvl-hard" onclick="startLevel('hard')">SULIT<div
|
|
||||||
style="font-size: 12px; font-weight: normal; margin-top: 5px;">Butuh Logika Ekstra</div></button>
|
|
||||||
<button class="btn-cancel" onclick="showMenuScreen()">Batal</button>
|
<button class="btn-cancel" onclick="showMenuScreen()">Batal</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="screen-game" class="screen">
|
<div id="screen-game" class="screen">
|
||||||
<div class="game-header">
|
<div class="game-header">
|
||||||
<button class="btn-back-icon" onclick="showMenuScreen()">←</button>
|
<button class="btn-back-icon" onclick="backToMenu()">←</button>
|
||||||
<div id="difficulty-label">MEDIUM</div>
|
|
||||||
<div style="width: 28px;"></div>
|
<div class="header-center">
|
||||||
|
<div id="difficulty-label">MEDIUM</div>
|
||||||
|
<div id="timer-label">00:00</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="mistake-label">Salah: 0/3</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="game-msg"></div>
|
<div id="game-msg"></div>
|
||||||
@ -440,13 +415,45 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="tools-row">
|
<div id="tools-row">
|
||||||
<div class="tool-btn btn-delete" onclick="deleteNumber()"><span>🗑️</span> HAPUS</div>
|
<div class="tool-btn btn-delete" onclick="deleteNumber()"><span>🗑</span> HAPUS</div>
|
||||||
<div id="btn-hint" class="tool-btn btn-hint" onclick="getHint()"><span>💡</span> BANTUAN (3)</div>
|
<div id="btn-hint" class="tool-btn btn-hint" onclick="getHint()"><span>💡</span> BANTUAN (3)</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="win-controls">
|
<div id="modal-game-over" class="modal-overlay">
|
||||||
<button class="btn-play-again" onclick="showLevelScreen()">Main Lagi</button>
|
<div class="modal-content">
|
||||||
|
<div class="modal-icon">😢</div>
|
||||||
|
<div class="modal-title">Permainan Berakhir</div>
|
||||||
|
<div class="modal-desc">
|
||||||
|
Kesempatan habis! Anda telah melakukan 3 kesalahan.
|
||||||
|
</div>
|
||||||
|
<button class="btn-modal btn-secondary-modal" onclick="restartCurrentLevel()">Coba Lagi (Acak Ulang)</button>
|
||||||
|
<button class="btn-modal btn-grey-modal" onclick="showLevelScreen()">Menu Utama</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="modal-win" class="modal-overlay">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-icon">🏆</div>
|
||||||
|
<div class="modal-title">Luar Biasa!</div>
|
||||||
|
<div class="modal-desc">
|
||||||
|
Anda berhasil menyelesaikan puzzle ini.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="win-stats">
|
||||||
|
<div class="stat-item">
|
||||||
|
<span class="stat-label">Tingkat</span>
|
||||||
|
<span class="stat-value" id="win-difficulty">MEDIUM</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat-item">
|
||||||
|
<span class="stat-label">Waktu</span>
|
||||||
|
<span class="stat-value" id="win-time">05:30</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="btn-modal btn-primary-modal" onclick="showLevelScreen()">Permainan Baru</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -454,20 +461,35 @@
|
|||||||
var tileSelected = null;
|
var tileSelected = null;
|
||||||
var board = [];
|
var board = [];
|
||||||
var solution = [];
|
var solution = [];
|
||||||
var hintsRemaining = 3; // Variabel untuk menyimpan sisa bantuan
|
var hintsRemaining = 3;
|
||||||
|
var mistakes = 0;
|
||||||
|
var currentDifficulty = 'easy';
|
||||||
|
|
||||||
|
var timerInterval;
|
||||||
|
var secondsElapsed = 0;
|
||||||
|
|
||||||
function switchScreen(screenId) {
|
function switchScreen(screenId) {
|
||||||
document.querySelectorAll('.screen').forEach(s => s.classList.remove('active'));
|
document.querySelectorAll('.screen').forEach(s => s.classList.remove('active'));
|
||||||
document.getElementById(screenId).classList.add('active');
|
document.getElementById(screenId).classList.add('active');
|
||||||
|
|
||||||
|
document.querySelectorAll('.modal-overlay').forEach(m => m.style.display = 'none');
|
||||||
|
}
|
||||||
|
|
||||||
|
function showMenuScreen() { switchScreen('screen-menu'); stopTimer(); }
|
||||||
|
function showLevelScreen() { switchScreen('screen-level'); stopTimer(); }
|
||||||
|
|
||||||
|
function backToMenu() {
|
||||||
|
stopTimer();
|
||||||
|
showMenuScreen();
|
||||||
}
|
}
|
||||||
function showMenuScreen() { switchScreen('screen-menu'); }
|
|
||||||
function showLevelScreen() { switchScreen('screen-level'); }
|
|
||||||
|
|
||||||
function startLevel(difficulty) {
|
function startLevel(difficulty) {
|
||||||
|
currentDifficulty = difficulty;
|
||||||
let holes = 30;
|
let holes = 30;
|
||||||
let label = "MUDAH";
|
let label = "MUDAH";
|
||||||
if (difficulty === 'medium') { holes = 40; label = "MEDIUM"; }
|
if (difficulty === 'medium') { holes = 40; label = "MEDIUM"; }
|
||||||
else if (difficulty === 'hard') { holes = 50; label = "SULIT"; }
|
else if (difficulty === 'hard') { holes = 50; label = "SULIT"; }
|
||||||
|
|
||||||
document.getElementById('difficulty-label').innerText = label;
|
document.getElementById('difficulty-label').innerText = label;
|
||||||
switchScreen('screen-game');
|
switchScreen('screen-game');
|
||||||
newGame(holes);
|
newGame(holes);
|
||||||
@ -478,19 +500,55 @@
|
|||||||
board = JSON.parse(JSON.stringify(solution));
|
board = JSON.parse(JSON.stringify(solution));
|
||||||
removeNumbers(board, holesCount);
|
removeNumbers(board, holesCount);
|
||||||
|
|
||||||
// Reset sisa bantuan ke 3 setiap game baru
|
|
||||||
hintsRemaining = 3;
|
hintsRemaining = 3;
|
||||||
updateHintButton();
|
updateHintButton();
|
||||||
|
|
||||||
|
mistakes = 0;
|
||||||
|
document.getElementById("mistake-label").innerText = "Salah: 0/3";
|
||||||
|
|
||||||
document.getElementById("tools-row").style.display = "flex";
|
document.getElementById("tools-row").style.display = "flex";
|
||||||
document.getElementById("numpad-row").style.display = "flex";
|
document.getElementById("numpad-row").style.display = "flex";
|
||||||
document.getElementById("win-controls").style.display = "none";
|
document.querySelectorAll('.modal-overlay').forEach(m => m.style.display = 'none');
|
||||||
|
|
||||||
document.getElementById("game-msg").innerText = "";
|
document.getElementById("game-msg").innerText = "";
|
||||||
|
|
||||||
|
startTimer();
|
||||||
|
|
||||||
setGame();
|
setGame();
|
||||||
updateRemainingCounts();
|
updateRemainingCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function restartCurrentLevel() {
|
||||||
|
let holes = 30;
|
||||||
|
if (currentDifficulty === 'medium') { holes = 40; }
|
||||||
|
else if (currentDifficulty === 'hard') { holes = 50; }
|
||||||
|
newGame(holes);
|
||||||
|
}
|
||||||
|
|
||||||
|
function startTimer() {
|
||||||
|
stopTimer();
|
||||||
|
secondsElapsed = 0;
|
||||||
|
document.getElementById("timer-label").innerText = "00:00";
|
||||||
|
|
||||||
|
timerInterval = setInterval(function() {
|
||||||
|
secondsElapsed++;
|
||||||
|
document.getElementById("timer-label").innerText = formatTime(secondsElapsed);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopTimer() {
|
||||||
|
clearInterval(timerInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(totalSeconds) {
|
||||||
|
let m = Math.floor(totalSeconds / 60);
|
||||||
|
let s = totalSeconds % 60;
|
||||||
|
let mStr = m < 10 ? "0" + m : m;
|
||||||
|
let sStr = s < 10 ? "0" + s : s;
|
||||||
|
return mStr + ":" + sStr;
|
||||||
|
}
|
||||||
|
// --------------------
|
||||||
|
|
||||||
function setGame() {
|
function setGame() {
|
||||||
document.getElementById("board").innerHTML = "";
|
document.getElementById("board").innerHTML = "";
|
||||||
tileSelected = null;
|
tileSelected = null;
|
||||||
@ -519,17 +577,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi untuk update tampilan tombol bantuan
|
|
||||||
function updateHintButton() {
|
function updateHintButton() {
|
||||||
let btnHint = document.getElementById("btn-hint");
|
let btnHint = document.getElementById("btn-hint");
|
||||||
btnHint.innerHTML = `<span>💡</span> BANTUAN (${hintsRemaining})`;
|
btnHint.innerHTML = `<span>💡</span> BANTUAN (${hintsRemaining})`;
|
||||||
|
if(hintsRemaining <= 0) btnHint.classList.add("btn-disabled");
|
||||||
// Jika habis, ganti tampilan jadi disabled
|
else btnHint.classList.remove("btn-disabled");
|
||||||
if(hintsRemaining <= 0) {
|
|
||||||
btnHint.classList.add("btn-disabled");
|
|
||||||
} else {
|
|
||||||
btnHint.classList.remove("btn-disabled");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRemainingCounts() {
|
function updateRemainingCounts() {
|
||||||
@ -540,7 +592,7 @@
|
|||||||
if (val !== 0) counts[val]++;
|
if (val !== 0) counts[val]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let digitButtons = document.querySelectorAll(".number");
|
let digitButtons = querySelectorAll(".number");
|
||||||
digitButtons.forEach(btn => {
|
digitButtons.forEach(btn => {
|
||||||
let num = parseInt(btn.getAttribute("data-num"));
|
let num = parseInt(btn.getAttribute("data-num"));
|
||||||
let remaining = 9 - counts[num];
|
let remaining = 9 - counts[num];
|
||||||
@ -568,6 +620,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function selectTile() {
|
function selectTile() {
|
||||||
|
if (document.querySelector(".modal-overlay[style*='flex']")) return;
|
||||||
|
if (document.getElementById("game-msg").innerText.includes("MENANG")) return;
|
||||||
|
|
||||||
if (tileSelected != null) { tileSelected.classList.remove("tile-selected"); }
|
if (tileSelected != null) { tileSelected.classList.remove("tile-selected"); }
|
||||||
tileSelected = this;
|
tileSelected = this;
|
||||||
tileSelected.classList.add("tile-selected");
|
tileSelected.classList.add("tile-selected");
|
||||||
@ -575,6 +630,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function selectNumber() {
|
function selectNumber() {
|
||||||
|
if (document.querySelector(".modal-overlay[style*='flex']")) return;
|
||||||
|
|
||||||
let mainNumSpan = this.querySelector(".main-num");
|
let mainNumSpan = this.querySelector(".main-num");
|
||||||
let numberValue = mainNumSpan.innerText;
|
let numberValue = mainNumSpan.innerText;
|
||||||
fillTile(numberValue);
|
fillTile(numberValue);
|
||||||
@ -582,21 +639,34 @@
|
|||||||
|
|
||||||
function fillTile(numberValue) {
|
function fillTile(numberValue) {
|
||||||
if (tileSelected && !tileSelected.classList.contains("tile-start")) {
|
if (tileSelected && !tileSelected.classList.contains("tile-start")) {
|
||||||
tileSelected.innerText = numberValue;
|
|
||||||
let coords = tileSelected.id.split("-");
|
let coords = tileSelected.id.split("-");
|
||||||
let r = parseInt(coords[0]);
|
let r = parseInt(coords[0]);
|
||||||
let c = parseInt(coords[1]);
|
let c = parseInt(coords[1]);
|
||||||
let val = parseInt(numberValue);
|
let val = parseInt(numberValue);
|
||||||
|
|
||||||
|
tileSelected.innerText = numberValue;
|
||||||
board[r][c] = val;
|
board[r][c] = val;
|
||||||
if (val !== solution[r][c]) { tileSelected.classList.add("tile-error"); }
|
|
||||||
else { tileSelected.classList.remove("tile-error"); }
|
if (val !== solution[r][c]) {
|
||||||
highlightSameNumbers(numberValue);
|
tileSelected.classList.add("tile-error");
|
||||||
updateRemainingCounts();
|
mistakes++;
|
||||||
checkIfWin();
|
document.getElementById("mistake-label").innerText = "Salah: " + mistakes + "/3";
|
||||||
|
|
||||||
|
if (mistakes >= 3) {
|
||||||
|
gameOver();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tileSelected.classList.remove("tile-error");
|
||||||
|
highlightSameNumbers(numberValue);
|
||||||
|
updateRemainingCounts();
|
||||||
|
checkIfWin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteNumber() {
|
function deleteNumber() {
|
||||||
|
if (document.querySelector(".modal-overlay[style*='flex']")) return;
|
||||||
|
|
||||||
if (tileSelected && !tileSelected.classList.contains("tile-start")) {
|
if (tileSelected && !tileSelected.classList.contains("tile-start")) {
|
||||||
tileSelected.innerText = "";
|
tileSelected.innerText = "";
|
||||||
let coords = tileSelected.id.split("-");
|
let coords = tileSelected.id.split("-");
|
||||||
@ -608,8 +678,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getHint() {
|
function getHint() {
|
||||||
// Cek apakah sisa bantuan masih ada
|
if(hintsRemaining <= 0 || document.querySelector(".modal-overlay[style*='flex']")) return;
|
||||||
if(hintsRemaining <= 0) return;
|
|
||||||
|
|
||||||
if (!tileSelected) return;
|
if (!tileSelected) return;
|
||||||
if (tileSelected.classList.contains("tile-start")) return;
|
if (tileSelected.classList.contains("tile-start")) return;
|
||||||
@ -623,25 +692,40 @@
|
|||||||
tileSelected.innerText = correctNum;
|
tileSelected.innerText = correctNum;
|
||||||
tileSelected.classList.remove("tile-error");
|
tileSelected.classList.remove("tile-error");
|
||||||
|
|
||||||
// Kurangi sisa bantuan
|
|
||||||
hintsRemaining--;
|
hintsRemaining--;
|
||||||
updateHintButton(); // Update tampilan tombol
|
updateHintButton();
|
||||||
|
|
||||||
highlightSameNumbers(correctNum.toString());
|
highlightSameNumbers(correctNum.toString());
|
||||||
updateRemainingCounts();
|
updateRemainingCounts();
|
||||||
checkIfWin();
|
checkIfWin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function gameOver() {
|
||||||
|
stopTimer();
|
||||||
|
document.getElementById("modal-game-over").style.display = "flex";
|
||||||
|
document.getElementById("tools-row").style.display = "none";
|
||||||
|
document.getElementById("numpad-row").style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
function checkIfWin() {
|
function checkIfWin() {
|
||||||
for (let r = 0; r < 9; r++) {
|
for (let r = 0; r < 9; r++) {
|
||||||
for (let c = 0; c < 9; c++) {
|
for (let c = 0; c < 9; c++) {
|
||||||
if (board[r][c] !== solution[r][c]) return false;
|
if (board[r][c] !== solution[r][c]) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementById("game-msg").innerText = "SELAMAT! ANDA MENANG!";
|
|
||||||
|
stopTimer();
|
||||||
|
|
||||||
|
let diffText = document.getElementById('difficulty-label').innerText;
|
||||||
|
let timeText = document.getElementById("timer-label").innerText;
|
||||||
|
|
||||||
|
document.getElementById("win-difficulty").innerText = diffText;
|
||||||
|
document.getElementById("win-time").innerText = timeText;
|
||||||
|
|
||||||
|
document.getElementById("modal-win").style.display = "flex";
|
||||||
|
|
||||||
document.getElementById("tools-row").style.display = "none";
|
document.getElementById("tools-row").style.display = "none";
|
||||||
document.getElementById("numpad-row").style.display = "none";
|
document.getElementById("numpad-row").style.display = "none";
|
||||||
document.getElementById("win-controls").style.display = "flex";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user