게임 루프
Coddy Lua 여정의 Logic & Flow 섹션에 포함된 레슨 — 54개 중 27번째.
챌린지
쉬움게임이 실행되는 동안 현재 방의 설명을 지속적으로 표시하는 메인 게임 루프를 구현하세요.
이전 챌린지에서 제공된 startingRoom, gardenRoom, 그리고 player 변수가 주어집니다.
gameRunning이라는 변수를 생성하고 true로 설정하세요.
gameRunning이 true인 동안 계속되는 while 루프를 작성하세요. 루프 내부에서 다음을 수행합니다:
- 플레이어의 현재 방에 대한 설명을 출력합니다.
- 루프를 종료하기 위해
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)