Update
This commit is contained in:
parent
232b756ef1
commit
e657b1004f
23
2048.js
23
2048.js
@ -4,14 +4,27 @@
|
|||||||
let board = [];
|
let board = [];
|
||||||
let currentScore = 0;
|
let currentScore = 0;
|
||||||
|
|
||||||
// Ambil username dari sessionStorage
|
// Ambil username dari sessionStorage (Cek apakah ada user login)
|
||||||
const currentUser = sessionStorage.getItem("loggedInUser") || "guest";
|
const loggedInUser = sessionStorage.getItem("loggedInUser");
|
||||||
|
|
||||||
// Buat nama kunci unik
|
// Tentukan user saat ini (jika tidak ada login, pakai "guest")
|
||||||
|
const currentUser = loggedInUser || "guest";
|
||||||
|
|
||||||
|
// Buat nama kunci unik untuk penyimpanan
|
||||||
const storageKey = 'highScore2048_' + currentUser;
|
const storageKey = 'highScore2048_' + currentUser;
|
||||||
|
|
||||||
// Ambil skor milik user tersebut
|
// --- PERBAIKAN DI SINI ---
|
||||||
let highScore = parseInt(localStorage.getItem(storageKey)) || 0;
|
let highScore = 0;
|
||||||
|
|
||||||
|
if (loggedInUser) {
|
||||||
|
// JIKA SUDAH LOGIN: Ambil High Score dari memori localStorage
|
||||||
|
highScore = parseInt(localStorage.getItem(storageKey)) || 0;
|
||||||
|
} else {
|
||||||
|
// JIKA BELUM LOGIN (GUEST): Selalu mulai High Score dari 0 saat refresh
|
||||||
|
highScore = 0;
|
||||||
|
}
|
||||||
|
// -------------------------
|
||||||
|
|
||||||
let lastMoveDir = null;
|
let lastMoveDir = null;
|
||||||
let isMoving = false;
|
let isMoving = false;
|
||||||
let mergesInCurrentMove = 0;
|
let mergesInCurrentMove = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user