<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Aventura Gráfica: La Mansión del Queso</title>
<style>
body {
background: #222;
color: #eee;
font-family: 'Consolas', 'Courier New', monospace;
margin: 0;
padding: 0;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
}
#game-container {
margin-top: 24px;
background: #333;
border: 3px solid #888;
border-radius: 8px;
width: 600px;
min-height: 500px;
display: flex;
flex-direction: column;
box-shadow: 0 0 16px #000a;
}
#scene {
flex: 1;
padding: 24px 24px 12px 24px;
min-height: 260px;
font-size: 18px;
white-space: pre;
background: #222;
border-bottom: 2px solid #444;
position: relative;
}
.object, .exit, .character {
color: #ff0;
cursor: pointer;
text-decoration: underline;
font-weight: bold;
transition: color 0.1s;
}
.object:hover, .exit:hover, .character:hover {
color: #0ff;
}
#inventory {
background: #222;
border-top: 2px solid #444;
padding: 8px 24px;
min-height: 36px;
display: flex;
align-items: center;
gap: 12px;
font-size: 16px;
}
#inventory-label {
color: #aaa;
margin-right: 8px;
}
.inv-item {
background: #444;
color: #fff;
border: 1px solid #888;
border-radius: 4px;
padding: 2px 8px;
margin-right: 4px;
cursor: pointer;
transition: background 0.1s;
font-size: 15px;
}
.inv-item.selected {
background: #0ff;
color: #222;
border-color: #fff;
font-weight: bold;
}
.inv-item:hover {
background: #ff0;
color: #222;
}
#dialogue {
background: #181818;
border-top: 2px solid #444;
min-height: 48px;
padding: 10px 24px;
font-size: 16px;
color: #fff;
font-style: italic;
min-height: 32px;
transition: background 0.2s;
}
@media (max-width: 650px) {
#game-container {
width: 98vw;
min-width: 0;
}
#scene, #inventory, #dialogue {
padding-left: 8px;
padding-right: 8px;
}
}
</style>
</head>
<body>
<h1 style="margin-top:16px; color:#ff0; text-shadow:1px 1px 2px #000;">La Mansión del Queso</h1>
<div id="game-container">
<div id="scene"></div>
<div id="inventory"><span id="inventory-label">Inventario:</span></div>
<div id="dialogue"></div>
</div>
<script>
// --- DATA STRUCTURES ---
const game = {
currentRoom: 'hall',
inventory: [],
selectedItem: null,
flags: {
doorUnlocked: false,
mouseFed: false,
cheeseTaken: false,
}
};
// --- ROOMS ---
const rooms = {
hall: {
name: "Vestíbulo de la Mansión",
ascii: `
___________________________
| |
| [Puerta Principal] |
| |
| (Alfombra) |
| |
| [Mesa] |
|___________________________|
`,
description: "Estás en el vestíbulo de la misteriosa Mansión del Queso. Hay una <span class='object' data-obj='door'>puerta principal</span> cerrada, una <span class='object' data-obj='mat'>alfombra</span> sospechosa en el suelo y una <span class='object' data-obj='table'>mesa</span> polvorienta en la esquina.",
objects: {
door: {
name: "Puerta Principal",
description: "Una puerta robusta con un gran candado. ¡La salida está tan cerca y tan lejos!",
interact: function() {
if (game.flags.doorUnlocked) {
showDialogue("¡La puerta está abierta! Puedes <span class='exit' data-exit='outside'>salir</span>.");
} else {
showDialogue("La puerta está cerrada con un candado enorme. ¿Tendrás algo para abrirla?");
}
},
use: function(item) {
if (item === 'rusty_key') {
game.flags.doorUnlocked = true;
showDialogue("¡Usas la llave oxidada y el candado se abre con un chirrido! Ahora puedes <span class='exit' data-exit='outside'>salir</span>.");
renderScene();
return true;
} else {
showDialogue("Eso no parece funcionar en la puerta.");
return false;
}
}
},
mat: {
name: "Alfombra",
description: "Una alfombra sospechosamente abultada. ¿Qué esconderá debajo?",
interact: function() {
if (!game.inventory.includes('rusty_key')) {
showDialogue("Levantas la alfombra y encuentras una <span class='object' data-obj='rusty_key'>llave oxidada</span>.");
rooms.hall.objects.rusty_key.visible = true;
renderScene();
} else {
showDialogue("Ya no hay nada bajo la alfombra, salvo pelusas y tus esperanzas.");
}
}
},
table: {
name: "Mesa",
description: "Una mesa polvorienta. Encima hay una nota y un trozo de queso.",
interact: function() {
showDialogue("Sobre la mesa hay una <span class='object' data-obj='note'>nota</span> y un <span class='object' data-obj='cheese'>queso</span>.");
rooms.hall.objects.note.visible = true;
if (!game.flags.cheeseTaken) rooms.hall.objects.cheese.visible = true;
renderScene();
}
},
note: {
name: "Nota",
description: "La nota dice: 'El ratón de la cocina sabe demasiado. ¡Dale de comer y te ayudará!'",
visible: false,
interact: function() {
showDialogue("La nota dice: 'El ratón de la cocina sabe demasiado. ¡Dale de comer y te ayudará!'");
}
},
cheese: {
name: "Queso",
description: "Un trozo de queso amarillo, huele fuerte. ¿Quién lo dejaría aquí?",
visible: false,
interact: function() {
showDialogue("¡Has recogido el queso! Esperemos que no esté muy pasado...");
addToInventory('cheese');
game.flags.cheeseTaken = true;
rooms.hall.objects.cheese.visible = false;
renderScene();
}
},
rusty_key: {
name: "Llave Oxidada",
description: "Una llave vieja y oxidada. ¿Abrirá alguna puerta?",
visible: false,
interact: function() {
showDialogue("¡Has recogido la llave oxidada!");
addToInventory('rusty_key');
rooms.hall.objects.rusty_key.visible = false;
renderScene();
}
}
},
exits: {
kitchen: "A la <span class='exit' data-exit='kitchen'>cocina</span> (a la derecha)",
study: "Al <span class='exit' data-exit='study'>estudio</span> (a la izquierda)"
}
},
kitchen: {
name: "Cocina",
ascii: `
___________________________
| _________ |
| | | |
| | Nevera| |
| |_______| |
| |
| [Ratón] |
|___________________________|
`,
description: "Estás en la cocina. Hay una <span class='object' data-obj='fridge'>nevera</span> y un <span class='character' data-obj='mouse'>ratón</span> hambriento te observa desde la esquina.",
objects: {
fridge: {
name: "Nevera",
description: "Una nevera vieja. ¿Qué habrá dentro?",
interact: function() {
if (!game.inventory.includes('fish')) {
showDialogue("Abres la nevera y encuentras un <span class='object' data-obj='fish'>pescado</span> sospechoso.");
rooms.kitchen.objects.fish.visible = true;
renderScene();
} else {
showDialogue("La nevera está vacía, salvo por un olor a queso... ¿o será a calcetines?");
}
}
},
fish: {
name: "Pescado",
description: "Un pescado que ha visto días mejores. ¿Para qué servirá?",
visible: false,
interact: function() {
showDialogue("¡Has recogido el pescado! Esperemos que nadie lo eche de menos.");
addToInventory('fish');
rooms.kitchen.objects.fish.visible = false;
renderScene();
}
},
mouse: {
name: "Ratón",
description: "Un ratón con cara de pocos amigos. Parece hambriento.",
interact: function() {
if (!game.flags.mouseFed) {
showDialogue("El ratón te mira con ojos suplicantes. ¿Tienes algo para darle?");
} else {
showDialogue("El ratón mastica felizmente y te señala con la patita hacia el <span class='exit' data-exit='secret'>pasadizo secreto</span>.");
}
},
use: function(item) {
if (item === 'cheese') {
game.flags.mouseFed = true;
removeFromInventory('cheese');
showDialogue("Le das el queso al ratón. ¡Te sonríe y te revela un <span class='exit' data-exit='secret'>pasadizo secreto</span> tras la nevera!");
renderScene();
return true;
} else {
showDialogue("El ratón rechaza eso. ¡Solo quiere queso!");
return false;
}
}
}
},
exits: {
hall: "Al <span class='exit' data-exit='hall'>vestíbulo</span>"
}
},
study: {
name: "Estudio",
ascii: `
___________________________
| [Estantería] |
| |
| [Sillón] |
| |
| [Cuadro Extraño] |
|___________________________|
`,
description: "Estás en el estudio. Hay una <span class='object' data-obj='bookshelf'>estantería</span> llena de libros, un <span class='object' data-obj='armchair'>sillón</span> y un <span class='object' data-obj='painting'>cuadro extraño</span> en la pared.",
objects: {
bookshelf: {
name: "Estantería",
description: "Libros polvorientos de títulos como '101 recetas con queso' y 'Cómo domesticar ratones'.",
interact: function() {
showDialogue("Encuentras un libro titulado 'Cómo abrir puertas con llaves oxidadas'. ¡Qué específico!");
}
},
armchair: {
name: "Sillón",
description: "Un sillón cómodo. Al sentarte, sientes algo duro debajo del cojín.",
interact: function() {
if (!game.inventory.includes('coin')) {
showDialogue("¡Encuentras una <span class='object' data-obj='coin'>moneda</span> bajo el cojín!");
rooms.study.objects.coin.visible = true;
renderScene();
} else {
showDialogue("Ya no hay nada bajo el cojín, salvo migas y sueños rotos.");
}
}
},
coin: {
name: "Moneda",
description: "Una moneda antigua. Quizá tenga algún valor... o no.",
visible: false,
interact: function() {
showDialogue("¡Has recogido la moneda! ¿Será de chocolate?");
addToInventory('coin');
rooms.study.objects.coin.visible = false;
renderScene();
}
},
painting: {
name: "Cuadro Extraño",
description: "Un cuadro de un queso gigante. Parece que los ojos te siguen...",
interact: function() {
showDialogue("El cuadro te observa fijamente. Sientes un escalofrío... o quizá solo hambre.");
}
}
},
exits: {
hall: "Al <span class='exit' data-exit='hall'>vestíbulo</span>"
}
},
secret: {
name: "Pasadizo Secreto",
ascii: `
___________________________
| |
| [Puerta de Salida] |
| |
| ¡Felicidades! |
|___________________________|
`,
description: "¡Has encontrado el pasadizo secreto! Al fondo hay una <span class='object' data-obj='final_door'>puerta de salida</span>.",
objects: {
final_door: {
name: "Puerta de Salida",
description: "La puerta final. ¿Estás listo para salir?",
interact: function() {
showDialogue("¡Enhorabuena! Has escapado de la Mansión del Queso. ¿Te atreves a volver a entrar?");
}
}
},
exits: {
kitchen: "A la <span class='exit' data-exit='kitchen'>cocina</span>"
}
},
outside: {
name: "¡Libertad!",
ascii: `
___________________________
| |
| ¡Has escapado! |
| |
| Gracias por jugar. |
|___________________________|
`,
description: "¡Has salido de la mansión! El aire fresco sabe a victoria... y a queso.",
objects: {},
exits: {}
}
};
// --- INVENTORY ITEMS ---
const inventoryItems = {
rusty_key: { name: "Llave Oxidada", description: "Una llave vieja y oxidada." },
cheese: { name: "Queso", description: "Un trozo de queso amarillo y oloroso." },
fish: { name: "Pescado", description: "Un pescado sospechoso." },
coin: { name: "Moneda", description: "Una moneda antigua y reluciente." }
};
// --- RENDERING FUNCTIONS ---
function renderScene() {
const room = rooms[game.currentRoom];
let html = `<div style="font-size:15px; color:#aaa; margin-bottom:8px;">${room.name}</div>`;
html += `<pre style="margin:0 0 8px 0; color:#0f0;">${room.ascii}</pre>`;
html += `<div>${room.description}</div>`;
// List visible objects
let objHtml = '';
for (const [key, obj] of Object.entries(room.objects || {})) {
if (obj.visible === false) continue;
// Already referenced in description? (avoid double listing)
if (!room.description.includes(`data-obj='${key}'`)) {
objHtml += `<div><span class='object' data-obj='${key}'>${obj.name}</span></div>`;
}
}
if (objHtml) html += `<div style="margin-top:8px;">${objHtml}</div>`;
// Exits
let exitsHtml = '';
for (const [to, desc] of Object.entries(room.exits || {})) {
exitsHtml += `<div>${desc}</div>`;
}
if (game.currentRoom === 'hall' && game.flags.doorUnlocked) {
exitsHtml += `<div><span class='exit' data-exit='outside'>Salir por la puerta principal</span></div>`;
}
if (game.currentRoom === 'kitchen' && game.flags.mouseFed) {
exitsHtml += `<div><span class='exit' data-exit='secret'>Entrar al pasadizo secreto</span></div>`;
}
if (exitsHtml) html += `<div style="margin-top:12px; color:#0ff;">${exitsHtml}</div>`;
document.getElementById('scene').innerHTML = html;
attachSceneListeners();
renderInventory();
}
function renderInventory() {
const invDiv = document.getElementById('inventory');
let html = `<span id="inventory-label">Inventario:</span>`;
if (game.inventory.length === 0) {
html += `<span style="color:#888;">(vacío)</span>`;
} else {
for (const item of game.inventory) {
html += `<span class="inv-item${game.selectedItem === item ? ' selected' : ''}" data-item="${item}" title="${inventoryItems[item]?.description || ''}">${inventoryItems[item]?.name || item}</span>`;
}
}
invDiv.innerHTML = html;
attachInventoryListeners();
}
function showDialogue(text) {
document.getElementById('dialogue').innerHTML = text;
}
// --- GAME LOGIC ---
function addToInventory(item) {
if (!game.inventory.includes(item)) {
game.inventory.push(item);
renderInventory();
}
}
function removeFromInventory(item) {
const idx = game.inventory.indexOf(item);
if (idx !== -1) {
game.inventory.splice(idx, 1);
if (game.selectedItem === item) game.selectedItem = null;
renderInventory();
}
}
// --- EVENT HANDLERS ---
function attachSceneListeners() {
// Objects
document.querySelectorAll('.object, .character').forEach(el => {
el.addEventListener('click', e => {
const objKey = el.getAttribute('data-obj');
const room = rooms[game.currentRoom];
const obj = room.objects?.[objKey];
if (!obj) return;
// If using an item
if (game.selectedItem && obj.use) {
const used = obj.use(game.selectedItem);
if (used) {
game.selectedItem = null;
renderInventory();
}
} else {
obj.interact();
}
});
// Hover: show description
el.addEventListener('mouseenter', e => {
const objKey = el.getAttribute('data-obj');
const room = rooms[game.currentRoom];
const obj = room.objects?.[objKey];
if (obj) showDialogue(obj.description);
});
el.addEventListener('mouseleave', e => {
document.getElementById('dialogue').innerHTML = '';
});
});
// Exits
document.querySelectorAll('.exit').forEach(el => {
el.addEventListener('click', e => {
const exitTo = el.getAttribute('data-exit');
if (exitTo && rooms[exitTo]) {
game.currentRoom = exitTo;
showDialogue('');
renderScene();
}
});
el.addEventListener('mouseenter', e => {
showDialogue("Ir a: " + el.textContent);
});
el.addEventListener('mouseleave', e => {
document.getElementById('dialogue').innerHTML = '';
});
});
}
function attachInventoryListeners() {
document.querySelectorAll('.inv-item').forEach(el => {
el.addEventListener('click', e => {
const item = el.getAttribute('data-item');
if (game.selectedItem === item) {
game.selectedItem = null;
showDialogue('');
} else {
game.selectedItem = item;
showDialogue(`Seleccionado: ${inventoryItems[item]?.name || item}. Haz clic en un objeto para usarlo.`);
}
renderInventory();
});
el.addEventListener('mouseenter', e => {
const item = el.getAttribute('data-item');
showDialogue(inventoryItems[item]?.description || '');
});
el.addEventListener('mouseleave', e => {
document.getElementById('dialogue').innerHTML = '';
});
});
}
// --- INITIALIZATION ---
function startGame() {
// Reset all dynamic visibilities
rooms.hall.objects.note.visible = false;
rooms.hall.objects.cheese.visible = false;
rooms.hall.objects.rusty_key.visible = false;
rooms.study.objects.coin.visible = false;
rooms.kitchen.objects.fish.visible = false;
game.currentRoom = 'hall';
game.inventory = [];
game.selectedItem = null;
game.flags = {
doorUnlocked: false,
mouseFed: false,
cheeseTaken: false,
};
renderScene();
showDialogue("¡Bienvenido a la Mansión del Queso! ¿Podrás escapar?");
}
// --- START ---
startGame();
</script>
</body>
</html>