import 'dart:io'; // حالة نظام المنزل الذكي (المتغيرات) bool lightsOn = false; int thermostatTemp = 20; // درجة حرارة ابتدائية String securityStatus = 'DISARMED'; // دالة لعرض القائمة الرئيسية void displayMenu() { print('\nWelcome to the Smart Home System!'); print('Please choose an action:'); print('1. Toggle lights'); print('2. Set thermostat temperature'); print('3. Arm/disarm security system'); print('4. View system status'); print('5. Exit'); } // دالة لتغيير حالة الإضاءة void toggleLights() { lightsOn = !lightsOn; print('Lights are now ${lightsOn ? 'ON' : 'OFF'}.'); } // دالة لضبط درجة حرارة منظم الحرارة void setThermostat() { stdout.write('Set thermostat temperature (15°C - 30°C): '); // قراءة مدخلات المستخدم String? input = stdin.readLineSync(); if (input != null) { try { int newTemp = int.parse(input.trim()); if (newTemp >= 15 && newTemp <= 30) { thermostatTemp = newTemp; print('Thermostat set to ${thermostatTemp}°C.'); } else { print('Invalid temperature. Please choose between 15°C and 30°C.'); } } catch (e) { print('Invalid input. Please enter a number.'); } } } // دالة Arm/Disarm (تفعيل/تعطيل نظام الحماية) void toggleSecurity() { if (securityStatus == 'DISARMED') { securityStatus = 'ARMED'; print('Security System is now ARMED.'); } else { securityStatus = 'DISARMED'; print('Security System is now DISARMED.'); } } // دالة لعرض حالة النظام void viewSystemStatus() { // تحديد حالة الطقس بناءً على الحرارة String tempStatus = (thermostatTemp > 24) ? 'Warm Day' : 'Cool Day'; print('System Status:'); print('- Lights: ${lightsOn ? 'ON' : 'OFF'}'); print('- Thermostat: ${thermostatTemp}°C - $tempStatus'); print('- Security System: $securityStatus'); } // الدالة الرئيسية (Main Function) void main() { bool running = true; // حلقة (Loop) للاستمرار في استقبال الأوامر while (running) { displayMenu(); // عرض القائمة stdout.write('Enter your choice: '); String? choiceInput = stdin.readLineSync(); // استقبال مدخلات المستخدم if (choiceInput == null) continue; int? choice = int.tryParse(choiceInput.trim()); switch (choice) { case 1: toggleLights(); break; case 2: setThermostat(); break; case 3: toggleSecurity(); break; case 4: viewSystemStatus(); break; case 5: print('Exiting the system. Goodbye!'); running = false; // إنهاء الحلقة والخروج break; default: print('Invalid choice. Please enter a number between 1 and 5.'); } }