/* ===================================================== LOVE SCHOOL GAME ===================================================== */ /* ===================================================== CHARACTER DATA ===================================================== */ const characters = { ray: { id: "ray", name: "เรย์", type: "รุ่นพี่เย็นชา", avatar: "👦", description: "รุ่นพี่ผู้เงียบขรึม ชอบอ่านหนังสือ และมักเก็บความรู้สึกไว้ข้างใน", color: "#60a5fa" }, non: { id: "non", name: "นนท์", type: "เพื่อนขี้เล่น", avatar: "😎", description: "หนุ่มอารมณ์ดีที่ชอบสร้างเสียงหัวเราะ แต่จริง ๆ แล้วใส่ใจคนรอบตัวมาก", color: "#facc15" }, kin: { id: "kin", name: "คิน", type: "หนุ่มอบอุ่น", avatar: "😊", description: "หนุ่มใจดีที่คอยช่วยเหลือทุกคน และชอบกิจกรรมเกี่ยวกับดนตรี", color: "#86efac" } }; /* ===================================================== GAME STATE ===================================================== */ let game = { playerName: "", character: null, day: 1, maxDay: 15, love: 0, charm: 50, intelligence: 50, energy: 100, money: 100, gifts: 0, flags: {}, currentScene: null }; /* ===================================================== DOM ===================================================== */ const startScreen = document.getElementById("startScreen"); const characterScreen = document.getElementById("characterScreen"); const gameScreen = document.getElementById("gameScreen"); const endingScreen = document.getElementById("endingScreen"); /* ===================================================== START GAME ===================================================== */ function startGame() { const name = document.getElementById("playerName").value.trim(); if (!name) { Swal.fire({ icon: "warning", title: "ยังไม่ได้ใส่ชื่อ", text: "กรุณาใส่ชื่อของคุณก่อนเริ่มเกม", confirmButtonText: "ตกลง" }); return; } game = { playerName: name, character: null, day: 1, maxDay: 15, love: 0, charm: 50, intelligence: 50, energy: 100, money: 100, gifts: 0, flags: {}, currentScene: null }; showScreen(characterScreen); renderCharacters(); } /* ===================================================== SCREEN CONTROL ===================================================== */ function showScreen(screen) { document.querySelectorAll(".screen") .forEach(s => s.classList.remove("active")); screen.classList.add("active"); } /* ===================================================== CHARACTER SELECT ===================================================== */ function renderCharacters() { const container = document.getElementById("characterList"); container.innerHTML = ""; Object.values(characters).forEach(character => { const card = document.createElement("div"); card.className = "character-card"; card.innerHTML = `
${character.avatar}

${character.name}

${character.type}

${character.description}

`; container.appendChild(card); }); } /* ===================================================== SELECT CHARACTER ===================================================== */ function selectCharacter(id) { game.character = id; const character = characters[id]; Swal.fire({ title: `เลือก ${character.name} แล้ว 💗`, text: `เรื่องราวของ ${character.name} กำลังจะเริ่มขึ้น`, icon: "success", confirmButtonText: "เริ่มเลย!" }).then(() => { showScreen(gameScreen); updateStats(); showOpening(); }); } /* ===================================================== OPENING ===================================================== */ function showOpening() { const character = characters[game.character]; let text = ""; if (game.character === "ray") { text = `${game.playerName} เดินเข้าห้องสมุดในช่วงพักกลางวัน ก่อนจะเห็น ${character.name} กำลังอ่านหนังสืออยู่คนเดียว`; } else if (game.character === "non") { text = `${game.playerName} เดินเข้าโรงเรียนและได้ยินเสียงหัวเราะดังมาจากสนาม ก่อนจะพบกับ ${character.name}`; } else { text = `${game.playerName} กำลังช่วยจัดของในห้องกิจกรรม ก่อนจะได้พบกับ ${character.name} ที่กำลังถือกีตาร์อยู่`; } showDialogue( character.name, text, character.avatar, [ { text: "ทักเขาก่อน", love: 5, next: "firstMeet" }, { text: "ทำเป็นไม่เห็น", love: 0, next: "firstMeet" } ] ); } /* ===================================================== DIALOGUE ===================================================== */ function showDialogue( speaker, text, avatar, choices = [] ) { document.getElementById("speaker") .textContent = speaker; document.getElementById("dialogue") .textContent = text; document.getElementById("characterAvatar") .textContent = avatar; const choiceContainer = document.getElementById("choices"); choiceContainer.innerHTML = ""; choices.forEach((choice, index) => { const button = document.createElement("button"); button.className = "choice-btn"; button.textContent = `${String.fromCharCode(65 + index)}. ${choice.text}`; button.onclick = () => { if (choice.love) { game.love += choice.love; } if (choice.charm) { game.charm += choice.charm; } if (choice.money) { game.money += choice.money; } if (choice.flag) { game.flags[choice.flag] = true; } updateStats(); handleScene(choice.next); }; choiceContainer.appendChild(button); }); document.getElementById("actionMenu") .style.display = "none"; } /* ===================================================== SCENE HANDLER ===================================================== */ function handleScene(scene) { switch(scene) { case "firstMeet": firstMeet(); break; case "secondMeet": secondMeet(); break; case "special": specialEvent(); break; case "normal": showActionMenu(); break; default: showActionMenu(); } } /* ===================================================== FIRST MEETING ===================================================== */ function firstMeet() { const c = characters[game.character]; let text = ""; if (game.character === "ray") { text = `${c.name}: "เธอ...มาหาหนังสือเหรอ?"`; } else if (game.character === "non") { text = `${c.name}: "อ้าว! เพิ่งมาโรงเรียนเหรอ วันนี้หน้าตาดูง่วง ๆ นะ"`; } else { text = `${c.name}: "สวัสดี เธอมาช่วยงานชมรมเหมือนกันเหรอ?"`; } showDialogue( c.name, text, c.avatar, [ { text: "ตอบอย่างเป็นมิตร", love: 7, next: "secondMeet" }, { text: "ตอบแบบเขิน ๆ", love: 4, next: "secondMeet" }, { text: "ตอบสั้น ๆ", love: 1, next: "secondMeet" } ] ); } /* ===================================================== SECOND MEETING ===================================================== */ function secondMeet() { const c = characters[game.character]; let choices = []; if (game.character === "ray") { showDialogue( c.name, `${c.name}: "เธอชอบอ่านหนังสือแบบนี้เหมือนกันเหรอ?"`, c.avatar, [ { text: "ชอบสิ", love: 8, intelligence: 5, next: "normal" }, { text: "ไม่ค่อยอ่าน แต่ลองดูได้", love: 6, next: "normal" }, { text: "จริง ๆ ฉันไม่ค่อยชอบ", love: 0, next: "normal" } ] ); } else if (game.character === "non") { showDialogue( c.name, `${c.name}: "เย็นนี้ไปหาอะไรกินกันไหม?"`, c.avatar, [ { text: "ไปสิ!", love: 8, next: "normal" }, { text: "ถ้าไม่ไกลก็ได้", love: 5, next: "normal" }, { text: "วันนี้ขอผ่านนะ", love: 1, next: "normal" } ] ); } else { showDialogue( c.name, `${c.name}: "เพลงนี้ฉันกำลังฝึกอยู่ อยากฟังไหม?"`, c.avatar, [ { text: "อยากฟังมาก", love: 8, next: "normal" }, { text: "ได้สิ", love: 5, next: "normal" }, { text: "ไว้วันหลังก็ได้", love: 1, next: "normal" } ] ); } } /* ===================================================== ACTION MENU ===================================================== */ function showActionMenu() { document.getElementById("choices") .innerHTML = ""; document.getElementById("actionMenu") .style.display = "block"; } /* ===================================================== ACTIVITIES ===================================================== */ function doActivity(type) { if (game.energy <= 0 && type !== "rest") { Swal.fire({ icon: "warning", title: "เหนื่อยเกินไปแล้ว 😵", text: "ลองพักผ่อนก่อนนะ", confirmButtonText: "พักก่อน" }); return; } switch(type) { /* ===================== STUDY ===================== */ case "study": game.intelligence += 10; game.energy -= 20; notify( "📚 อ่านหนังสือสำเร็จ", "+10 ความฉลาด" ); break; /* ===================== WORK ===================== */ case "work": game.money += 40; game.energy -= 25; notify( "💼 ทำงานพิเศษ", "+40 เงิน" ); break; /* ===================== CHARM ===================== */ case "charm": game.charm += 10; game.energy -= 15; notify( "✨ ดูแลตัวเอง", "+10 เสน่ห์" ); break; /* ===================== MEET ===================== */ case "meet": game.love += 8; game.energy -= 25; notify( "💕 ได้ใช้เวลาร่วมกัน", "+8 ความสัมพันธ์" ); break; /* ===================== GIFT ===================== */ case "gift": if (game.money < 30) { Swal.fire({ icon: "error", title: "เงินไม่พอ 💸", text: "ต้องมีเงินอย่างน้อย 30", confirmButtonText: "ตกลง" }); return; } game.money -= 30; game.love += 15; game.gifts++; game.energy -= 10; notify( "🎁 มอบของขวัญ", "+15 ความสัมพันธ์" ); break; /* ===================== REST ===================== */ case "rest": game.energy = 100; notify( "💤 พักผ่อนแล้ว", "พลังงานเต็ม!" ); break; } updateStats(); setTimeout(() => { nextDay(); }, 900); } /* ===================================================== NEXT DAY ===================================================== */ function nextDay() { game.day++; if (game.day > game.maxDay) { calculateEnding(); return; } updateStats(); /* ทุก 3 วันมีโอกาสเกิดอีเวนต์ */ if (game.day === 5 || game.day === 9 || game.day === 12) { specialEvent(); } else { showRandomDialogue(); } } /* ===================================================== RANDOM DIALOGUE ===================================================== */ function showRandomDialogue() { const c = characters[game.character]; const dialogues = { ray: [ "วันนี้ห้องสมุดเงียบดีนะ... เธออยากนั่งตรงนี้ไหม?", "เธอดูตั้งใจเรียนดีนะ", "วันนี้เป็นยังไงบ้าง?" ], non: [ "วันนี้ดูสดใสดีนะ!", "รู้ไหม วันนี้ฉันมีเรื่องตลกจะเล่าให้ฟัง", "ไปเดินเล่นกันไหม?" ], kin: [ "วันนี้เหนื่อยไหม? พักบ้างนะ", "ถ้ามีอะไรให้ช่วยก็บอกฉันได้", "วันนี้อยากฟังเพลงอะไร?" ] }; const list = dialogues[game.character]; const text = list[Math.floor(Math.random() * list.length)]; showDialogue( c.name, text, c.avatar, [ { text: "ยิ้มและตอบกลับ", love: 5, next: "normal" }, { text: "พูดคุยต่อ", love: 8, next: "normal" }, { text: "แกล้งเขาเล่น", love: 3, charm: 3, next: "normal" } ] ); } /* ===================================================== SPECIAL EVENT ===================================================== */ function specialEvent() { const c = characters[game.character]; if (game.day === 5) { showDialogue( "เหตุการณ์พิเศษ", `${c.name} ชวนคุณไปเดินเล่นหลังเลิกเรียน`, c.avatar, [ { text: "ตอบตกลง", love: 15, flag: "dateAccepted", next: "normal" }, { text: "ขอคิดดูก่อน", love: 5, next: "normal" } ] ); } else if (game.day === 9) { showDialogue( "เหตุการณ์พิเศษ", `${c.name} ดูเหมือนจะมีเรื่องไม่สบายใจ คุณจะทำอย่างไร?`, c.avatar, [ { text: "ถามว่าเกิดอะไรขึ้น", love: 12, next: "normal" }, { text: "ปล่อยให้เขาอยู่คนเดียว", love: 0, next: "normal" } ] ); } else { showDialogue( "เหตุการณ์พิเศษ", `${c.name}: "ขอบคุณนะที่อยู่ข้าง ๆ กันมาตลอด"`, c.avatar, [ { text: "เราจะอยู่ตรงนี้เสมอ", love: 18, next: "normal" }, { text: "ไม่เป็นไรหรอก", love: 10, next: "normal" } ] ); } } /* ===================================================== ENDING ===================================================== */ function calculateEnding() { const love = game.love; let title; let text; let icon; if (love >= 100) { title = "💖 BEST ENDING"; icon = "💗"; text = `ตลอด 15 วันที่ผ่านมา ${characters[game.character].name} และ ${game.playerName} ได้เรียนรู้จักกันมากขึ้น ความสัมพันธ์ของทั้งคู่กลายเป็นความทรงจำที่แสนพิเศษ`; } else if (love >= 60) { title = "💕 GOOD ENDING"; icon = "🌸"; text = `ความสัมพันธ์ของ ${game.playerName} และ ${characters[game.character].name} เติบโตขึ้นอย่างช้า ๆ แม้เรื่องราวยังไม่จบ แต่ทั้งคู่ก็อยากรู้จักกันต่อไป`; } else if (love >= 30) { title = "🌷 NORMAL ENDING"; icon = "🌷"; text = `คุณกับ ${characters[game.character].name} กลายเป็นเพื่อนที่ดีต่อกัน และยังมีโอกาสได้สร้างความทรงจำใหม่ ๆ ในอนาคต`; } else { title = "🍃 BAD ENDING"; icon = "🍃"; text = `เรื่องราวของคุณกับ ${characters[game.character].name} จบลงโดยที่ความสัมพันธ์ยังไม่ทันได้พัฒนา แต่บางทีการเริ่มต้นใหม่อาจทำให้เรื่องราวเปลี่ยนไป`; } document.getElementById("endingIcon") .textContent = icon; document.getElementById("endingTitle") .textContent = title; document.getElementById("endingText") .textContent = text; document.getElementById("finalLove") .textContent = game.love; document.getElementById("finalCharm") .textContent = game.charm; document.getElementById("finalMoney") .textContent = game.money; showScreen(endingScreen); } /* ===================================================== UPDATE STATS ===================================================== */ function updateStats() { document.getElementById("dayText") .textContent = `วันที่ ${game.day} / ${game.maxDay}`; document.getElementById("loveStat") .textContent = Math.max(0, game.love); document.getElementById("charmStat") .textContent = Math.max(0, game.charm); document.getElementById("energyStat") .textContent = Math.max(0, game.energy); document.getElementById("moneyStat") .textContent = Math.max(0, game.money); } /* ===================================================== SWEET ALERT NOTIFICATION ===================================================== */ function notify(title, text) { Swal.fire({ icon: "success", title: title, text: text, timer: 1200, showConfirmButton: false, toast: true, position: "top-end" }); } /* ===================================================== STATUS ===================================================== */ function showStatus() { const c = characters[game.character]; Swal.fire({ title: "📊 สถานะของคุณ", html: `
👤 ชื่อ: ${game.playerName}
💕 คนที่กำลังทำความรู้จัก: ${c.name}
❤️ ความสัมพันธ์: ${game.love}
✨ เสน่ห์: ${game.charm}
🧠 ความฉลาด: ${game.intelligence}
⚡ พลังงาน: ${game.energy}
💰 เงิน: ${game.money}
🎁 ของขวัญ: ${game.gifts}
`, confirmButtonText: "ปิด" }); } /* ===================================================== SAVE GAME ===================================================== */ function saveGame() { localStorage.setItem( "loveSchoolSave", JSON.stringify(game) ); Swal.fire({ icon: "success", title: "บันทึกเกมแล้ว 💾", text: "สามารถกลับมาเล่นต่อได้", timer: 1200, showConfirmButton: false }); } /* ===================================================== LOAD GAME ===================================================== */ function loadGame() { const saved = localStorage.getItem("loveSchoolSave"); if (!saved) { Swal.fire({ icon: "info", title: "ยังไม่มีข้อมูล", text: "ยังไม่มีเกมที่บันทึกไว้", confirmButtonText: "ตกลง" }); return; } try { game = JSON.parse(saved); if (!game.character) { showScreen(characterScreen); renderCharacters(); } else { showScreen(gameScreen); updateStats(); showRandomDialogue(); } Swal.fire({ icon: "success", title: "โหลดเกมสำเร็จ 💗", timer: 1000, showConfirmButton: false }); } catch(error) { Swal.fire({ icon: "error", title: "โหลดเกมไม่สำเร็จ", text: "ข้อมูลเซฟอาจเสียหาย" }); } } /* ===================================================== RESTART ===================================================== */ function restartGame() { localStorage.removeItem("loveSchoolSave"); location.reload(); }