ゲームループ
CoddyのLuaジャーニー「Logic & Flow」セクションの一部 — レッスン 27/54。
チャレンジ
簡単ゲームが実行されている間、現在の部屋の説明を継続的に表示するメインのゲームループを実装してください。
前のチャレンジで作成した 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)