Añadidos juegos

This commit is contained in:
2025-08-21 23:42:55 +02:00
parent ec9c7d8d63
commit 90b2643d8d
46 changed files with 3936 additions and 0 deletions

15
3-en-raya/index.html Normal file
View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Tres en Raya</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Tres en Raya (Tic Tac Toe)</h1>
<div id="board"></div>
<div id="status"></div>
<button id="restart-btn">Reiniciar</button>
<script src="script.js"></script>
</body>
</html>

52
3-en-raya/script.js Normal file
View File

@@ -0,0 +1,52 @@
const boardDiv = document.getElementById('board');
const statusDiv = document.getElementById('status');
const restartBtn = document.getElementById('restart-btn');
let board, currentPlayer, gameOver;
function initGame() {
board = Array(9).fill('');
currentPlayer = 'X';
gameOver = false;
statusDiv.textContent = "Turno de " + currentPlayer;
renderBoard();
}
function renderBoard() {
boardDiv.innerHTML = '';
board.forEach((cell, idx) => {
const cellDiv = document.createElement('div');
cellDiv.className = 'cell';
cellDiv.textContent = cell;
cellDiv.onclick = () => handleCellClick(idx);
boardDiv.appendChild(cellDiv);
});
}
function handleCellClick(idx) {
if (gameOver || board[idx] !== '') return;
board[idx] = currentPlayer;
renderBoard();
if (checkWinner(currentPlayer)) {
statusDiv.textContent = `¡${currentPlayer} gana! 🎉`;
gameOver = true;
} else if (board.every(cell => cell !== '')) {
statusDiv.textContent = "¡Empate!";
gameOver = true;
} else {
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
statusDiv.textContent = "Turno de " + currentPlayer;
}
}
function checkWinner(player) {
const winCases = [
[0,1,2],[3,4,5],[6,7,8], // Filas
[0,3,6],[1,4,7],[2,5,8], // Columnas
[0,4,8],[2,4,6] // Diagonales
];
return winCases.some(combo => combo.every(i => board[i] === player));
}
restartBtn.onclick = initGame;
initGame();

121
3-en-raya/styles.css Normal file
View File

@@ -0,0 +1,121 @@
body {
background: #eef2f3;
font-family: Arial, sans-serif;
text-align: center;
color: #222;
margin: 0;
padding: 0;
}
h1 {
margin-top: 2rem;
color: #3498db;
font-size: 2.5rem;
line-height: 1.2;
}
/* Board responsive styles */
#board {
display: grid;
grid-template-columns: repeat(3, minmax(60px, 22vw));
grid-template-rows: repeat(3, minmax(60px, 22vw));
gap: 0.8em;
justify-content: center;
margin: 2rem auto 1.5rem auto;
max-width: 95vw;
}
/* Cell responsive styles */
.cell {
width: 100%;
height: 100%;
background: #fff;
border-radius: 0.5em;
box-shadow: 0 2px 8px #bbb;
font-size: 8em;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.2s;
}
.cell:hover, .cell:focus {
background: #f1fafe;
}
#status {
font-size: 1.15em;
min-height: 2em;
margin-bottom: 1em;
word-break: break-word;
}
#restart-btn {
background: #3498db;
color: #fff;
font-size: 1em;
border: none;
border-radius: 0.7em;
padding: 0.7em 2em;
cursor: pointer;
transition: background 0.2s;
}
#restart-btn:hover,
#restart-btn:focus {
background: #297fb8;
}
/* SMALL DEVICES (phones) */
@media (max-width: 480px) {
h1 {
font-size: 1.5rem;
margin-top: 1rem;
}
#board {
grid-template-columns: repeat(3, minmax(40px, 28vw));
grid-template-rows: repeat(3, minmax(40px, 28vw));
gap: 0.5em;
margin: 1rem auto;
}
.cell {
font-size: 10em;
border-radius: 0.35em;
}
#status {
font-size: 1em;
min-height: 1.2em;
margin-bottom: 0.7em;
}
#restart-btn {
font-size: 0.95em;
padding: 0.6em 1.2em;
}
}
/* TABLETS */
@media (max-width: 768px) {
h1 {
font-size: 2rem;
}
#board {
grid-template-columns: repeat(3, minmax(50px, 22vw));
grid-template-rows: repeat(3, minmax(50px, 22vw));
}
.cell {
font-size: 10em;
}
}
/* BIG SCREENS */
@media (min-width: 1200px) {
#board {
grid-template-columns: repeat(3, 110px);
grid-template-rows: repeat(3, 110px);
gap: 1em;
}
.cell {
font-size: 3em;
}
}