游戏可以运行
This commit is contained in:
@@ -186,6 +186,14 @@ class UI:
|
||||
build_rect.centery - t.get_height() // 2))
|
||||
self.menu_buttons["deck_build"] = build_rect
|
||||
|
||||
# Random opponent button
|
||||
random_rect = pygame.Rect(WINDOW_WIDTH // 2 - 80, WINDOW_HEIGHT - 60, 160, 40)
|
||||
ink_style.draw_ink_rect(self.screen, random_rect, ZHU_HONG, alpha=200)
|
||||
t = self.font_md.render("随机对手", True, PAPER_WHITE)
|
||||
self.screen.blit(t, (random_rect.centerx - t.get_width() // 2,
|
||||
random_rect.centery - t.get_height() // 2))
|
||||
self.menu_buttons["random"] = random_rect
|
||||
|
||||
def draw_deck_builder(self, faction_id):
|
||||
from card_game.config import DECK_SIZE
|
||||
from collections import Counter
|
||||
@@ -203,7 +211,7 @@ class UI:
|
||||
count_text = self.font_md.render(f"已选:{deck_count}/{DECK_SIZE}", True, count_color)
|
||||
self.screen.blit(count_text, (WINDOW_WIDTH // 2 - count_text.get_width() // 2, 42))
|
||||
|
||||
# Left: available cards
|
||||
# Left: available cards (show stats inline)
|
||||
self.deck_card_rects = []
|
||||
left_x = 20
|
||||
left_y = 75
|
||||
@@ -211,15 +219,15 @@ class UI:
|
||||
left_y += 25
|
||||
|
||||
available = [c for c in CARD_DATABASE.values()
|
||||
if c["faction"] == faction_id or c["faction"] in ("neutral", "ally")]
|
||||
if c["faction"] == faction_id or c["faction"] == "ally"]
|
||||
available.sort(key=lambda c: (c["cost"], c["name"]))
|
||||
|
||||
small_w, small_h = 160, 32
|
||||
cols = 4
|
||||
small_w, small_h = 250, 42
|
||||
cols = 2
|
||||
for i, card_data in enumerate(available):
|
||||
row, col = divmod(i, cols)
|
||||
x = left_x + col * (small_w + 8)
|
||||
y = left_y + row * (small_h + 4)
|
||||
x = left_x + col * (small_w + 6)
|
||||
y = left_y + row * (small_h + 3)
|
||||
if y + small_h > WINDOW_HEIGHT - 60:
|
||||
break
|
||||
cid = card_data["id"]
|
||||
@@ -228,29 +236,33 @@ class UI:
|
||||
can_add = in_deck < max_copies and deck_count < DECK_SIZE
|
||||
|
||||
rect = pygame.Rect(x, y, small_w, small_h)
|
||||
if card_data["faction"] not in ("neutral", "ally"):
|
||||
if card_data["faction"] == faction_id:
|
||||
bg = tuple(max(0, c - 30) for c in faction_color)
|
||||
elif card_data["faction"] == "ally":
|
||||
bg = (100, 90, 55)
|
||||
else:
|
||||
bg = (80, 75, 65)
|
||||
bg = (100, 90, 55)
|
||||
ink_style.draw_ink_rect(self.screen, rect, bg, alpha=180)
|
||||
border_color = PAPER_WHITE if can_add else INK_WASH_3
|
||||
pygame.draw.rect(self.screen, border_color, rect, 1, border_radius=3)
|
||||
|
||||
# Line 1: cost + name + count
|
||||
cost_s = self.font_sm.render(str(card_data["cost"]), True, TENG_HUANG)
|
||||
self.screen.blit(cost_s, (x + 4, y + 8))
|
||||
self.screen.blit(cost_s, (x + 4, y + 3))
|
||||
|
||||
icon = {"unit": "兵", "order": "谋"}.get(card_data["type"], "?")
|
||||
ally_tag = card_data.get("ally_state", "")
|
||||
if card_data["faction"] == "ally" and ally_tag:
|
||||
icon = ally_tag
|
||||
self.screen.blit(self.font_sm.render(icon, True, TENG_HUANG), (x + 22, y + 8))
|
||||
self.screen.blit(self.font_sm.render(card_data["name"][:4], True, PAPER_WHITE), (x + 40, y + 8))
|
||||
name_str = card_data["name"][:6]
|
||||
self.screen.blit(self.font_sm.render(name_str, True, PAPER_WHITE), (x + 22, y + 3))
|
||||
|
||||
ct = f"×{in_deck}/{max_copies}" if in_deck > 0 else f"0/{max_copies}"
|
||||
cs = self.font_sm.render(ct, True, count_color if in_deck > 0 else GRAY)
|
||||
self.screen.blit(cs, (x + small_w - cs.get_width() - 4, y + 8))
|
||||
self.screen.blit(cs, (x + small_w - cs.get_width() - 4, y + 3))
|
||||
|
||||
# Line 2: type + stats
|
||||
if card_data["type"] == "unit":
|
||||
icon = {"infantry": "步", "cavalry": "骑", "chariot": "车",
|
||||
"archer": "弓", "siege": "攻"}.get(card_data.get("unit_type"), "?")
|
||||
stats = f"{icon} 攻{card_data['attack']} 防{card_data['defense']} 血{card_data['max_hp']}"
|
||||
else:
|
||||
stats = f"谋略: {card_data['description'][:12]}"
|
||||
self.screen.blit(self.font_sm.render(stats, True, LIGHT_GRAY), (x + 22, y + 22))
|
||||
self.deck_card_rects.append((rect, cid))
|
||||
|
||||
# Right: current deck
|
||||
@@ -265,30 +277,32 @@ class UI:
|
||||
|
||||
for i, (cid, count) in enumerate(deck_items):
|
||||
card_data = CARD_DATABASE[cid]
|
||||
row, col = divmod(i, 3)
|
||||
x = right_x + col * (small_w + 8)
|
||||
y = right_y + row * (small_h + 4)
|
||||
row, col = divmod(i, 2)
|
||||
x = right_x + col * (small_w + 6)
|
||||
y = right_y + row * (small_h + 3)
|
||||
if y + small_h > WINDOW_HEIGHT - 60:
|
||||
break
|
||||
rect = pygame.Rect(x, y, small_w, small_h)
|
||||
if card_data["faction"] not in ("neutral", "ally"):
|
||||
if card_data["faction"] == faction_id:
|
||||
bg = tuple(max(0, c - 30) for c in faction_color)
|
||||
elif card_data["faction"] == "ally":
|
||||
bg = (100, 90, 55)
|
||||
else:
|
||||
bg = (80, 75, 65)
|
||||
bg = (100, 90, 55)
|
||||
ink_style.draw_ink_rect(self.screen, rect, bg, alpha=180)
|
||||
pygame.draw.rect(self.screen, GOLD, rect, 1, border_radius=3)
|
||||
|
||||
self.screen.blit(self.font_sm.render(str(card_data["cost"]), True, TENG_HUANG), (x + 4, y + 8))
|
||||
icon = {"unit": "兵", "order": "谋"}.get(card_data["type"], "?")
|
||||
ally_tag = card_data.get("ally_state", "")
|
||||
if card_data["faction"] == "ally" and ally_tag:
|
||||
icon = ally_tag
|
||||
self.screen.blit(self.font_sm.render(icon, True, TENG_HUANG), (x + 22, y + 8))
|
||||
self.screen.blit(self.font_sm.render(card_data["name"][:4], True, PAPER_WHITE), (x + 40, y + 8))
|
||||
self.screen.blit(self.font_sm.render(str(card_data["cost"]), True, TENG_HUANG), (x + 4, y + 3))
|
||||
name_str = card_data["name"][:6]
|
||||
self.screen.blit(self.font_sm.render(name_str, True, PAPER_WHITE), (x + 22, y + 3))
|
||||
cs = self.font_sm.render(f"×{count}", True, SONGHUA_GREEN)
|
||||
self.screen.blit(cs, (x + small_w - cs.get_width() - 4, y + 8))
|
||||
self.screen.blit(cs, (x + small_w - cs.get_width() - 4, y + 3))
|
||||
|
||||
if card_data["type"] == "unit":
|
||||
icon = {"infantry": "步", "cavalry": "骑", "chariot": "车",
|
||||
"archer": "弓", "siege": "攻"}.get(card_data.get("unit_type"), "?")
|
||||
stats = f"{icon} 攻{card_data['attack']} 防{card_data['defense']} 血{card_data['max_hp']}"
|
||||
else:
|
||||
stats = f"谋略: {card_data['description'][:12]}"
|
||||
self.screen.blit(self.font_sm.render(stats, True, LIGHT_GRAY), (x + 22, y + 22))
|
||||
self.deck_build_rects.append((rect, cid))
|
||||
|
||||
# Bottom buttons
|
||||
|
||||
Reference in New Issue
Block a user