Menu
Coddy logo textTech

Игровой цикл

Часть раздела Logic & Flow путешествия по Lua на Coddy — урок 27 из 54.

challenge icon

Задание

Легко

Реализуйте основной игровой цикл, который непрерывно отображает описание текущей комнаты, пока игра запущена.

Вам предоставлены переменные startingRoom, gardenRoom и player из предыдущего испытания.

Создайте переменную с именем gameRunning и установите её значение в true.

Напишите цикл while, который продолжается до тех пор, пока gameRunning имеет значение true. Внутри цикла:

  • Выведите описание текущей комнаты игрока
  • Установите gameRunning в значение false, чтобы выйти из цикла (пока что мы добавим правильную обработку ввода в следующем уроке)

Ожидаемый формат вывода:

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

Попробуйте сами

-- 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)

Все уроки раздела Logic & Flow