File size: 24,442 Bytes
89dc309 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
"""
رابط کاربری متنی پیشرفته برای بازی
"""
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)
# انتخاب 3 کشور برتر
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]: # فقط 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]: # فقط 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() |