Menu
Coddy logo textTech

El bucle del juego

Parte de la sección Logic & Flow del Journey de Lua de Coddy — lección 27 de 54.

challenge icon

Desafío

Fácil

Implementa el bucle principal del juego que muestra continuamente la descripción de la habitación actual mientras el juego se está ejecutando.

Se te proporcionan las variables startingRoom, gardenRoom y player del desafío anterior.

Crea una variable llamada gameRunning y establécela en true.

Escribe un bucle while que continúe mientras gameRunning sea true. Dentro del bucle:

  • Imprime la descripción de la habitación actual del jugador (player)
  • Establece gameRunning en false para salir del bucle (por ahora, añadiremos el manejo de entrada adecuado en la próxima lección)

Formato de salida esperado:

You find yourself in a dusty library filled with ancient books and scrolls.

Pruébalo tú mismo

-- Create the starting room
local startingRoom = {
    name = "Ancient Library",
    description = "You find yourself in a dusty library filled with ancient books and scrolls."
}

-- Create the garden room
local gardenRoom = {
    name = "Secret Garden",
    description = "A beautiful garden with exotic flowers and a mysterious fountain."
}

-- Link the rooms
startingRoom.nextRoom = gardenRoom
gardenRoom.previousRoom = startingRoom

-- Create the player table
local player = {
    currentRoom = startingRoom
}

-- Print the player's current room name and description
print(player.currentRoom.name)
print(player.currentRoom.description)

Todas las lecciones de Logic & Flow