Menu
Coddy logo textTech
flag Ar iconالعربيةdown icon

حلقة اللعبة

جزء من قسم المنطق والتحكم في التدفق في رحلة 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)

جميع دروس المنطق والتحكم في التدفق

تدرّب بنفسك: مترجم Lua عبر الإنترنت