حلقة اللعبة
جزء من قسم Logic & Flow في رحلة Lua على Coddy — الدرس 27 من 54.
التحدي
سهلقم بتنفيذ حلقة اللعبة الرئيسية التي تعرض وصف الغرفة الحالية باستمرار أثناء تشغيل اللعبة.
تم تزويدك بمتغيرات 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
1التكرار المتقدم عبر الجداول
التكرار باستخدام pairs()التكرار باستخدام ipairs()pairs() مقابل ipairs()مراجعة - ورقة الشخصية2المزيد من دوال مكتبة Table
table.concat()إنشاء الجداول و unpack()table.sort()فرز مخصص باستخدام الدوالمراجعة - لوحة أعلى النتائج5مشروع: محرك مغامرة نصية
إعداد المشروع: الغرفةربط الغرف