| | """
|
| | رابط کاربری متنی پیشرفته برای بازی
|
| | """
|
| |
|
| | from ui.colors import Colors
|
| | from utils.helpers import format_number, format_percentage
|
| | import time
|
| | import sys
|
| | import textwrap
|
| |
|
| | class ConsoleUI:
|
| | """کلاس برای مدیریت رابط کاربری متنی"""
|
| |
|
| | @staticmethod
|
| | def clear_screen():
|
| | """پاک کردن صفحه ترمینال"""
|
| | import os
|
| | os.system('cls' if os.name == 'nt' else 'clear')
|
| |
|
| | @staticmethod
|
| | def display_title_screen():
|
| | """نمایش صفحه عنوان بازی"""
|
| | ConsoleUI.clear_screen()
|
| |
|
| | title = r"""
|
| | █████╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗████████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗██████╗ ███████╗██████╗
|
| | ██╔══██╗██╔══██╗██║ ██║██╔════╝████╗ ██║╚══██╔══╝ ██╔═══██╗██╔═══██╗██╔══██╗██║ ██║██╔══██╗██╔════╝██╔══██╗
|
| | ███████║██████╔╝██║ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ██║██║ ██║██████╔╝██║ ██║██████╔╝█████╗ ██████╔╝
|
| | ██╔══██║██╔══██╗╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ██║ ██║██║ ██║██╔══██╗██║ ██║██╔══██╗██╔══╝ ██╔══██╗
|
| | ██║ ██║██║ ██║ ╚████╔╝ ███████╗██║ ╚████║ ██║ ╚██████╔╝╚██████╔╝██║ ██║╚██████╔╝██║ ██║███████╗██║ ██║
|
| | ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
| | """
|
| |
|
| | print(Colors.HEADER + title)
|
| | print(Colors.NEUTRAL + "════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════")
|
| | print(Colors.NEUTRAL + " به دنیای پویای 'سایههای امپراتوری' خوش آمدید! جایی که قدرت، سیاست و استراتژی، کلید پیروزی هستند.")
|
| | print(Colors.NEUTRAL + " شما رهبر یک کشور کوچک و نوظهور هستید و هدف شما، گسترش قلمرو، تقویت اقتصاد، و تسلط بر جهان است.")
|
| | print(Colors.NEUTRAL + "════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════")
|
| | print()
|
| |
|
| | @staticmethod
|
| | def display_intro():
|
| | """نمایش مقدمه بازی"""
|
| | ConsoleUI.clear_screen()
|
| |
|
| | intro_text = [
|
| | "در سال ۱۵۰۰ میلادی، جهان لرزان است!",
|
| | "امپراتوریهای عظیم بر سر قدرت به رقابت پرداختهاند،",
|
| | "دریانوردان جسور به دنبال سرزمینهای ناشناخته میگردند،",
|
| | "و سرنوشت ملل در دست رهبرانی است که هوش سیاسی، شجاعت نظامی،",
|
| | "و دیپلماسی هوشمندانه را میآموزند.",
|
| | "",
|
| | "شما اکنون فرمانروای یک پادشاهی نوظهور هستید که در میان طوفان تاریخ،",
|
| | "باید با تصمیماتی تاریخساز از یک سرزمین کوچک، امپراتوریای جاودانه بسازید!",
|
| | "",
|
| | "آمادهاید تا در سال ۱۵۰۰ میلادی، سرنوشت تاریخ را رقم بزنید؟"
|
| | ]
|
| |
|
| | for line in intro_text:
|
| | ConsoleUI.typewriter_effect(line)
|
| | time.sleep(0.3)
|
| |
|
| | print("\n")
|
| | ConsoleUI.wait_for_enter()
|
| |
|
| | @staticmethod
|
| | def typewriter_effect(text, delay=None):
|
| | """نمایش متن با افکت تایپ رایتر"""
|
| | if delay is None:
|
| | delay = 0.02 if len(text) > 50 else 0.03
|
| |
|
| | for char in text:
|
| | sys.stdout.write(char)
|
| | sys.stdout.flush()
|
| | time.sleep(delay)
|
| | print()
|
| |
|
| | @staticmethod
|
| | def display_section_title(title, width=80):
|
| | """نمایش عنوان بخش با فرمت خاص"""
|
| | padding = (width - len(title) - 2) // 2
|
| | print(Colors.HEADER + "╔" + "═" * (width - 2) + "╗")
|
| | print(Colors.HEADER + "║" + " " * padding + Colors.TITLE + title + " " * (width - padding - len(title) - 2) + Colors.HEADER + "║")
|
| | print(Colors.HEADER + "╠" + "═" * (width - 2) + "╣")
|
| |
|
| | @staticmethod
|
| | def display_message(message, indent=2, width=78):
|
| | """نمایش یک پیام معمولی با قابلیت پیچش خط"""
|
| | prefix = " " * indent
|
| | wrapped_lines = textwrap.wrap(message, width=width-indent)
|
| |
|
| | for line in wrapped_lines:
|
| | print(f"{prefix}{Colors.NEUTRAL}{line}")
|
| |
|
| | @staticmethod
|
| | def display_success(message, indent=2, width=78):
|
| | """نمایش پیام موفقیت با افکت"""
|
| | prefix = " " * indent
|
| | wrapped_lines = textwrap.wrap(message, width=width-indent)
|
| |
|
| | for line in wrapped_lines:
|
| | print(f"{prefix}{Colors.SUCCESS}✓ {line}{Colors.NEUTRAL}")
|
| |
|
| | @staticmethod
|
| | def display_warning(message, indent=2, width=78):
|
| | """نمایش هشدار با افکت"""
|
| | prefix = " " * indent
|
| | wrapped_lines = textwrap.wrap(message, width=width-indent)
|
| |
|
| | for line in wrapped_lines:
|
| | print(f"{prefix}{Colors.WARNING}⚠ {line}{Colors.NEUTRAL}")
|
| |
|
| | @staticmethod
|
| | def display_error(message, indent=2, width=78):
|
| | """نمایش خطا با افکت"""
|
| | prefix = " " * indent
|
| | wrapped_lines = textwrap.wrap(message, width=width-indent)
|
| |
|
| | for line in wrapped_lines:
|
| | print(f"{prefix}{Colors.ERROR}✗ {line}{Colors.NEUTRAL}")
|
| |
|
| | @staticmethod
|
| | def display_game_status(game_state, width=80):
|
| | """نمایش وضعیت فعلی بازی با طراحی پیشرفته"""
|
| | country = game_state.player_country
|
| | year = game_state.current_year
|
| |
|
| |
|
| | ConsoleUI.display_section_title(f"{country['name']} - سال {year}", width)
|
| |
|
| |
|
| | status_lines = [
|
| | f"سکه طلا: {Colors.GOLD}{format_number(game_state.gold)}{Colors.NEUTRAL} | "
|
| | f"ثبات سیاسی: {Colors.STABILITY}{format_percentage(game_state.political_stability)}{Colors.NEUTRAL} | "
|
| | f"نارضایتی عمومی: {Colors.DISSATISFACTION}{format_percentage(game_state.public_dissatisfaction)}{Colors.NEUTRAL}",
|
| |
|
| | f"اقتصاد: تجارت={format_percentage(game_state.economy['trade'])} | "
|
| | f"کشاورزی={format_percentage(game_state.economy['agriculture'])} | "
|
| | f"صنعت={format_percentage(game_state.economy['industry'])} | "
|
| | f"تورم={format_percentage(game_state.economy['inflation'])}",
|
| |
|
| | f"روابط بینالمللی: {ConsoleUI.format_relations(game_state.relations, width-20)}",
|
| |
|
| | f"پیشرفت: فرهنگ={format_percentage(game_state.culture_score)} | "
|
| | f"دین={format_percentage(game_state.religious_influence)} | "
|
| | f"قلمرو={game_state.controlled_territories}/23 کشور | "
|
| | f"فناوری={game_state.technology_level}"
|
| | ]
|
| |
|
| | for line in status_lines:
|
| | ConsoleUI.display_message(line, indent=2, width=width-2)
|
| |
|
| | print(Colors.HEADER + "╚" + "═" * (width - 2) + "╝")
|
| | print()
|
| |
|
| | @staticmethod
|
| | def format_relations(relations, width=60):
|
| | """فرمتبندی روابط بینالمللی برای نمایش"""
|
| |
|
| | filtered = {k: v for k, v in relations.items() if v != 100 and abs(v) > 10}
|
| |
|
| |
|
| | sorted_relations = sorted(filtered.items(), key=lambda x: abs(x[1]), reverse=True)
|
| |
|
| |
|
| | top_relations = []
|
| | for name, value in sorted_relations[:3]:
|
| | if value > 50:
|
| | status = f"{Colors.ALLY}همپیمان{Colors.NEUTRAL}"
|
| | elif value > 0:
|
| | status = f"{Colors.FRIEND}دوست{Colors.NEUTRAL}"
|
| | elif value > -30:
|
| | status = f"{Colors.NEUTRAL}خنثی{Colors.NEUTRAL}"
|
| | else:
|
| | status = f"{Colors.ENEMY}دشمن{Colors.NEUTRAL}"
|
| |
|
| | top_relations.append(f"{name}({status}{format_percentage(value)}{Colors.NEUTRAL})")
|
| |
|
| | return ", ".join(top_relations) + ("..." if len(sorted_relations) > 3 else "")
|
| |
|
| | @staticmethod
|
| | def display_country_info(country):
|
| | """نمایش اطلاعات کشور انتخابی با جزئیات بیشتر"""
|
| | ConsoleUI.clear_screen()
|
| | ConsoleUI.display_section_title(f"اطلاعات {country['name']}")
|
| |
|
| | info_lines = [
|
| | f"شرح: {country['description']}",
|
| | "",
|
| | f"ویژگی منحصربهفرد: {Colors.SUCCESS}{country['unique_trait']}{Colors.NEUTRAL}",
|
| | "",
|
| | "ویژگیهای اولیه:",
|
| | f"- جمعیت: {country['base_attributes']['population']} میلیون نفر",
|
| | f"- اقتصاد: تجارت={country['base_attributes']['economy']['trade']}, "
|
| | f"کشاورزی={country['base_attributes']['economy']['agriculture']}, "
|
| | f"صنعت={country['base_attributes']['economy']['industry']}",
|
| | f"- ارتش: ارتش={country['base_attributes']['military']['army']}, "
|
| | f"نیروی دریایی={country['base_attributes']['military']['navy']}, "
|
| | f"فناوری={country['base_attributes']['military']['tech']}",
|
| | f"- ثبات سیاسی: {country['base_attributes']['stability']}",
|
| | f"- مذهب: {country['base_attributes']['religion']}",
|
| | f"- نرخ باروری: {country['base_attributes']['birth_rate']}",
|
| | f"- نرخ مرگومیر: {country['base_attributes']['death_rate']}"
|
| | ]
|
| |
|
| | for line in info_lines:
|
| | ConsoleUI.display_message(line)
|
| |
|
| | print()
|
| |
|
| |
|
| | if "historical_events" in country and country["historical_events"]:
|
| | ConsoleUI.display_section_title("تاریخچه کلیدی", width=60)
|
| | for event in country["historical_events"][:2]:
|
| | ConsoleUI.display_message(f"• {event['year']}: {event['name']}", indent=2)
|
| |
|
| | ConsoleUI.wait_for_enter()
|
| |
|
| | @staticmethod
|
| | def display_event(event):
|
| | """نمایش رویداد و گزینههای آن با طراحی پیشرفته"""
|
| | ConsoleUI.display_section_title(f"رویداد: {event['name']}")
|
| | ConsoleUI.display_message(event["description"], indent=2)
|
| | print()
|
| |
|
| |
|
| | for i, choice in enumerate(event["choices"], 1):
|
| | ConsoleUI.display_message(f"{i}. {choice['text']}", indent=2)
|
| | ConsoleUI.display_message(f" - {choice['description']}", indent=4)
|
| |
|
| | print()
|
| |
|
| | @staticmethod
|
| | def display_weather_event(event):
|
| | """نمایش رویداد آبوهوایی با طراحی مخصوص"""
|
| | ConsoleUI.display_section_title(f"رویداد آبوهوایی: {event['name']}", width=80)
|
| | ConsoleUI.display_warning(event["description"], indent=2)
|
| | print()
|
| |
|
| |
|
| | from game.climate.climate_system import ClimateSystem
|
| | climate = ClimateSystem(None)
|
| | ConsoleUI.display_message("وضعیت فعلی آبوهوایی:", indent=2)
|
| | ConsoleUI.display_message(f"- دما: {climate.temperature}°C", indent=4)
|
| | ConsoleUI.display_message(f"- رطوبت: {climate.humidity}%", indent=4)
|
| | ConsoleUI.display_message(f"- بارش: {climate.precipitation}%", indent=4)
|
| | ConsoleUI.display_message(f"- فصل: {climate.season}", indent=4)
|
| |
|
| | print()
|
| |
|
| |
|
| | for i, choice in enumerate(event["choices"], 1):
|
| | ConsoleUI.display_message(f"{i}. {choice['text']}", indent=2)
|
| | ConsoleUI.display_message(f" - {choice['description']}", indent=4)
|
| |
|
| | print()
|
| |
|
| | @staticmethod
|
| | def display_historical_event(event):
|
| | """نمایش رویداد تاریخی با طراحی مخصوص"""
|
| | ConsoleUI.display_section_title(f"رویداد تاریخی: {event['year']} - {event['name']}", width=80)
|
| | ConsoleUI.display_success(event["description"], indent=2)
|
| | print()
|
| |
|
| |
|
| | ConsoleUI.display_message("اهمیت تاریخی:", indent=2)
|
| | ConsoleUI.display_message("- این رویداد تأثیر عمدهای بر سرنوشت کشور شما داشت", indent=4)
|
| | ConsoleUI.display_message("- انتخابهای شما میتواند مسیر تاریخ را تغییر دهد", indent=4)
|
| |
|
| | print()
|
| |
|
| |
|
| | for i, choice in enumerate(event["choices"], 1):
|
| | ConsoleUI.display_message(f"{i}. {choice['text']}", indent=2)
|
| | ConsoleUI.display_message(f" - {choice['description']}", indent=4)
|
| |
|
| | print()
|
| |
|
| | @staticmethod
|
| | def get_player_choice(choices):
|
| | """دریافت انتخاب بازیکن از بین گزینهها با اعتبارسنجی پیشرفته"""
|
| | while True:
|
| | try:
|
| | choice = input(Colors.PROMPT + "لطفاً شماره انتخاب خود را وارد کنید: " + Colors.NEUTRAL)
|
| | choice_idx = int(choice)
|
| |
|
| | if 1 <= choice_idx <= len(choices):
|
| | return choice_idx
|
| | else:
|
| | ConsoleUI.display_warning(f"لطفاً یک عدد بین 1 تا {len(choices)} انتخاب کنید.")
|
| | except ValueError:
|
| | ConsoleUI.display_warning("لطفاً یک عدد معتبر وارد کنید.")
|
| |
|
| | @staticmethod
|
| | def get_menu_choice(options, width=78):
|
| | """نمایش منو و دریافت انتخاب بازیکن با پیچش خط"""
|
| | for i, option in enumerate(options, 1):
|
| | wrapped_lines = textwrap.wrap(option, width=width-5)
|
| | print(f"{Colors.MENU}{i}. {Colors.NEUTRAL}{wrapped_lines[0]}")
|
| | for line in wrapped_lines[1:]:
|
| | print(f" {line}")
|
| |
|
| | print()
|
| | return ConsoleUI.get_player_choice(options)
|
| |
|
| | @staticmethod
|
| | def confirm_action(prompt):
|
| | """دریافت تأیید از بازیکن برای یک اقدام با گزینههای فارسی"""
|
| | while True:
|
| | response = input(Colors.PROMPT + f"{prompt} (بله/خیر): " + Colors.NEUTRAL).lower()
|
| | if response in ['بله', 'b', 'y', 'yes']:
|
| | return True
|
| | elif response in ['خیر', 'n', 'no']:
|
| | return False
|
| | else:
|
| | ConsoleUI.display_warning("لطفاً 'بله' یا 'خیر' را وارد کنید.")
|
| |
|
| | @staticmethod
|
| | def wait_for_enter():
|
| | """منتظر ماندن تا بازیکن Enter بزند با پیام پویا"""
|
| | print(Colors.PROMPT + "\nبرای ادامه، ", end="")
|
| | for char in "Enter را فشار دهید...":
|
| | sys.stdout.write(char)
|
| | sys.stdout.flush()
|
| | time.sleep(0.05)
|
| | print(Colors.NEUTRAL)
|
| | input()
|
| |
|
| | @staticmethod
|
| | def display_country_status(game_state):
|
| | """نمایش وضعیت کامل کشور با جزئیات"""
|
| | ConsoleUI.clear_screen()
|
| | ConsoleUI.display_section_title(f"وضعیت کامل {game_state.player_country['name']}")
|
| |
|
| |
|
| | ConsoleUI.display_section_title("اطلاعات پایه", width=60)
|
| | ConsoleUI.display_message(f"سال: {game_state.current_year}", indent=2)
|
| | ConsoleUI.display_message(f"جمعیت: {format_number(game_state.population)} نفر", indent=2)
|
| | ConsoleUI.display_message(f"رشد جمعیت: {game_state.population_growth:.1f}%", indent=2)
|
| | ConsoleUI.display_message(f"نرخ سواد: {game_state.literacy_rate}%", indent=2)
|
| | ConsoleUI.display_message(f"شاخص سلامت: {game_state.health_index}", indent=2)
|
| | ConsoleUI.display_message(f"شادی مردم: {game_state.happiness}%", indent=2)
|
| |
|
| |
|
| | ConsoleUI.display_section_title("وضعیت اقتصادی", width=60)
|
| | ConsoleUI.display_message(f"سکه طلا: {format_number(game_state.gold)}", indent=2)
|
| | ConsoleUI.display_message(f"بودجه: مالیات={game_state.tax_rate}%", indent=2)
|
| | ConsoleUI.display_message(f"تجزیه بودجه:", indent=2)
|
| | for sector, percent in game_state.budget.items():
|
| | ConsoleUI.display_message(f"- {sector}: {percent}%", indent=4)
|
| |
|
| | ConsoleUI.display_message(f"اقتصاد:", indent=2)
|
| | ConsoleUI.display_message(f"- تجارت: {game_state.economy['trade']}%", indent=4)
|
| | ConsoleUI.display_message(f"- کشاورزی: {game_state.economy['agriculture']}%", indent=4)
|
| | ConsoleUI.display_message(f"- صنعت: {game_state.economy['industry']}%", indent=4)
|
| | ConsoleUI.display_message(f"- تورم: {game_state.economy['inflation']}%", indent=4)
|
| | ConsoleUI.display_message(f"- بیکاری: {game_state.economy['unemployment']}%", indent=4)
|
| | ConsoleUI.display_message(f"- رشد GDP: {game_state.economy['gdp_growth']}%", indent=4)
|
| |
|
| |
|
| | ConsoleUI.display_section_title("منابع طبیعی", width=60)
|
| | for resource, amount in game_state.resources.items():
|
| | ConsoleUI.display_message(f"{resource}: {amount}", indent=2)
|
| |
|
| | ConsoleUI.wait_for_enter()
|
| |
|
| | @staticmethod
|
| | def display_cultural_status(game_state):
|
| | """نمایش وضعیت فرهنگی کشور"""
|
| | ConsoleUI.clear_screen()
|
| | ConsoleUI.display_section_title("وضعیت فرهنگی")
|
| |
|
| |
|
| | ConsoleUI.display_message(f"امتیاز فرهنگی: {game_state.culture_score}/100", indent=2)
|
| | ConsoleUI.display_message(f"نفوذ فرهنگی: {game_state.cultural_influence}%", indent=2)
|
| | ConsoleUI.display_message(f"زبان رسمی: {game_state.player_country.get('language', 'فارسی')}", indent=2)
|
| |
|
| |
|
| | ConsoleUI.display_section_title("سطح فناوری فرهنگی", width=60)
|
| | ConsoleUI.display_message(f"ادبیات: {game_state.technology.get('literature', 1)}/5", indent=2)
|
| | ConsoleUI.display_message(f"هنر: {game_state.technology.get('art', 1)}/5", indent=2)
|
| | ConsoleUI.display_message(f"موسیقی: {game_state.technology.get('music', 1)}/5", indent=2)
|
| | ConsoleUI.display_message(f"معماری: {game_state.technology.get('architecture', 1)}/5", indent=2)
|
| |
|
| |
|
| | ConsoleUI.display_section_title("کشورهای تحت تأثیر فرهنگی", width=60)
|
| | influenced_countries = [c for c, rel in game_state.relations.items()
|
| | if rel > 50 and c != game_state.player_country["name"]]
|
| |
|
| | if influenced_countries:
|
| | for country in influenced_countries[:5]:
|
| | influence = min(100, 50 + (game_state.relations[country] - 50) * 2)
|
| | ConsoleUI.display_message(f"- {country}: {influence}%", indent=2)
|
| | else:
|
| | ConsoleUI.display_message("هیچ کشوری تحت تأثیر فرهنگی شما نیست.", indent=2)
|
| |
|
| | ConsoleUI.wait_for_enter()
|
| |
|
| | @staticmethod
|
| | def display_technology_tree(game_state):
|
| | """نمایش درخت فناوری با پیشرفت فعلی"""
|
| | ConsoleUI.clear_screen()
|
| | ConsoleUI.display_section_title("درخت فناوری")
|
| |
|
| |
|
| | ConsoleUI.display_message(f"سطح فناوری کلی: {game_state.technology_level}", indent=2)
|
| | ConsoleUI.display_message(f"فناوری جاری در دست تحقیق: {game_state.current_research or 'هیچکدام'}", indent=2)
|
| | ConsoleUI.display_message(f"پیشرفت تحقیق: {game_state.research_progress}%", indent=2)
|
| | ConsoleUI.display_message(f"کارایی تحقیق: {game_state.research_efficiency:.1f}x", indent=2)
|
| |
|
| |
|
| | categories = ["military", "agriculture", "trade", "industry", "medicine", "education"]
|
| | for category in categories:
|
| | ConsoleUI.display_section_title(f"فناوریهای {category}", width=60)
|
| |
|
| |
|
| | category_techs = [tech_id for tech_id, tech in TECHNOLOGIES.items()
|
| | if tech["category"] == category]
|
| |
|
| | for tech_id in category_techs:
|
| | tech = TECHNOLOGIES[tech_id]
|
| | is_unlocked = tech_id in game_state.unlocked_technologies
|
| |
|
| | status = Colors.SUCCESS + "آشکار شده" if is_unlocked else Colors.NEUTRAL + "مخفی"
|
| | symbol = "✓" if is_unlocked else "✗"
|
| |
|
| | ConsoleUI.display_message(f"{symbol} {tech['name']} [{status}{Colors.NEUTRAL}]", indent=2)
|
| | ConsoleUI.display_message(f" {tech['description']}", indent=4)
|
| |
|
| | ConsoleUI.wait_for_enter() |