File size: 72,127 Bytes
9e27a10 |
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 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 |
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mini Clash of Clans</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>
.village-grid {
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: repeat(8, 1fr);
gap: 8px;
width: 600px;
height: 600px;
background-color: #4ade80;
padding: 10px;
border-radius: 8px;
position: relative;
overflow: hidden;
}
.grid-cell {
background-color: rgba(255, 255, 255, 0.2);
border-radius: 4px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: all 0.2s;
}
.grid-cell:hover {
background-color: rgba(255, 255, 255, 0.4);
}
.building {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
}
.attack-animation {
position: absolute;
width: 30px;
height: 30px;
background-color: red;
border-radius: 50%;
animation: attackMove 1s forwards;
}
@keyframes attackMove {
0% { transform: translate(0, 0); opacity: 1; }
100% { transform: translate(var(--tx), var(--ty)); opacity: 0; }
}
.damage-effect {
animation: damageShake 0.5s;
}
@keyframes damageShake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-5px); }
75% { transform: translateX(5px); }
}
.progress-bar {
height: 5px;
background-color: #4ade80;
width: 100%;
position: absolute;
bottom: 0;
left: 0;
border-radius: 0 0 4px 4px;
}
.progress-fill {
height: 100%;
background-color: #3b82f6;
width: 100%;
transition: width 0.3s;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 100;
justify-content: center;
align-items: center;
}
.modal-content {
background-color: white;
padding: 20px;
border-radius: 8px;
max-width: 800px;
width: 90%;
}
/* Animación para el splash screen */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.splash-screen {
animation: fadeIn 0.5s ease-out forwards;
}
/* Estilos para el chatbot */
.chatbot-container {
position: fixed;
bottom: 20px;
right: 20px;
width: 350px;
z-index: 1000;
transition: all 0.3s ease;
}
.chatbot-closed {
transform: translateY(100px);
}
.chatbot-header {
background-color: #3b82f6;
color: white;
padding: 12px 15px;
border-radius: 10px 10px 0 0;
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
}
.chatbot-body {
background-color: white;
border-radius: 0 0 10px 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
max-height: 400px;
overflow-y: auto;
display: none;
}
.chatbot-messages {
padding: 15px;
min-height: 200px;
max-height: 300px;
overflow-y: auto;
}
.chatbot-input {
display: flex;
padding: 10px;
border-top: 1px solid #eee;
}
.chatbot-input input {
flex: 1;
padding: 8px;
border: 1px solid #ddd;
border-radius: 20px;
outline: none;
}
.chatbot-input button {
background-color: #3b82f6;
color: white;
border: none;
border-radius: 20px;
padding: 8px 15px;
margin-left: 10px;
cursor: pointer;
}
.message {
margin-bottom: 10px;
padding: 8px 12px;
border-radius: 18px;
max-width: 80%;
word-wrap: break-word;
}
.bot-message {
background-color: #f1f5f9;
align-self: flex-start;
border-bottom-left-radius: 5px;
}
.user-message {
background-color: #3b82f6;
color: white;
align-self: flex-end;
margin-left: auto;
border-bottom-right-radius: 5px;
}
.suggest-btn {
background-color: #f59e0b;
color: white;
border: none;
border-radius: 20px;
padding: 8px 15px;
margin-top: 10px;
cursor: pointer;
font-size: 14px;
display: block;
width: 100%;
text-align: center;
}
.typing-indicator {
display: flex;
padding: 8px 12px;
}
.typing-dot {
width: 8px;
height: 8px;
background-color: #94a3b8;
border-radius: 50%;
margin: 0 2px;
animation: typingAnimation 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) {
animation-delay: 0s;
}
.typing-dot:nth-child(2) {
animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes typingAnimation {
0%, 60%, 100% { transform: translateY(0); }
30% { transform: translateY(-5px); }
}
/* Estilos para el modal de vista previa del enemigo */
.enemy-preview {
background-color: #f8fafc;
border: 2px solid #e2e8f0;
border-radius: 8px;
padding: 15px;
margin-bottom: 20px;
}
.enemy-grid {
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: repeat(8, 1fr);
gap: 4px;
width: 400px;
height: 400px;
background-color: #fecaca;
padding: 8px;
border-radius: 8px;
margin: 0 auto;
}
.enemy-cell {
background-color: rgba(255, 255, 255, 0.3);
border-radius: 3px;
display: flex;
justify-content: center;
align-items: center;
}
.enemy-building {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.enemy-stats {
display: flex;
justify-content: space-around;
margin-top: 15px;
padding: 10px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.stat-item {
text-align: center;
}
.stat-value {
font-weight: bold;
font-size: 1.2rem;
color: #3b82f6;
}
.stat-label {
font-size: 0.8rem;
color: #64748b;
}
.attack-options {
display: flex;
justify-content: center;
gap: 15px;
margin-top: 20px;
}
.attack-btn {
padding: 10px 20px;
border-radius: 8px;
font-weight: bold;
cursor: pointer;
transition: all 0.3s;
}
.attack-now {
background-color: #ef4444;
color: white;
border: none;
}
.attack-now:hover {
background-color: #dc2626;
}
.cancel-attack {
background-color: white;
color: #64748b;
border: 1px solid #e2e8f0;
}
.cancel-attack:hover {
background-color: #f8fafc;
}
</style>
</head>
<body class="bg-gray-100 min-h-screen flex flex-col items-center py-8">
<!-- Splash Screen -->
<div id="splash-screen" class="fixed inset-0 bg-blue-900 flex items-center justify-center z-50 splash-screen">
<div class="bg-white rounded-xl shadow-2xl p-8 max-w-2xl w-full mx-4">
<div class="flex justify-center mb-6">
<div class="bg-yellow-400 rounded-full w-20 h-20 flex items-center justify-center shadow-lg">
<i class="fas fa-chess-rook text-yellow-800 text-4xl"></i>
</div>
</div>
<h1 class="text-3xl font-bold text-center text-blue-800 mb-6">
¡Bienvenido a Mini Clash of Clans!
</h1>
<div class="space-y-4 mb-8">
<div class="flex items-start">
<div class="bg-blue-100 rounded-full w-8 h-8 flex-shrink-0 flex items-center justify-center mr-3 mt-1">
<i class="fas fa-info-circle text-blue-600"></i>
</div>
<p class="text-gray-700">
<strong>¿Qué es este juego?</strong><br>
Es una versión simplificada del popular juego Clash of Clans. Construye tu aldea,
recolecta recursos, entrena tropas y ataca aldeas enemigas para ganar recompensas.
</p>
</div>
<div class="flex items-start">
<div class="bg-green-100 rounded-full w-8 h-8 flex-shrink-0 flex items-center justify-center mr-3 mt-1">
<i class="fas fa-gamepad text-green-600"></i>
</div>
<p class="text-gray-700">
<strong>¿Cómo se juega?</strong><br>
1. <strong>Construye</strong> edificios en tu aldea usando oro.<br>
2. <strong>Recolecta</strong> oro y elixir para mejorar tus edificios.<br>
3. <strong>Entrena</strong> tropas usando elixir.<br>
4. <strong>Ataca</strong> aldeas enemigas para ganar más recursos.
</p>
</div>
<div class="flex items-start">
<div class="bg-purple-100 rounded-full w-8 h-8 flex-shrink-0 flex items-center justify-center mr-3 mt-1">
<i class="fas fa-trophy text-purple-600"></i>
</div>
<p class="text-gray-700">
<strong>Objetivo del juego</strong><br>
Destruye el ayuntamiento enemigo para ganar la batalla. Cuanto más desarrollada esté
tu aldea, más fuertes serán tus tropas y defensas.
</p>
</div>
</div>
<div class="flex justify-center">
<button id="start-game-btn" class="bg-blue-600 hover:bg-blue-700 text-white px-8 py-3 rounded-lg text-lg font-semibold transition-all transform hover:scale-105">
<i class="fas fa-play mr-2"></i>¡Comenzar a jugar!
</button>
</div>
</div>
</div>
<!-- Contenido principal del juego (oculto inicialmente) -->
<div id="game-container" class="container mx-auto px-4 hidden">
<h1 class="text-4xl font-bold text-center text-blue-800 mb-6">
<i class="fas fa-chess-rook mr-2"></i> Mini Clash of Clans
</h1>
<!-- Recursos -->
<div class="flex justify-between items-center bg-white rounded-lg shadow-md p-4 mb-6">
<div class="flex items-center">
<div class="bg-yellow-400 rounded-full w-10 h-10 flex items-center justify-center mr-2">
<i class="fas fa-coins text-yellow-800"></i>
</div>
<div>
<p class="text-sm text-gray-500">Oro</p>
<p id="gold-amount" class="font-bold text-lg">1000</p>
</div>
</div>
<div class="flex items-center">
<div class="bg-purple-500 rounded-full w-10 h-10 flex items-center justify-center mr-2">
<i class="fas fa-gem text-purple-100"></i>
</div>
<div>
<p class="text-sm text-gray-500">Elixir</p>
<p id="elixir-amount" class="font-bold text-lg">500</p>
</div>
</div>
<div class="flex items-center">
<div class="bg-green-500 rounded-full w-10 h-10 flex items-center justify-center mr-2">
<i class="fas fa-shield-alt text-green-100"></i>
</div>
<div>
<p class="text-sm text-gray-500">Tropas</p>
<p id="troops-amount" class="font-bold text-lg">5</p>
</div>
</div>
<button id="collect-btn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg ml-4">
<i class="fas fa-hand-holding-usd mr-2"></i>Recolectar
</button>
</div>
<!-- Controles -->
<div class="flex justify-between mb-6">
<div class="bg-white rounded-lg shadow-md p-4 w-1/3 mr-4">
<h2 class="text-xl font-semibold mb-4 text-center">Construir</h2>
<div class="grid grid-cols-2 gap-3">
<button class="build-btn bg-yellow-100 hover:bg-yellow-200 p-3 rounded-lg" data-type="townhall" data-cost="500">
<i class="fas fa-chess-king text-yellow-600 text-2xl mb-1"></i>
<p class="text-sm">Ayuntamiento (500)</p>
</button>
<button class="build-btn bg-blue-100 hover:bg-blue-200 p-3 rounded-lg" data-type="goldmine" data-cost="200">
<i class="fas fa-coins text-yellow-600 text-2xl mb-1"></i>
<p class="text-sm">Mina de oro (200)</p>
</button>
<button class="build-btn bg-purple-100 hover:bg-purple-200 p-3 rounded-lg" data-type="elixircollector" data-cost="200">
<i class="fas fa-flask text-purple-600 text-2xl mb-1"></i>
<p class="text-sm">Recolector (200)</p>
</button>
<button class="build-btn bg-red-100 hover:bg-red-200 p-3 rounded-lg" data-type="cannon" data-cost="300">
<i class="fas fa-crosshairs text-red-600 text-2xl mb-1"></i>
<p class="text-sm">Cañón (300)</p>
</button>
<button class="build-btn bg-green-100 hover:bg-green-200 p-3 rounded-lg" data-type="barracks" data-cost="400">
<i class="fas fa-chess-knight text-green-600 text-2xl mb-1"></i>
<p class="text-sm">Cuartel (400)</p>
</button>
<button class="build-btn bg-gray-100 hover:bg-gray-200 p-3 rounded-lg" data-type="wall" data-cost="100">
<i class="fas fa-border-style text-gray-600 text-2xl mb-1"></i>
<p class="text-sm">Muro (100)</p>
</button>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-4 w-1/3 mr-4">
<h2 class="text-xl font-semibold mb-4 text-center">Entrenar Tropas</h2>
<div class="grid grid-cols-2 gap-3">
<button class="train-btn bg-red-100 hover:bg-red-200 p-3 rounded-lg" data-type="barbarian" data-cost="50">
<i class="fas fa-user-shield text-red-600 text-2xl mb-1"></i>
<p class="text-sm">Bárbaro (50)</p>
</button>
<button class="train-btn bg-blue-100 hover:bg-blue-200 p-3 rounded-lg" data-type="archer" data-cost="80">
<i class="fas fa-bow-arrow text-blue-600 text-2xl mb-1"></i>
<p class="text-sm">Arquera (80)</p>
</button>
<button class="train-btn bg-green-100 hover:bg-green-200 p-3 rounded-lg" data-type="giant" data-cost="150">
<i class="fas fa-people-arrows text-green-600 text-2xl mb-1"></i>
<p class="text-sm">Gigante (150)</p>
</button>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-4 w-1/3">
<h2 class="text-xl font-semibold mb-4 text-center">Atacar</h2>
<div class="flex flex-col items-center">
<div class="mb-4">
<p class="text-sm text-gray-600 mb-2">Selecciona tropas para atacar:</p>
<div id="attack-troops" class="flex flex-wrap gap-2 mb-4"></div>
</div>
<button id="attack-btn" class="bg-red-600 hover:bg-red-700 text-white px-6 py-3 rounded-lg w-full">
<i class="fas fa-bolt mr-2"></i>Explorar y Atacar
</button>
<div id="battle-log" class="mt-4 p-2 bg-gray-100 rounded w-full h-24 overflow-y-auto text-sm"></div>
</div>
</div>
</div>
<!-- Aldea -->
<div class="flex justify-center">
<div class="village-grid" id="village-grid">
<!-- Las celdas se generarán con JavaScript -->
</div>
</div>
</div>
<!-- Modal de Vista Previa del Enemigo -->
<div id="enemy-preview-modal" class="modal">
<div class="modal-content">
<h2 class="text-2xl font-bold text-center mb-4">Aldea Enemiga</h2>
<p class="text-center text-gray-600 mb-6">Examina las defensas enemigas y prepara tu ataque</p>
<div class="enemy-preview">
<div id="enemy-grid-container" class="flex justify-center mb-4">
<!-- La cuadrícula enemiga se generará aquí -->
</div>
<div class="enemy-stats">
<div class="stat-item">
<div class="stat-value" id="enemy-buildings-count">0</div>
<div class="stat-label">Edificios</div>
</div>
<div class="stat-item">
<div class="stat-value" id="enemy-defenses-count">0</div>
<div class="stat-label">Defensas</div>
</div>
<div class="stat-item">
<div class="stat-value" id="enemy-townhall-level">1</div>
<div class="stat-label">Nivel Ayuntamiento</div>
</div>
</div>
</div>
<div class="attack-options">
<button id="cancel-attack-btn" class="cancel-attack">
<i class="fas fa-times mr-2"></i>Cancelar
</button>
<button id="confirm-attack-btn" class="attack-now">
<i class="fas fa-bolt mr-2"></i>Atacar Ahora
</button>
</div>
</div>
</div>
<!-- Modal de Victoria/Derrota -->
<div id="result-modal" class="modal">
<div class="modal-content text-center p-8">
<h2 id="result-title" class="text-3xl font-bold mb-4"></h2>
<p id="result-message" class="text-xl mb-6"></p>
<button id="restart-btn" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded-lg">
<i class="fas fa-redo mr-2"></i>Jugar de nuevo
</button>
</div>
</div>
<!-- Chatbot de estrategias -->
<div id="chatbot-container" class="chatbot-container chatbot-closed">
<div class="chatbot-header" id="chatbot-toggle">
<div class="flex items-center">
<div class="bg-white rounded-full w-8 h-8 flex items-center justify-center mr-2">
<i class="fas fa-robot text-blue-600"></i>
</div>
<span>Asistente de Estrategia</span>
</div>
<i class="fas fa-chevron-down" id="chatbot-arrow"></i>
</div>
<div class="chatbot-body" id="chatbot-body">
<div class="chatbot-messages" id="chatbot-messages">
<div class="message bot-message">
¡Hola, jefe! Soy tu asistente de estrategia. ¿Necesitas consejos para mejorar tu aldea o planificar ataques?
</div>
<button class="suggest-btn" id="suggest-buildings">
<i class="fas fa-building mr-2"></i>Sugerir construcciones
</button>
<button class="suggest-btn" id="suggest-troops">
<i class="fas fa-shield-alt mr-2"></i>Sugerir composición de tropas
</button>
<button class="suggest-btn" id="suggest-attack">
<i class="fas fa-bolt mr-2"></i>Sugerir estrategia de ataque
</button>
</div>
<div class="chatbot-input">
<input type="text" id="chatbot-input" placeholder="Escribe tu pregunta...">
<button id="chatbot-send"><i class="fas fa-paper-plane"></i></button>
</div>
</div>
</div>
<script>
// Variables del juego
let resources = {
gold: 1000,
elixir: 500,
troops: 5
};
let buildings = [];
let selectedBuildingType = null;
let selectedBuildingCost = 0;
let troops = [];
let selectedTroops = [];
let isAttacking = false;
let attackInterval;
let enemyBuildings = [];
// Inicializar el juego
document.addEventListener('DOMContentLoaded', function() {
// Mostrar splash screen al inicio
document.getElementById('splash-screen').style.display = 'flex';
// Event listener para el botón de comenzar juego
document.getElementById('start-game-btn').addEventListener('click', function() {
// Ocultar splash screen
document.getElementById('splash-screen').style.display = 'none';
// Mostrar juego
document.getElementById('game-container').classList.remove('hidden');
// Inicializar el juego
initializeGame();
});
// Inicializar chatbot
initializeChatbot();
});
function initializeGame() {
// Crear la cuadrícula de la aldea
const villageGrid = document.getElementById('village-grid');
for (let i = 0; i < 64; i++) {
const cell = document.createElement('div');
cell.className = 'grid-cell';
cell.dataset.index = i;
cell.addEventListener('click', handleCellClick);
villageGrid.appendChild(cell);
}
// Construir ayuntamiento inicial
buildInitialTownHall();
// Generar aldea enemiga
generateEnemyVillage();
// Event listeners para botones de construcción
const buildButtons = document.querySelectorAll('.build-btn');
buildButtons.forEach(button => {
button.addEventListener('click', function() {
selectedBuildingType = this.dataset.type;
selectedBuildingCost = parseInt(this.dataset.cost);
// Resaltar botón seleccionado
buildButtons.forEach(btn => btn.classList.remove('ring-2', 'ring-blue-500'));
this.classList.add('ring-2', 'ring-blue-500');
});
});
// Event listeners para botones de entrenamiento
const trainButtons = document.querySelectorAll('.train-btn');
trainButtons.forEach(button => {
button.addEventListener('click', function() {
const troopType = this.dataset.type;
const troopCost = parseInt(this.dataset.cost);
if (resources.elixir >= troopCost) {
resources.elixir -= troopCost;
troops.push({ type: troopType, level: 1 });
updateResources();
// Mostrar notificación
showNotification(`¡Has entrenado un ${getTroopName(troopType)}!`, 'success');
} else {
showNotification('No tienes suficiente elixir', 'error');
}
});
});
// Event listener para botón de recolectar
document.getElementById('collect-btn').addEventListener('click', collectResources);
// Event listener para botón de ataque
document.getElementById('attack-btn').addEventListener('click', showEnemyPreview);
// Event listeners para botones del modal de vista previa
document.getElementById('cancel-attack-btn').addEventListener('click', function() {
document.getElementById('enemy-preview-modal').style.display = 'none';
});
document.getElementById('confirm-attack-btn').addEventListener('click', function() {
document.getElementById('enemy-preview-modal').style.display = 'none';
startAttack();
});
// Event listener para botón de reinicio
document.getElementById('restart-btn').addEventListener('click', restartGame);
// Actualizar la UI inicial
updateResources();
updateTroopsUI();
// Generar recursos cada 10 segundos
setInterval(generateResources, 10000);
}
function initializeChatbot() {
const chatbotToggle = document.getElementById('chatbot-toggle');
const chatbotBody = document.getElementById('chatbot-body');
const chatbotArrow = document.getElementById('chatbot-arrow');
const chatbotContainer = document.getElementById('chatbot-container');
let isChatbotOpen = false;
// Alternar visibilidad del chatbot
chatbotToggle.addEventListener('click', function() {
isChatbotOpen = !isChatbotOpen;
if (isChatbotOpen) {
chatbotBody.style.display = 'block';
chatbotContainer.classList.remove('chatbot-closed');
chatbotArrow.classList.remove('fa-chevron-down');
chatbotArrow.classList.add('fa-chevron-up');
} else {
chatbotBody.style.display = 'none';
chatbotContainer.classList.add('chatbot-closed');
chatbotArrow.classList.remove('fa-chevron-up');
chatbotArrow.classList.add('fa-chevron-down');
}
});
// Botón de enviar mensaje
document.getElementById('chatbot-send').addEventListener('click', sendChatbotMessage);
// Enter para enviar mensaje
document.getElementById('chatbot-input').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
sendChatbotMessage();
}
});
// Botones de sugerencias
document.getElementById('suggest-buildings').addEventListener('click', function() {
suggestBuildings();
});
document.getElementById('suggest-troops').addEventListener('click', function() {
suggestTroops();
});
document.getElementById('suggest-attack').addEventListener('click', function() {
suggestAttackStrategy();
});
}
function sendChatbotMessage() {
const input = document.getElementById('chatbot-input');
const message = input.value.trim();
if (message) {
// Mostrar mensaje del usuario
addUserMessage(message);
input.value = '';
// Mostrar que el bot está escribiendo
showTypingIndicator();
// Simular tiempo de respuesta
setTimeout(() => {
removeTypingIndicator();
respondToMessage(message);
}, 1000 + Math.random() * 2000);
}
}
function addUserMessage(message) {
const messagesContainer = document.getElementById('chatbot-messages');
const messageElement = document.createElement('div');
messageElement.className = 'message user-message';
messageElement.textContent = message;
messagesContainer.appendChild(messageElement);
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}
function addBotMessage(message) {
const messagesContainer = document.getElementById('chatbot-messages');
const messageElement = document.createElement('div');
messageElement.className = 'message bot-message';
messageElement.innerHTML = message;
messagesContainer.appendChild(messageElement);
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}
function showTypingIndicator() {
const messagesContainer = document.getElementById('chatbot-messages');
const typingElement = document.createElement('div');
typingElement.className = 'typing-indicator';
typingElement.id = 'typing-indicator';
typingElement.innerHTML = `
<div class="typing-dot"></div>
<div class="typing-dot"></div>
<div class="typing-dot"></div>
`;
messagesContainer.appendChild(typingElement);
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}
function removeTypingIndicator() {
const typingElement = document.getElementById('typing-indicator');
if (typingElement) {
typingElement.remove();
}
}
function respondToMessage(message) {
const lowerMessage = message.toLowerCase();
if (lowerMessage.includes('hola') || lowerMessage.includes('buenos') || lowerMessage.includes('buenas')) {
addBotMessage('¡Hola, jefe! ¿En qué puedo ayudarte hoy?');
}
else if (lowerMessage.includes('constru') || lowerMessage.includes('edificio') || lowerMessage.includes('mina') || lowerMessage.includes('recolector')) {
suggestBuildings();
}
else if (lowerMessage.includes('tropa') || lowerMessage.includes('ejército') || lowerMessage.includes('atacar') || lowerMessage.includes('ataque')) {
suggestTroops();
}
else if (lowerMessage.includes('estrategia') || lowerMessage.includes('defensa') || lowerMessage.includes('proteger')) {
suggestAttackStrategy();
}
else if (lowerMessage.includes('recurso') || lowerMessage.includes('oro') || lowerMessage.includes('elixir')) {
addBotMessage('Para obtener más recursos:<br>' +
'1. Construye más minas de oro y recolectores de elixir<br>' +
'2. Mejora tus edificios de recursos para aumentar su producción<br>' +
'3. Ataca aldeas enemigas para obtener botines<br>' +
'4. Usa el botón "Recolectar" para obtener recursos acumulados');
}
else {
const randomResponses = [
"No estoy seguro de entender. ¿Quieres que te sugiera construcciones, tropas o estrategias de ataque?",
"Puedo ayudarte con sugerencias para construir, entrenar tropas o planificar ataques. ¿Qué te interesa saber?",
"Como asistente de estrategia, puedo darte consejos para mejorar tu aldea. ¿Qué te interesa saber?"
];
addBotMessage(randomResponses[Math.floor(Math.random() * randomResponses.length)]);
}
}
function suggestBuildings() {
// Analizar el estado actual del juego
const goldMines = buildings.filter(b => b.type === 'goldmine').length;
const elixirCollectors = buildings.filter(b => b.type === 'elixircollector').length;
const barracks = buildings.filter(b => b.type === 'barracks').length;
const cannons = buildings.filter(b => b.type === 'cannon').length;
const walls = buildings.filter(b => b.type === 'wall').length;
let suggestion = "Basado en tu aldea actual, te recomendaría:<br><br>";
// Priorizar según recursos disponibles
if (resources.gold > 500) {
if (goldMines < 2) {
suggestion += "- <strong>Construye otra mina de oro</strong> para aumentar tu producción de oro<br>";
}
if (elixirCollectors < 2) {
suggestion += "- <strong>Construye otro recolector de elixir</strong> para aumentar tu producción de elixir<br>";
}
if (barracks < 1) {
suggestion += "- <strong>Construye un cuartel</strong> para poder entrenar más tropas<br>";
}
if (cannons < 2) {
suggestion += "- <strong>Construye más cañones</strong> para mejorar tus defensas<br>";
}
if (walls < 4) {
suggestion += "- <strong>Construye algunos muros</strong> para proteger tus edificios importantes<br>";
}
if (suggestion === "Basado en tu aldea actual, te recomendaría:<br><br>") {
suggestion += "- <strong>Mejora tus edificios existentes</strong> para aumentar su producción y defensas";
}
} else {
suggestion += "- <strong>Enfócate en recolectar más oro</strong> antes de construir nuevos edificios<br>";
suggestion += "- Considera atacar aldeas enemigas para obtener más recursos";
}
addBotMessage(suggestion);
}
function suggestTroops() {
// Analizar las tropas actuales
const barbarians = troops.filter(t => t.type === 'barbarian').length;
const archers = troops.filter(t => t.type === 'archer').length;
const giants = troops.filter(t => t.type === 'giant').length;
let suggestion = "Para un ejército equilibrado, te recomendaría:<br><br>";
if (troops.length < resources.troops) {
// Sugerir composición basada en tropas disponibles
const remainingSpace = resources.troops - troops.length;
if (remainingSpace >= 3) {
suggestion += "- <strong>Entrena 2 bárbaros y 1 arquera</strong> para un ataque básico<br>";
suggestion += "- O <strong>1 gigante, 1 bárbaro y 1 arquera</strong> para más poder de ataque<br>";
} else if (remainingSpace >= 2) {
suggestion += "- <strong>Entrena 1 bárbaro y 1 arquera</strong> para cubrir diferentes roles<br>";
} else {
suggestion += "- <strong>Entrena 1 arquera</strong> para ataque a distancia";
}
suggestion += "<br>Estrategias avanzadas:<br>";
suggestion += "- <strong>Bárbaros</strong>: Bueno para daño rápido a edificios cercanos<br>";
suggestion += "- <strong>Arqueras</strong>: Excelente para atacar desde lejos y evitar defensas<br>";
suggestion += "- <strong>Gigantes</strong>: Perfectos para absorber daño y atacar defensas";
} else {
suggestion += "Ya tienes el máximo de tropas. Considera:<br>";
suggestion += "- <strong>Atacar ahora</strong> con tu ejército actual<br>";
suggestion += "- <strong>Construir más cuarteles</strong> para aumentar tu capacidad de tropas";
}
addBotMessage(suggestion);
}
function suggestAttackStrategy() {
// Analizar las tropas disponibles
const barbarians = troops.filter(t => t.type === 'barbarian').length;
const archers = troops.filter(t => t.type === 'archer').length;
const giants = troops.filter(t => t.type === 'giant').length;
let suggestion = "Estrategias de ataque basadas en tus tropas:<br><br>";
if (giants >= 2) {
suggestion += "- <strong>Estrategia de tanques</strong>: Usa gigantes para absorber daño mientras tus otras tropas destruyen edificios<br>";
suggestion += "1. Libera los gigantes primero para que atraigan las defensas<br>";
suggestion += "2. Espera unos segundos y luego envía bárbaros/arqueras<br>";
suggestion += "3. Enfócate en destruir los cañones enemigos primero";
}
else if (archers >= 3) {
suggestion += "- <strong>Estrategia de ataque a distancia</strong>: Usa arqueras para atacar desde lejos<br>";
suggestion += "1. Libera todas las arqueras en un borde del mapa<br>";
suggestion += "2. Avanzarán destruyendo edificios sin exponerse mucho<br>";
suggestion += "3. Usa bárbaros para protegerlas si hay defensas cercanas";
}
else if (barbarians >= 4) {
suggestion += "- <strong>Ataque rápido</strong>: Usa bárbaros para daño rápido<br>";
suggestion += "1. Libera los bárbaros en grupos de 2-3 cerca de edificios<br>";
suggestion += "2. Enfócate en edificios de recursos primero (minas, recolectores)<br>";
suggestion += "3. Evita los cañones hasta que tengas suficientes tropas";
}
else {
suggestion += "- <strong>Ataque básico</strong>: Con pocas tropas, enfócate en objetivos específicos<br>";
suggestion += "1. Identifica el edificio más débil (muros o recolectores)<br>";
suggestion += "2. Libera todas tus tropas cerca de ese edificio<br>";
suggestion += "3. Intenta obtener al menos el 50% de destrucción para algunas recompensas";
}
suggestion += "<br><strong>Objetivo principal</strong>: Siempre intenta destruir el ayuntamiento enemigo para ganar la batalla";
addBotMessage(suggestion);
}
function buildInitialTownHall() {
// Construir ayuntamiento en el centro
const centerIndex = 27;
const cell = document.querySelector(`.grid-cell[data-index="${centerIndex}"]`);
const building = {
type: 'townhall',
level: 1,
health: 100,
maxHealth: 100,
position: centerIndex,
lastCollected: Date.now()
};
buildings.push(building);
renderBuilding(building);
}
function generateEnemyVillage() {
// Limpiar edificios enemigos
enemyBuildings = [];
// Generar edificios enemigos aleatorios
const buildingTypes = ['townhall', 'goldmine', 'elixircollector', 'cannon', 'barracks', 'wall'];
const positions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, 23, 24, 31, 32, 39, 40, 47, 48, 55, 56, 57, 58, 59, 60, 61, 62, 63];
// Ayuntamiento enemigo
enemyBuildings.push({
type: 'townhall',
level: 1 + Math.floor(Math.random() * 3), // Nivel 1-3
health: 150,
maxHealth: 150,
position: 0
});
// Otros edificios enemigos
const numBuildings = 5 + Math.floor(Math.random() * 4); // 5-8 edificios
for (let i = 0; i < numBuildings; i++) {
const randomType = buildingTypes[Math.floor(Math.random() * buildingTypes.length)];
const randomPos = positions[Math.floor(Math.random() * positions.length)];
// Verificar que la posición no esté ocupada
if (!enemyBuildings.some(b => b.position === randomPos)) {
enemyBuildings.push({
type: randomType,
level: 1 + Math.floor(Math.random() * 2), // Nivel 1-2
health: randomType === 'wall' ? 50 : 100,
maxHealth: randomType === 'wall' ? 50 : 100,
position: randomPos
});
}
}
}
function showEnemyPreview() {
if (isAttacking) return;
if (selectedTroops.length === 0) {
showNotification('Selecciona al menos una tropa para atacar', 'error');
return;
}
// Crear la cuadrícula enemiga
const enemyGridContainer = document.getElementById('enemy-grid-container');
enemyGridContainer.innerHTML = '';
const enemyGrid = document.createElement('div');
enemyGrid.className = 'enemy-grid';
for (let i = 0; i < 64; i++) {
const cell = document.createElement('div');
cell.className = 'enemy-cell';
enemyGrid.appendChild(cell);
}
// Renderizar edificios enemigos
enemyBuildings.forEach(building => {
const cell = enemyGrid.children[building.position];
const buildingElement = document.createElement('div');
buildingElement.className = 'enemy-building';
// Estilo según el tipo de edificio
switch(building.type) {
case 'townhall':
buildingElement.innerHTML = '<i class="fas fa-chess-king text-yellow-600 text-xl"></i>';
break;
case 'goldmine':
buildingElement.innerHTML = '<i class="fas fa-coins text-yellow-500 text-xl"></i>';
break;
case 'elixircollector':
buildingElement.innerHTML = '<i class="fas fa-flask text-purple-500 text-xl"></i>';
break;
case 'cannon':
buildingElement.innerHTML = '<i class="fas fa-crosshairs text-red-500 text-xl"></i>';
break;
case 'barracks':
buildingElement.innerHTML = '<i class="fas fa-chess-knight text-green-500 text-xl"></i>';
break;
case 'wall':
buildingElement.innerHTML = '<i class="fas fa-border-style text-gray-500 text-xl"></i>';
break;
}
// Barra de salud
const healthBar = document.createElement('div');
healthBar.className = 'progress-bar';
const healthFill = document.createElement('div');
healthFill.className = 'progress-fill';
healthFill.style.width = `${(building.health / building.maxHealth) * 100}%`;
healthBar.appendChild(healthFill);
buildingElement.appendChild(healthBar);
cell.innerHTML = '';
cell.appendChild(buildingElement);
});
enemyGridContainer.appendChild(enemyGrid);
// Actualizar estadísticas del enemigo
const townhall = enemyBuildings.find(b => b.type === 'townhall');
const defenses = enemyBuildings.filter(b => b.type === 'cannon' || b.type === 'wall').length;
document.getElementById('enemy-buildings-count').textContent = enemyBuildings.length;
document.getElementById('enemy-defenses-count').textContent = defenses;
document.getElementById('enemy-townhall-level').textContent = townhall ? townhall.level : '1';
// Mostrar el modal
document.getElementById('enemy-preview-modal').style.display = 'flex';
}
function handleCellClick(e) {
const cellIndex = parseInt(e.target.dataset.index);
// Verificar si ya hay un edificio en esta celda
const existingBuilding = buildings.find(b => b.position === cellIndex);
if (existingBuilding) {
// Mostrar información del edificio
showBuildingInfo(existingBuilding);
return;
}
// Si estamos en modo de construcción
if (selectedBuildingType) {
// Verificar si tenemos suficientes recursos
if (resources.gold >= selectedBuildingCost) {
// Construir el edificio
const building = {
type: selectedBuildingType,
level: 1,
health: selectedBuildingType === 'wall' ? 50 : 100,
maxHealth: selectedBuildingType === 'wall' ? 50 : 100,
position: cellIndex,
lastCollected: Date.now()
};
buildings.push(building);
resources.gold -= selectedBuildingCost;
updateResources();
renderBuilding(building);
showNotification(`¡Has construido un ${getBuildingName(selectedBuildingType)}!`, 'success');
} else {
showNotification('No tienes suficiente oro', 'error');
}
}
}
function renderBuilding(building) {
const cell = document.querySelector(`.grid-cell[data-index="${building.position}"]`);
cell.innerHTML = '';
const buildingElement = document.createElement('div');
buildingElement.className = 'building';
// Estilo según el tipo de edificio
switch(building.type) {
case 'townhall':
buildingElement.innerHTML = '<i class="fas fa-chess-king text-yellow-600 text-2xl"></i>';
break;
case 'goldmine':
buildingElement.innerHTML = '<i class="fas fa-coins text-yellow-500 text-2xl"></i>';
break;
case 'elixircollector':
buildingElement.innerHTML = '<i class="fas fa-flask text-purple-500 text-2xl"></i>';
break;
case 'cannon':
buildingElement.innerHTML = '<i class="fas fa-crosshairs text-red-500 text-2xl"></i>';
break;
case 'barracks':
buildingElement.innerHTML = '<i class="fas fa-chess-knight text-green-500 text-2xl"></i>';
break;
case 'wall':
buildingElement.innerHTML = '<i class="fas fa-border-style text-gray-500 text-2xl"></i>';
break;
}
// Barra de salud
const healthBar = document.createElement('div');
healthBar.className = 'progress-bar';
const healthFill = document.createElement('div');
healthFill.className = 'progress-fill';
healthFill.style.width = `${(building.health / building.maxHealth) * 100}%`;
healthBar.appendChild(healthFill);
buildingElement.appendChild(healthBar);
cell.appendChild(buildingElement);
}
function showBuildingInfo(building) {
const buildingName = getBuildingName(building.type);
const info = `
<div class="bg-white p-4 rounded-lg shadow-lg">
<h3 class="text-xl font-bold mb-2">${buildingName} (Nivel ${building.level})</h3>
<p class="text-gray-700 mb-2">Salud: ${building.health}/${building.maxHealth}</p>
${building.type === 'townhall' ? '<p class="text-gray-700">Corazón de tu aldea</p>' : ''}
${building.type === 'goldmine' ? '<p class="text-gray-700">Genera oro cada 10 segundos</p>' : ''}
${building.type === 'elixircollector' ? '<p class="text-gray-700">Genera elixir cada 10 segundos</p>' : ''}
${building.type === 'cannon' ? '<p class="text-gray-700">Defiende tu aldea de ataques</p>' : ''}
${building.type === 'barracks' ? '<p class="text-gray-700">Permite entrenar más tropas</p>' : ''}
${building.type === 'wall' ? '<p class="text-gray-700">Protege otros edificios</p>' : ''}
<button class="upgrade-btn mt-3 bg-blue-500 hover:bg-blue-600 text-white px-3 py-1 rounded" data-position="${building.position}">
<i class="fas fa-arrow-up mr-1"></i>Mejorar (${getUpgradeCost(building.type, building.level)})
</button>
</div>
`;
// Mostrar tooltip o modal con la información
showNotification(info, 'info', 5000);
// Agregar event listener al botón de mejora
setTimeout(() => {
const upgradeBtn = document.querySelector('.upgrade-btn');
if (upgradeBtn) {
upgradeBtn.addEventListener('click', function() {
const position = parseInt(this.dataset.position);
upgradeBuilding(position);
});
}
}, 100);
}
function getUpgradeCost(type, level) {
const baseCosts = {
townhall: 1000,
goldmine: 300,
elixircollector: 300,
cannon: 400,
barracks: 500,
wall: 150
};
return baseCosts[type] * level;
}
function upgradeBuilding(position) {
const building = buildings.find(b => b.position === position);
if (!building) return;
const upgradeCost = getUpgradeCost(building.type, building.level);
if (resources.gold >= upgradeCost) {
resources.gold -= upgradeCost;
building.level += 1;
building.maxHealth += 50;
building.health = building.maxHealth;
updateResources();
renderBuilding(building);
showNotification(`¡Has mejorado tu ${getBuildingName(building.type)} al nivel ${building.level}!`, 'success');
} else {
showNotification('No tienes suficiente oro para mejorar', 'error');
}
}
function getBuildingName(type) {
const names = {
townhall: 'Ayuntamiento',
goldmine: 'Mina de Oro',
elixircollector: 'Recolector de Elixir',
cannon: 'Cañón',
barracks: 'Cuartel',
wall: 'Muro'
};
return names[type] || type;
}
function getTroopName(type) {
const names = {
barbarian: 'Bárbaro',
archer: 'Arquera',
giant: 'Gigante'
};
return names[type] || type;
}
function generateResources() {
let goldGenerated = 0;
let elixirGenerated = 0;
buildings.forEach(building => {
if (building.type === 'goldmine') {
const amount = 50 * building.level;
goldGenerated += amount;
} else if (building.type === 'elixircollector') {
const amount = 30 * building.level;
elixirGenerated += amount;
}
});
if (goldGenerated > 0 || elixirGenerated > 0) {
resources.gold += goldGenerated;
resources.elixir += elixirGenerated;
updateResources();
let message = '';
if (goldGenerated > 0) message += `+${goldGenerated} Oro `;
if (elixirGenerated > 0) message += `+${elixirGenerated} Elixir`;
showNotification(message, 'success');
}
}
function collectResources() {
let goldCollected = 0;
let elixirCollected = 0;
buildings.forEach(building => {
if (building.type === 'goldmine') {
const amount = 100 * building.level;
goldCollected += amount;
} else if (building.type === 'elixircollector') {
const amount = 60 * building.level;
elixirCollected += amount;
}
});
if (goldCollected > 0 || elixirCollected > 0) {
resources.gold += goldCollected;
resources.elixir += elixirCollected;
updateResources();
let message = '';
if (goldCollected > 0) message += `Recolectaste ${goldCollected} Oro `;
if (elixirCollected > 0) message += `Recolectaste ${elixirCollected} Elixir`;
showNotification(message, 'success');
} else {
showNotification('No hay recursos para recolectar', 'info');
}
}
function updateResources() {
document.getElementById('gold-amount').textContent = resources.gold;
document.getElementById('elixir-amount').textContent = resources.elixir;
// Actualizar tropas basadas en cuarteles
const barracksCount = buildings.filter(b => b.type === 'barracks').length;
resources.troops = 5 + (barracksCount * 3);
document.getElementById('troops-amount').textContent = resources.troops;
// Actualizar UI de tropas
updateTroopsUI();
}
function updateTroopsUI() {
const troopsContainer = document.getElementById('attack-troops');
troopsContainer.innerHTML = '';
troops.forEach((troop, index) => {
const troopElement = document.createElement('div');
troopElement.className = 'flex flex-col items-center cursor-pointer';
troopElement.dataset.index = index;
let iconClass = '';
let bgColor = '';
switch(troop.type) {
case 'barbarian':
iconClass = 'fas fa-user-shield text-red-600';
bgColor = 'bg-red-100';
break;
case 'archer':
iconClass = 'fas fa-bow-arrow text-blue-600';
bgColor = 'bg-blue-100';
break;
case 'giant':
iconClass = 'fas fa-people-arrows text-green-600';
bgColor = 'bg-green-100';
break;
}
troopElement.innerHTML = `
<div class="w-12 h-12 rounded-full ${bgColor} flex items-center justify-center mb-1 ${selectedTroops.includes(index) ? 'ring-2 ring-yellow-500' : ''}">
<i class="${iconClass} text-xl"></i>
</div>
<span class="text-xs">Nvl ${troop.level}</span>
`;
troopElement.addEventListener('click', function() {
toggleTroopSelection(index);
});
troopsContainer.appendChild(troopElement);
});
}
function toggleTroopSelection(index) {
const troopIndex = selectedTroops.indexOf(index);
if (troopIndex === -1) {
// Verificar si ya hemos alcanzado el límite de tropas seleccionadas
if (selectedTroops.length < resources.troops) {
selectedTroops.push(index);
} else {
showNotification(`Solo puedes seleccionar ${resources.troops} tropas`, 'error');
}
} else {
selectedTroops.splice(troopIndex, 1);
}
updateTroopsUI();
}
function startAttack() {
if (isAttacking) return;
isAttacking = true;
document.getElementById('attack-btn').disabled = true;
document.getElementById('attack-btn').classList.add('opacity-50');
// Mostrar modal con la aldea enemiga
const modal = document.getElementById('result-modal');
const resultTitle = document.getElementById('result-title');
const resultMessage = document.getElementById('result-message');
resultTitle.textContent = '¡Ataque en progreso!';
resultMessage.innerHTML = '<div class="flex justify-center mb-4"><div class="animate-spin rounded-full h-10 w-10 border-b-2 border-blue-600"></div></div><p>Preparando el ataque...</p>';
modal.style.display = 'flex';
// Iniciar el ataque después de un breve retraso
setTimeout(() => {
performAttack();
}, 1500);
}
function performAttack() {
const battleLog = document.getElementById('battle-log');
battleLog.innerHTML = '';
// Clonar edificios enemigos para no modificar los originales
const enemyBuildingsCopy = JSON.parse(JSON.stringify(enemyBuildings));
// Clonar tropas seleccionadas
const attackingTroops = selectedTroops.map(index => {
return {...troops[index]};
});
// Función para registrar un evento en el log de batalla
function logEvent(message) {
const logEntry = document.createElement('div');
logEntry.className = 'mb-1';
logEntry.innerHTML = `<span class="text-gray-500">[${new Date().toLocaleTimeString()}]</span> ${message}`;
battleLog.appendChild(logEntry);
battleLog.scrollTop = battleLog.scrollHeight;
}
// Mostrar resumen inicial
logEvent(`Iniciaste un ataque con ${attackingTroops.length} tropas contra ${enemyBuildingsCopy.length} edificios enemigos.`);
// Simular batalla por turnos
let turn = 1;
const maxTurns = 10;
attackInterval = setInterval(() => {
if (turn > maxTurns || attackingTroops.length === 0 || enemyBuildingsCopy.length === 0) {
clearInterval(attackInterval);
endAttack(attackingTroops, enemyBuildingsCopy);
return;
}
logEvent(`<strong>Turno ${turn}</strong>`);
// Tropas atacan edificios
attackingTroops.forEach((troop, index) => {
if (enemyBuildingsCopy.length === 0) return;
const targetIndex = Math.floor(Math.random() * enemyBuildingsCopy.length);
const target = enemyBuildingsCopy[targetIndex];
let damage = 0;
switch(troop.type) {
case 'barbarian':
damage = 20 * troop.level;
break;
case 'archer':
damage = 15 * troop.level;
break;
case 'giant':
damage = 30 * troop.level;
break;
}
target.health -= damage;
logEvent(`Tu ${getTroopName(troop.type)} inflige ${damage} de daño al ${getBuildingName(target.type)} enemigo.`);
// Verificar si el edificio fue destruido
if (target.health <= 0) {
logEvent(`¡${getBuildingName(target.type)} enemigo destruido!`);
enemyBuildingsCopy.splice(targetIndex, 1);
// Recompensa por destruir edificios
if (target.type === 'goldmine') {
resources.gold += 200;
} else if (target.type === 'elixircollector') {
resources.elixir += 100;
} else if (target.type === 'townhall') {
resources.gold += 1000;
resources.elixir += 500;
}
}
});
// Edificios defienden (solo cañones)
enemyBuildingsCopy.forEach(building => {
if (building.type === 'cannon' && attackingTroops.length > 0) {
const targetIndex = Math.floor(Math.random() * attackingTroops.length);
const target = attackingTroops[targetIndex];
const damage = 25 * building.level;
target.health -= damage;
logEvent(`Cañón enemigo inflige ${damage} de daño a tu ${getTroopName(target.type)}.`);
// Verificar si la tropa fue eliminada
if (target.health <= 0) {
logEvent(`¡Tu ${getTroopName(target.type)} ha sido eliminado!`);
attackingTroops.splice(targetIndex, 1);
}
}
});
turn++;
updateResources();
}, 1500);
}
function endAttack(remainingTroops, remainingBuildings) {
isAttacking = false;
document.getElementById('attack-btn').disabled = false;
document.getElementById('attack-btn').classList.remove('opacity-50');
const battleLog = document.getElementById('battle-log');
const modal = document.getElementById('result-modal');
const resultTitle = document.getElementById('result-title');
const resultMessage = document.getElementById('result-message');
// Determinar resultado
const townhallDestroyed = !remainingBuildings.some(b => b.type === 'townhall');
const allTroopsDead = remainingTroops.length === 0;
if (townhallDestroyed) {
resultTitle.textContent = '¡Victoria!';
resultMessage.innerHTML = `
<p class="text-green-600 text-xl mb-4">¡Has destruido el ayuntamiento enemigo!</p>
<p class="mb-2">Recompensas:</p>
<ul class="list-disc pl-5 mb-4">
<li>+1000 Oro</li>
<li>+500 Elixir</li>
</ul>
<p>${remainingTroops.length} tropas sobrevivieron.</p>
`;
// Eliminar tropas usadas en el ataque
selectedTroops.sort((a, b) => b - a).forEach(index => {
troops.splice(index, 1);
});
// Agregar tropas sobrevivientes
remainingTroops.forEach(troop => {
troops.push(troop);
});
selectedTroops = [];
updateTroopsUI();
// Generar nueva aldea enemiga
setTimeout(generateEnemyVillage, 3000);
} else if (allTroopsDead) {
resultTitle.textContent = 'Derrota';
resultMessage.innerHTML = `
<p class="text-red-600 text-xl mb-4">Todas tus tropas han sido eliminadas.</p>
<p>Inténtalo de nuevo con un ejército más fuerte.</p>
`;
// Eliminar tropas usadas en el ataque
selectedTroops.sort((a, b) => b - a).forEach(index => {
troops.splice(index, 1);
});
selectedTroops = [];
updateTroopsUI();
} else {
resultTitle.textContent = 'Retirada';
resultMessage.innerHTML = `
<p class="text-yellow-600 text-xl mb-4">Te has retirado del combate.</p>
<p>${remainingTroops.length} tropas sobrevivieron.</p>
<p class="mt-2">Destruiste ${enemyBuildings.length - remainingBuildings.length} edificios enemigos.</p>
`;
// Eliminar tropas usadas en el ataque
selectedTroops.sort((a, b) => b - a).forEach(index => {
troops.splice(index, 1);
});
// Agregar tropas sobrevivientes
remainingTroops.forEach(troop => {
troops.push(troop);
});
selectedTroops = [];
updateTroopsUI();
}
modal.style.display = 'flex';
}
function restartGame() {
// Reiniciar variables del juego
resources = {
gold: 1000,
elixir: 500,
troops: 5
};
buildings = [];
troops = [];
selectedTroops = [];
// Limpiar la aldea
document.querySelectorAll('.grid-cell').forEach(cell => {
cell.innerHTML = '';
});
// Construir ayuntamiento inicial
buildInitialTownHall();
// Generar nueva aldea enemiga
generateEnemyVillage();
// Actualizar UI
updateResources();
updateTroopsUI();
// Ocultar modal
document.getElementById('result-modal').style.display = 'none';
}
function showNotification(message, type = 'info', duration = 3000) {
const notification = document.createElement('div');
notification.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg z-50 animate-fade-in`;
// Estilo según el tipo
switch(type) {
case 'success':
notification.className += ' bg-green-100 text-green-800 border-l-4 border-green-500';
break;
case 'error':
notification.className += ' bg-red-100 text-red-800 border-l-4 border-red-500';
break;
case 'info':
notification.className += ' bg-blue-100 text-blue-800 border-l-4 border-blue-500';
break;
default:
notification.className += ' bg-gray-100 text-gray-800 border-l-4 border-gray-500';
}
notification.innerHTML = message;
document.body.appendChild(notification);
// Eliminar después de un tiempo
if (duration > 0) {
setTimeout(() => {
notification.classList.remove('animate-fade-in');
notification.classList.add('animate-fade-out');
setTimeout(() => {
notification.remove();
}, 300);
}, duration);
}
}
</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=Ateneo/clash-ii" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |