Spaces:
Running
Running
File size: 51,126 Bytes
9d93e5f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Epic Quest RPG</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.animate-pulse-slow {
animation: pulse 3s infinite;
}
.health-bar {
transition: width 0.5s ease;
}
.fade-in {
animation: fadeIn 0.5s;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.damage-popup {
animation: popup 1s forwards;
}
@keyframes popup {
0% { transform: translateY(0); opacity: 1; }
100% { transform: translateY(-50px); opacity: 0; }
}
</style>
</head>
<body class="bg-gray-900 text-white min-h-screen">
<div class="container mx-auto px-4 py-8">
<!-- Game Title -->
<header class="text-center mb-8">
<h1 class="text-5xl font-bold text-yellow-400 mb-2">Epic Quest</h1>
<p class="text-xl text-gray-300">A JavaScript RPG Adventure</p>
</header>
<!-- Game Container -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Left Panel - Character Info -->
<div id="characterPanel" class="bg-gray-800 rounded-lg p-6 shadow-lg hidden">
<h2 class="text-2xl font-bold text-yellow-400 mb-4 border-b border-gray-700 pb-2">Character</h2>
<div class="flex items-center mb-6">
<div class="w-20 h-20 bg-gray-700 rounded-full flex items-center justify-center text-4xl mr-4">
<span id="characterIcon">👤</span>
</div>
<div>
<h3 id="characterName" class="text-xl font-bold">Unknown Hero</h3>
<div class="flex items-center">
<span id="characterLevel" class="bg-blue-600 text-xs px-2 py-1 rounded mr-2">Lvl 1</span>
<span id="characterClass" class="bg-purple-600 text-xs px-2 py-1 rounded">Class</span>
</div>
</div>
</div>
<div class="mb-4">
<div class="flex justify-between mb-1">
<span>Health</span>
<span id="healthText">100/100</span>
</div>
<div class="w-full bg-gray-700 rounded-full h-4">
<div id="healthBar" class="health-bar bg-red-600 h-4 rounded-full" style="width: 100%"></div>
</div>
</div>
<div class="mb-4">
<div class="flex justify-between mb-1">
<span>Experience</span>
<span id="expText">0/100</span>
</div>
<div class="w-full bg-gray-700 rounded-full h-4">
<div id="expBar" class="health-bar bg-blue-500 h-4 rounded-full" style="width: 0%"></div>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mb-6">
<div class="bg-gray-700 p-3 rounded">
<div class="text-sm text-gray-400">Strength</div>
<div id="strengthStat" class="text-xl font-bold">10</div>
</div>
<div class="bg-gray-700 p-3 rounded">
<div class="text-sm text-gray-400">Dexterity</div>
<div id="dexterityStat" class="text-xl font-bold">10</div>
</div>
<div class="bg-gray-700 p-3 rounded">
<div class="text-sm text-gray-400">Intellect</div>
<div id="intellectStat" class="text-xl font-bold">10</div>
</div>
<div class="bg-gray-700 p-3 rounded">
<div class="text-sm text-gray-400">Defense</div>
<div id="defenseStat" class="text-xl font-bold">10</div>
</div>
</div>
<div class="mb-6">
<h3 class="text-lg font-semibold mb-2 text-gray-300">Equipment</h3>
<div class="grid grid-cols-3 gap-2">
<div class="equip-slot bg-gray-700 p-2 rounded text-center" data-slot="weapon">
<div class="text-xs text-gray-400">Weapon</div>
<div id="weaponSlot" class="text-xl">-</div>
</div>
<div class="equip-slot bg-gray-700 p-2 rounded text-center" data-slot="armor">
<div class="text-xs text-gray-400">Armor</div>
<div id="armorSlot" class="text-xl">-</div>
</div>
<div class="equip-slot bg-gray-700 p-2 rounded text-center" data-slot="shield">
<div class="text-xs text-gray-400">Shield</div>
<div id="shieldSlot" class="text-xl">-</div>
</div>
</div>
</div>
<div>
<h3 class="text-lg font-semibold mb-2 text-gray-300">Inventory</h3>
<div id="inventory" class="bg-gray-700 p-3 rounded max-h-40 overflow-y-auto">
<p class="text-gray-500 text-center py-4">Empty</p>
</div>
</div>
</div>
<!-- Center Panel - Game Content -->
<div class="lg:col-span-2">
<!-- Character Creation -->
<div id="characterCreation" class="bg-gray-800 rounded-lg p-6 shadow-lg mb-6">
<h2 class="text-2xl font-bold text-yellow-400 mb-6 text-center">Create Your Hero</h2>
<div class="mb-6">
<label for="heroName" class="block text-gray-300 mb-2">Hero Name</label>
<input type="text" id="heroName" class="w-full bg-gray-700 border border-gray-600 rounded py-2 px-3 focus:outline-none focus:ring-2 focus:ring-yellow-500" placeholder="Enter your hero's name">
</div>
<div class="mb-6">
<label class="block text-gray-300 mb-3">Choose a Class</label>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="class-option bg-gray-700 p-4 rounded-lg border-2 border-transparent hover:border-yellow-500 cursor-pointer transition-all" data-class="warrior">
<div class="text-4xl mb-2">🛡️</div>
<h3 class="font-bold text-lg">Warrior</h3>
<p class="text-sm text-gray-400">Strong and tough, excels in melee combat</p>
<div class="mt-3 text-xs">
<div>+5 Strength</div>
<div>+3 Defense</div>
</div>
</div>
<div class="class-option bg-gray-700 p-4 rounded-lg border-2 border-transparent hover:border-yellow-500 cursor-pointer transition-all" data-class="rogue">
<div class="text-4xl mb-2">🗡️</div>
<h3 class="font-bold text-lg">Rogue</h3>
<p class="text-sm text-gray-400">Quick and deadly, specializes in critical hits</p>
<div class="mt-3 text-xs">
<div>+5 Dexterity</div>
<div>+3 Strength</div>
</div>
</div>
<div class="class-option bg-gray-700 p-4 rounded-lg border-2 border-transparent hover:border-yellow-500 cursor-pointer transition-all" data-class="mage">
<div class="text-4xl mb-2">🔮</div>
<h3 class="font-bold text-lg">Mage</h3>
<p class="text-sm text-gray-400">Master of arcane arts, powerful spells</p>
<div class="mt-3 text-xs">
<div>+5 Intellect</div>
<div>+3 Dexterity</div>
</div>
</div>
</div>
</div>
<button id="startGameBtn" class="w-full bg-yellow-600 hover:bg-yellow-700 text-white font-bold py-3 px-4 rounded-lg transition-all animate-pulse-slow">
Begin Your Adventure
</button>
</div>
<!-- Game Display -->
<div id="gameDisplay" class="hidden">
<div class="bg-gray-800 rounded-lg p-6 shadow-lg mb-6 min-h-64">
<div id="gameText" class="mb-4 text-lg">
<p>Welcome to the world of Aetheria! Your adventure begins now...</p>
</div>
<div id="combatLog" class="bg-gray-900 p-3 rounded max-h-32 overflow-y-auto mb-4 hidden">
<!-- Combat messages will appear here -->
</div>
<div id="enemyDisplay" class="hidden text-center mb-6">
<div class="inline-block bg-gray-700 p-4 rounded-lg">
<div id="enemyIcon" class="text-6xl mb-2">👹</div>
<h3 id="enemyName" class="text-xl font-bold">Enemy</h3>
<div class="w-full bg-gray-600 rounded-full h-3 mt-2">
<div id="enemyHealthBar" class="health-bar bg-red-600 h-3 rounded-full" style="width: 100%"></div>
</div>
<div id="enemyHealthText" class="text-xs mt-1">100/100</div>
</div>
</div>
<div id="damageContainer" class="relative h-20">
<!-- Damage numbers will appear here -->
</div>
</div>
<!-- Action Buttons -->
<div id="actionButtons" class="grid grid-cols-2 gap-4 hidden">
<button id="exploreBtn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-4 rounded-lg transition-all">
<i class="fas fa-binoculars mr-2"></i> Explore
</button>
<button id="inventoryBtn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded-lg transition-all">
<i class="fas fa-backpack mr-2"></i> Inventory
</button>
<button id="questsBtn" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-4 rounded-lg transition-all">
<i class="fas fa-scroll mr-2"></i> Quests
</button>
<button id="restBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-lg transition-all">
<i class="fas fa-campground mr-2"></i> Rest
</button>
</div>
<!-- Combat Buttons -->
<div id="combatButtons" class="grid grid-cols-2 gap-4 hidden">
<button id="attackBtn" class="bg-red-600 hover:bg-red-700 text-white font-bold py-3 px-4 rounded-lg transition-all">
<i class="fas fa-sword mr-2"></i> Attack
</button>
<button id="specialBtn" class="bg-yellow-600 hover:bg-yellow-700 text-white font-bold py-3 px-4 rounded-lg transition-all">
<i class="fas fa-fire mr-2"></i> Special
</button>
<button id="defendBtn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded-lg transition-all">
<i class="fas fa-shield-alt mr-2"></i> Defend
</button>
<button id="fleeBtn" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-3 px-4 rounded-lg transition-all">
<i class="fas fa-running mr-2"></i> Flee
</button>
</div>
<!-- Quest Log -->
<div id="questLog" class="bg-gray-800 rounded-lg p-6 shadow-lg hidden">
<div class="flex justify-between items-center mb-4">
<h2 class="text-2xl font-bold text-yellow-400">Quests</h2>
<button id="closeQuestsBtn" class="text-gray-400 hover:text-white">
<i class="fas fa-times"></i>
</button>
</div>
<div id="activeQuests" class="mb-6">
<h3 class="text-lg font-semibold mb-2 text-gray-300">Active Quests</h3>
<div id="questList" class="space-y-3">
<div class="quest bg-gray-700 p-3 rounded border-l-4 border-yellow-500">
<div class="flex justify-between">
<h4 class="font-bold">First Steps</h4>
<span class="text-xs bg-blue-600 px-2 py-1 rounded">New</span>
</div>
<p class="text-sm text-gray-400 mt-1">Defeat 3 enemies to prove your worth</p>
<div class="w-full bg-gray-600 rounded-full h-2 mt-2">
<div class="bg-blue-500 h-2 rounded-full" style="width: 0%"></div>
</div>
<div class="text-xs text-right mt-1">0/3</div>
</div>
</div>
</div>
</div>
<!-- Inventory Modal -->
<div id="inventoryModal" class="bg-gray-800 rounded-lg p-6 shadow-lg hidden">
<div class="flex justify-between items-center mb-4">
<h2 class="text-2xl font-bold text-yellow-400">Inventory</h2>
<button id="closeInventoryBtn" class="text-gray-400 hover:text-white">
<i class="fas fa-times"></i>
</button>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<h3 class="text-lg font-semibold mb-2 text-gray-300">Items</h3>
<div id="inventoryItems" class="bg-gray-700 p-3 rounded max-h-64 overflow-y-auto">
<!-- Items will be listed here -->
</div>
</div>
<div>
<h3 class="text-lg font-semibold mb-2 text-gray-300">Item Info</h3>
<div id="itemInfo" class="bg-gray-700 p-4 rounded h-64 flex items-center justify-center">
<p class="text-gray-500">Select an item to view details</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Game State
const gameState = {
player: {
name: '',
class: '',
level: 1,
exp: 0,
maxExp: 100,
health: 100,
maxHealth: 100,
stats: {
strength: 10,
dexterity: 10,
intellect: 10,
defense: 10
},
equipment: {
weapon: null,
armor: null,
shield: null
},
inventory: [],
quests: [
{
id: 1,
name: 'First Steps',
description: 'Defeat 3 enemies to prove your worth',
completed: false,
progress: 0,
required: 3,
reward: { exp: 50, gold: 20, items: ['health_potion'] }
}
],
enemiesDefeated: 0
},
inCombat: false,
currentEnemy: null,
gameMessages: [],
locations: [
'Dark Forest',
'Misty Mountains',
'Forgotten Ruins',
'Haunted Castle',
'Dragon\'s Lair'
],
enemies: [
{ name: 'Goblin', health: 30, maxHealth: 30, attack: 8, defense: 3, exp: 15, icon: '👺' },
{ name: 'Orc', health: 50, maxHealth: 50, attack: 12, defense: 5, exp: 25, icon: '👹' },
{ name: 'Skeleton', health: 25, maxHealth: 25, attack: 10, defense: 2, exp: 20, icon: '💀' },
{ name: 'Troll', health: 80, maxHealth: 80, attack: 15, defense: 8, exp: 40, icon: '🧌' },
{ name: 'Dragon', health: 150, maxHealth: 150, attack: 25, defense: 15, exp: 100, icon: '🐉' }
],
items: {
health_potion: { name: 'Health Potion', effect: 'Restores 30 HP', icon: '🧪', type: 'consumable', value: 10 },
sword: { name: 'Iron Sword', effect: '+5 Attack', icon: '⚔️', type: 'weapon', stat: 'strength', value: 5 },
armor: { name: 'Leather Armor', effect: '+5 Defense', icon: '🛡️', type: 'armor', stat: 'defense', value: 5 },
shield: { name: 'Wooden Shield', effect: '+3 Defense', icon: '🛡️', type: 'shield', stat: 'defense', value: 3 },
spellbook: { name: 'Spellbook', effect: '+5 Intellect', icon: '📖', type: 'weapon', stat: 'intellect', value: 5 }
}
};
// DOM Elements
const characterCreation = document.getElementById('characterCreation');
const gameDisplay = document.getElementById('gameDisplay');
const characterPanel = document.getElementById('characterPanel');
const heroNameInput = document.getElementById('heroName');
const classOptions = document.querySelectorAll('.class-option');
const startGameBtn = document.getElementById('startGameBtn');
const characterName = document.getElementById('characterName');
const characterLevel = document.getElementById('characterLevel');
const characterClass = document.getElementById('characterClass');
const characterIcon = document.getElementById('characterIcon');
const healthBar = document.getElementById('healthBar');
const healthText = document.getElementById('healthText');
const expBar = document.getElementById('expBar');
const expText = document.getElementById('expText');
const strengthStat = document.getElementById('strengthStat');
const dexterityStat = document.getElementById('dexterityStat');
const intellectStat = document.getElementById('intellectStat');
const defenseStat = document.getElementById('defenseStat');
const weaponSlot = document.getElementById('weaponSlot');
const armorSlot = document.getElementById('armorSlot');
const shieldSlot = document.getElementById('shieldSlot');
const inventory = document.getElementById('inventory');
const gameText = document.getElementById('gameText');
const combatLog = document.getElementById('combatLog');
const enemyDisplay = document.getElementById('enemyDisplay');
const enemyName = document.getElementById('enemyName');
const enemyIcon = document.getElementById('enemyIcon');
const enemyHealthBar = document.getElementById('enemyHealthBar');
const enemyHealthText = document.getElementById('enemyHealthText');
const damageContainer = document.getElementById('damageContainer');
const actionButtons = document.getElementById('actionButtons');
const exploreBtn = document.getElementById('exploreBtn');
const inventoryBtn = document.getElementById('inventoryBtn');
const questsBtn = document.getElementById('questsBtn');
const restBtn = document.getElementById('restBtn');
const combatButtons = document.getElementById('combatButtons');
const attackBtn = document.getElementById('attackBtn');
const specialBtn = document.getElementById('specialBtn');
const defendBtn = document.getElementById('defendBtn');
const fleeBtn = document.getElementById('fleeBtn');
const questLog = document.getElementById('questLog');
const questList = document.getElementById('questList');
const closeQuestsBtn = document.getElementById('closeQuestsBtn');
const inventoryModal = document.getElementById('inventoryModal');
const inventoryItems = document.getElementById('inventoryItems');
const itemInfo = document.getElementById('itemInfo');
const closeInventoryBtn = document.getElementById('closeInventoryBtn');
// Event Listeners
startGameBtn.addEventListener('click', startGame);
classOptions.forEach(option => {
option.addEventListener('click', selectClass);
});
exploreBtn.addEventListener('click', explore);
inventoryBtn.addEventListener('click', openInventory);
questsBtn.addEventListener('click', openQuests);
restBtn.addEventListener('click', rest);
attackBtn.addEventListener('click', playerAttack);
specialBtn.addEventListener('click', specialAttack);
defendBtn.addEventListener('click', defend);
fleeBtn.addEventListener('click', flee);
closeQuestsBtn.addEventListener('click', closeQuests);
closeInventoryBtn.addEventListener('click', closeInventory);
// Game Functions
function startGame() {
const name = heroNameInput.value.trim();
if (!name) {
alert('Please enter a name for your hero!');
return;
}
if (!gameState.player.class) {
alert('Please select a class for your hero!');
return;
}
gameState.player.name = name;
// Apply class bonuses
switch(gameState.player.class) {
case 'warrior':
gameState.player.stats.strength += 5;
gameState.player.stats.defense += 3;
gameState.player.inventory.push('sword');
gameState.player.inventory.push('armor');
break;
case 'rogue':
gameState.player.stats.dexterity += 5;
gameState.player.stats.strength += 3;
gameState.player.inventory.push('sword');
break;
case 'mage':
gameState.player.stats.intellect += 5;
gameState.player.stats.dexterity += 3;
gameState.player.inventory.push('spellbook');
break;
}
// Start with a health potion
gameState.player.inventory.push('health_potion');
// Equip starting items
equipStartingItems();
// Hide character creation, show game
characterCreation.classList.add('hidden');
gameDisplay.classList.remove('hidden');
characterPanel.classList.remove('hidden');
// Update UI
updateCharacterUI();
// Add welcome message
addGameMessage(`Welcome, ${gameState.player.name} the ${gameState.player.class}! Your adventure begins...`);
// Show action buttons
actionButtons.classList.remove('hidden');
}
function selectClass(e) {
const selectedClass = e.currentTarget.dataset.class;
gameState.player.class = selectedClass;
// Update UI
classOptions.forEach(option => {
option.classList.remove('border-yellow-500');
if (option.dataset.class === selectedClass) {
option.classList.add('border-yellow-500');
}
});
}
function equipStartingItems() {
if (gameState.player.class === 'warrior') {
gameState.player.equipment.weapon = 'sword';
gameState.player.equipment.armor = 'armor';
} else if (gameState.player.class === 'rogue') {
gameState.player.equipment.weapon = 'sword';
} else if (gameState.player.class === 'mage') {
gameState.player.equipment.weapon = 'spellbook';
}
}
function updateCharacterUI() {
characterName.textContent = gameState.player.name;
characterLevel.textContent = `Lvl ${gameState.player.level}`;
characterClass.textContent = gameState.player.class.charAt(0).toUpperCase() + gameState.player.class.slice(1);
// Set class icon
let icon = '👤';
if (gameState.player.class === 'warrior') icon = '🛡️';
if (gameState.player.class === 'rogue') icon = '🗡️';
if (gameState.player.class === 'mage') icon = '🔮';
characterIcon.textContent = icon;
// Update stats
healthBar.style.width = `${(gameState.player.health / gameState.player.maxHealth) * 100}%`;
healthText.textContent = `${gameState.player.health}/${gameState.player.maxHealth}`;
expBar.style.width = `${(gameState.player.exp / gameState.player.maxExp) * 100}%`;
expText.textContent = `${gameState.player.exp}/${gameState.player.maxExp}`;
strengthStat.textContent = gameState.player.stats.strength;
dexterityStat.textContent = gameState.player.stats.dexterity;
intellectStat.textContent = gameState.player.stats.intellect;
defenseStat.textContent = gameState.player.stats.defense;
// Update equipment
weaponSlot.textContent = gameState.player.equipment.weapon ? gameState.items[gameState.player.equipment.weapon].icon : '-';
armorSlot.textContent = gameState.player.equipment.armor ? gameState.items[gameState.player.equipment.armor].icon : '-';
shieldSlot.textContent = gameState.player.equipment.shield ? gameState.items[gameState.player.equipment.shield].icon : '-';
// Update inventory
updateInventoryUI();
}
function updateInventoryUI() {
inventoryItems.innerHTML = '';
if (gameState.player.inventory.length === 0) {
inventoryItems.innerHTML = '<p class="text-gray-500 text-center py-4">Empty</p>';
return;
}
// Count items
const itemCounts = {};
gameState.player.inventory.forEach(item => {
itemCounts[item] = (itemCounts[item] || 0) + 1;
});
// Display items
Object.keys(itemCounts).forEach(itemKey => {
const item = gameState.items[itemKey];
const itemElement = document.createElement('div');
itemElement.className = 'flex justify-between items-center p-2 hover:bg-gray-600 rounded cursor-pointer';
itemElement.dataset.item = itemKey;
itemElement.innerHTML = `
<div class="flex items-center">
<span class="text-xl mr-3">${item.icon}</span>
<span>${item.name}</span>
</div>
<span class="bg-gray-800 px-2 py-1 rounded text-xs">x${itemCounts[itemKey]}</span>
`;
itemElement.addEventListener('click', () => showItemInfo(itemKey));
inventoryItems.appendChild(itemElement);
});
}
function showItemInfo(itemKey) {
const item = gameState.items[itemKey];
itemInfo.innerHTML = `
<div class="text-center">
<span class="text-5xl mb-2">${item.icon}</span>
<h3 class="text-xl font-bold mb-1">${item.name}</h3>
<p class="text-gray-300 mb-3">${item.effect}</p>
${item.type === 'consumable' ?
`<button class="use-item bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded" data-item="${itemKey}">
Use
</button>` :
(!gameState.player.equipment[item.type] || gameState.player.equipment[item.type] !== itemKey) ?
`<button class="equip-item bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" data-item="${itemKey}" data-type="${item.type}">
Equip
</button>` :
`<button class="unequip-item bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded" data-item="${itemKey}" data-type="${item.type}">
Unequip
</button>`
}
</div>
`;
// Add event listeners to buttons
const useBtn = itemInfo.querySelector('.use-item');
const equipBtn = itemInfo.querySelector('.equip-item');
const unequipBtn = itemInfo.querySelector('.unequip-item');
if (useBtn) {
useBtn.addEventListener('click', () => useItem(itemKey));
}
if (equipBtn) {
equipBtn.addEventListener('click', () => equipItem(itemKey, item.type));
}
if (unequipBtn) {
unequipBtn.addEventListener('click', () => unequipItem(itemKey, item.type));
}
}
function useItem(itemKey) {
const item = gameState.items[itemKey];
if (item.type === 'consumable') {
if (itemKey === 'health_potion') {
const healAmount = 30;
gameState.player.health = Math.min(gameState.player.health + healAmount, gameState.player.maxHealth);
addGameMessage(`You used a Health Potion and recovered ${healAmount} HP!`);
// Remove item from inventory
const index = gameState.player.inventory.indexOf(itemKey);
if (index !== -1) {
gameState.player.inventory.splice(index, 1);
}
// Update UI
updateCharacterUI();
showItemInfo(itemKey);
}
}
}
function equipItem(itemKey, itemType) {
// Unequip current item if any
if (gameState.player.equipment[itemType]) {
unequipItem(gameState.player.equipment[itemType], itemType);
}
// Equip new item
gameState.player.equipment[itemType] = itemKey;
const item = gameState.items[itemKey];
// Apply stat bonus
if (item.stat) {
gameState.player.stats[item.stat] += item.value;
}
addGameMessage(`You equipped ${item.name}!`);
updateCharacterUI();
showItemInfo(itemKey);
}
function unequipItem(itemKey, itemType) {
const item = gameState.items[itemKey];
// Remove stat bonus
if (item.stat) {
gameState.player.stats[item.stat] -= item.value;
}
gameState.player.equipment[itemType] = null;
addGameMessage(`You unequipped ${item.name}!`);
updateCharacterUI();
showItemInfo(itemKey);
}
function addGameMessage(message) {
const messageElement = document.createElement('p');
messageElement.className = 'fade-in';
messageElement.textContent = message;
gameText.insertBefore(messageElement, gameText.firstChild);
// Limit number of messages
if (gameText.children.length > 5) {
gameText.removeChild(gameText.lastChild);
}
}
function addCombatMessage(message) {
const messageElement = document.createElement('p');
messageElement.className = 'text-sm fade-in';
messageElement.textContent = message;
combatLog.insertBefore(messageElement, combatLog.firstChild);
// Limit number of messages
if (combatLog.children.length > 5) {
combatLog.removeChild(combatLog.lastChild);
}
}
function showDamage(value, isPlayer, isCritical = false) {
const damageElement = document.createElement('div');
damageElement.className = `damage-popup absolute ${isPlayer ? 'right-10' : 'left-10'} text-2xl font-bold ${isCritical ? 'text-yellow-400' : isPlayer ? 'text-red-500' : 'text-green-500'}`;
damageElement.textContent = `${isPlayer ? '-' : '+'}${value}`;
damageContainer.appendChild(damageElement);
// Remove after animation
setTimeout(() => {
damageElement.remove();
}, 1000);
}
function explore() {
if (gameState.inCombat) return;
const location = gameState.locations[Math.floor(Math.random() * gameState.locations.length)];
addGameMessage(`You explore the ${location}...`);
// 60% chance of combat
if (Math.random() < 0.6) {
startCombat();
} else {
// 30% chance of finding an item
if (Math.random() < 0.3) {
const items = Object.keys(gameState.items);
const randomItem = items[Math.floor(Math.random() * items.length)];
gameState.player.inventory.push(randomItem);
addGameMessage(`You found a ${gameState.items[randomItem].name}!`);
updateCharacterUI();
} else {
addGameMessage('You find nothing of interest.');
}
}
}
function startCombat() {
gameState.inCombat = true;
const enemyIndex = Math.min(Math.floor(gameState.player.level / 2), gameState.enemies.length - 1);
gameState.currentEnemy = {...gameState.enemies[enemyIndex]};
// Scale enemy stats based on player level
gameState.currentEnemy.maxHealth += (gameState.player.level - 1) * 10;
gameState.currentEnemy.health = gameState.currentEnemy.maxHealth;
gameState.currentEnemy.attack += (gameState.player.level - 1) * 2;
gameState.currentEnemy.defense += (gameState.player.level - 1);
gameState.currentEnemy.exp += (gameState.player.level - 1) * 5;
// Update UI
enemyName.textContent = gameState.currentEnemy.name;
enemyIcon.textContent = gameState.currentEnemy.icon;
enemyHealthBar.style.width = '100%';
enemyHealthText.textContent = `${gameState.currentEnemy.health}/${gameState.currentEnemy.maxHealth}`;
enemyDisplay.classList.remove('hidden');
combatLog.classList.remove('hidden');
actionButtons.classList.add('hidden');
combatButtons.classList.remove('hidden');
addGameMessage(`A wild ${gameState.currentEnemy.name} appears!`);
addCombatMessage(`Combat begins!`);
}
function endCombat(playerWon) {
gameState.inCombat = false;
if (playerWon) {
const expGained = gameState.currentEnemy.exp;
gameState.player.exp += expGained;
gameState.player.enemiesDefeated++;
// Check for level up
checkLevelUp();
addGameMessage(`You defeated the ${gameState.currentEnemy.name} and gained ${expGained} EXP!`);
// Update quest progress
updateQuestProgress();
} else {
addGameMessage(`You were defeated by the ${gameState.currentEnemy.name}!`);
// Lose some EXP on defeat
const expLost = Math.floor(gameState.player.exp * 0.1);
gameState.player.exp = Math.max(0, gameState.player.exp - expLost);
if (expLost > 0) {
addGameMessage(`You lost ${expLost} EXP!`);
}
// Recover some health after defeat
gameState.player.health = Math.floor(gameState.player.maxHealth * 0.3);
}
// Update UI
updateCharacterUI();
enemyDisplay.classList.add('hidden');
combatLog.classList.add('hidden');
actionButtons.classList.remove('hidden');
combatButtons.classList.add('hidden');
// Clear combat log
combatLog.innerHTML = '';
}
function playerAttack() {
if (!gameState.inCombat) return;
// Calculate damage
let baseDamage = Math.floor(gameState.player.stats.strength * 0.8 + gameState.player.stats.dexterity * 0.2);
// Check for critical hit (10% chance)
const isCritical = Math.random() < 0.1;
if (isCritical) {
baseDamage *= 2;
addCombatMessage('Critical hit!');
}
// Apply enemy defense
const finalDamage = Math.max(1, baseDamage - Math.floor(gameState.currentEnemy.defense * 0.5));
// Apply damage
gameState.currentEnemy.health -= finalDamage;
// Update UI
enemyHealthBar.style.width = `${(gameState.currentEnemy.health / gameState.currentEnemy.maxHealth) * 100}%`;
enemyHealthText.textContent = `${Math.max(0, gameState.currentEnemy.health)}/${gameState.currentEnemy.maxHealth}`;
// Show damage
showDamage(finalDamage, false, isCritical);
addCombatMessage(`You hit the ${gameState.currentEnemy.name} for ${finalDamage} damage!`);
// Check if enemy is defeated
if (gameState.currentEnemy.health <= 0) {
endCombat(true);
return;
}
// Enemy attacks back
setTimeout(enemyAttack, 1000);
}
function specialAttack() {
if (!gameState.inCombat) return;
// Different special attacks based on class
let baseDamage = 0;
let specialMessage = '';
switch(gameState.player.class) {
case 'warrior':
baseDamage = Math.floor(gameState.player.stats.strength * 1.5);
specialMessage = 'You unleash a mighty swing!';
break;
case 'rogue':
baseDamage = Math.floor(gameState.player.stats.dexterity * 1.2);
// Rogues have higher crit chance on special
if (Math.random() < 0.3) {
baseDamage *= 2;
specialMessage = 'You strike a vulnerable spot! (Critical hit)';
} else {
specialMessage = 'You perform a precise strike!';
}
break;
case 'mage':
baseDamage = Math.floor(gameState.player.stats.intellect * 1.3);
specialMessage = 'You cast a powerful spell!';
break;
}
// Apply enemy defense (less effective against special attacks)
const finalDamage = Math.max(1, baseDamage - Math.floor(gameState.currentEnemy.defense * 0.3));
// Apply damage
gameState.currentEnemy.health -= finalDamage;
// Update UI
enemyHealthBar.style.width = `${(gameState.currentEnemy.health / gameState.currentEnemy.maxHealth) * 100}%`;
enemyHealthText.textContent = `${Math.max(0, gameState.currentEnemy.health)}/${gameState.currentEnemy.maxHealth}`;
// Show damage
showDamage(finalDamage, false, true);
addCombatMessage(specialMessage);
addCombatMessage(`You hit the ${gameState.currentEnemy.name} for ${finalDamage} damage!`);
// Check if enemy is defeated
if (gameState.currentEnemy.health <= 0) {
endCombat(true);
return;
}
// Enemy attacks back
setTimeout(enemyAttack, 1000);
}
function defend() {
if (!gameState.inCombat) return;
// Reduce incoming damage by 50%
const defenseMultiplier = 0.5;
addCombatMessage('You take a defensive stance!');
// Enemy attacks
setTimeout(() => {
enemyAttack(defenseMultiplier);
}, 1000);
}
function flee() {
if (!gameState.inCombat) return;
// 70% chance to flee successfully
if (Math.random() < 0.7) {
addCombatMessage('You successfully fled from battle!');
endCombat(false);
} else {
addCombatMessage('You failed to flee!');
// Enemy attacks
setTimeout(enemyAttack, 1000);
}
}
function enemyAttack(defenseMultiplier = 1) {
if (!gameState.inCombat) return;
// Calculate damage
let baseDamage = Math.floor(gameState.currentEnemy.attack * (0.8 + Math.random() * 0.4));
// Apply player defense
const finalDamage = Math.max(1, Math.floor(baseDamage * defenseMultiplier - gameState.player.stats.defense * 0.3));
// Apply damage
gameState.player.health -= finalDamage;
// Update UI
healthBar.style.width = `${(gameState.player.health / gameState.player.maxHealth) * 100}%`;
healthText.textContent = `${Math.max(0, gameState.player.health)}/${gameState.player.maxHealth}`;
// Show damage
showDamage(finalDamage, true);
addCombatMessage(`The ${gameState.currentEnemy.name} hits you for ${finalDamage} damage!`);
// Check if player is defeated
if (gameState.player.health <= 0) {
endCombat(false);
}
}
function checkLevelUp() {
if (gameState.player.exp >= gameState.player.maxExp) {
gameState.player.level++;
gameState.player.exp -= gameState.player.maxExp;
gameState.player.maxExp = Math.floor(gameState.player.maxExp * 1.5);
// Increase stats
gameState.player.maxHealth += 10 + gameState.player.level;
gameState.player.health = gameState.player.maxHealth;
gameState.player.stats.strength += 2;
gameState.player.stats.dexterity += 2;
gameState.player.stats.intellect += 2;
gameState.player.stats.defense += 2;
// Class-specific bonuses
switch(gameState.player.class) {
case 'warrior':
gameState.player.stats.strength += 2;
gameState.player.stats.defense += 2;
break;
case 'rogue':
gameState.player.stats.dexterity += 3;
gameState.player.stats.strength += 1;
break;
case 'mage':
gameState.player.stats.intellect += 3;
gameState.player.stats.dexterity += 1;
break;
}
addGameMessage(`Level up! You are now level ${gameState.player.level}!`);
updateCharacterUI();
// Check for another level up (unlikely but possible)
checkLevelUp();
}
}
function updateQuestProgress() {
const quest = gameState.player.quests[0]; // Only one quest in this simple version
if (!quest.completed) {
quest.progress++;
if (quest.progress >= quest.required) {
quest.completed = true;
addGameMessage(`Quest completed: ${quest.name}!`);
// Give rewards
gameState.player.exp += quest.reward.exp;
addGameMessage(`You gained ${quest.reward.exp} EXP!`);
if (quest.reward.items) {
quest.reward.items.forEach(item => {
gameState.player.inventory.push(item);
addGameMessage(`You received a ${gameState.items[item].name}!`);
});
}
// Check for level up from quest rewards
checkLevelUp();
// Update inventory UI if it's open
if (!inventoryModal.classList.contains('hidden')) {
updateInventoryUI();
}
}
// Update quest UI if it's open
if (!questLog.classList.contains('hidden')) {
updateQuestUI();
}
}
}
function openQuests() {
updateQuestUI();
questLog.classList.remove('hidden');
}
function closeQuests() {
questLog.classList.add('hidden');
}
function updateQuestUI() {
questList.innerHTML = '';
gameState.player.quests.forEach(quest => {
const questElement = document.createElement('div');
questElement.className = 'quest bg-gray-700 p-3 rounded border-l-4 border-yellow-500';
questElement.innerHTML = `
<div class="flex justify-between">
<h4 class="font-bold">${quest.name}</h4>
${quest.completed ?
'<span class="text-xs bg-green-600 px-2 py-1 rounded">Completed</span>' :
'<span class="text-xs bg-blue-600 px-2 py-1 rounded">In Progress</span>'}
</div>
<p class="text-sm text-gray-400 mt-1">${quest.description}</p>
<div class="w-full bg-gray-600 rounded-full h-2 mt-2">
<div class="bg-blue-500 h-2 rounded-full" style="width: ${(quest.progress / quest.required) * 100}%"></div>
</div>
<div class="text-xs text-right mt-1">${quest.progress}/${quest.required}</div>
`;
questList.appendChild(questElement);
});
}
function openInventory() {
updateInventoryUI();
inventoryModal.classList.remove('hidden');
}
function closeInventory() {
inventoryModal.classList.add('hidden');
}
function rest() {
const healAmount = Math.floor(gameState.player.maxHealth * 0.5);
gameState.player.health = Math.min(gameState.player.health + healAmount, gameState.player.maxHealth);
addGameMessage(`You rest and recover ${healAmount} HP.`);
updateCharacterUI();
}
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Timasthedev/epic-quest" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |