プレイヤーの状態
CoddyのLuaジャーニー「Logic & Flow」セクションの一部 — レッスン 26/54。
チャレンジ
簡単リンクされた部屋の構成を基に、ゲームの世界におけるプレイヤーの現在地を追跡するための player テーブルを作成しましょう。
前のチャレンジで作成した startingRoom と gardenRoom 変数が用意されています。
player という名前のテーブルを作成し、以下の1つのキーを設定してください:
currentRoom: これをstartingRoomを参照するように設定します。
プレイヤーの現在の部屋の name を表示し、次にプレイヤーの現在の部屋の description を、それぞれ別の行に出力してください。
期待される出力形式:
Ancient Library
You find yourself in a dusty library filled with ancient books and scrolls.自分で試してみよう
-- Create the starting room
local startingRoom = {
name = "Ancient Library",
description = "A dusty library filled with ancient tomes and scrolls.",
exits = {}
}
-- Create the garden room
local gardenRoom = {
name = "Secret Garden",
description = "A hidden garden with overgrown plants and a small fountain.",
exits = {}
}
-- Link the rooms together
startingRoom.exits["east"] = gardenRoom
gardenRoom.exits["west"] = startingRoom
-- Print the required output
print(startingRoom.name)
print(startingRoom.exits["east"].name)
print(startingRoom.exits["east"].exits["west"].name)