212 lines
7.1 KiB
Python
212 lines
7.1 KiB
Python
"""
|
||
卡牌系统演示
|
||
"""
|
||
import sys
|
||
import os
|
||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||
from kards_battle.core.enums import Nation
|
||
from kards_battle.game.game_engine import GameEngine
|
||
from kards_battle.cards.placeholder_cards import create_placeholder_unit_cards
|
||
|
||
|
||
def demo_basic_card_system():
|
||
"""演示基础卡牌系统功能"""
|
||
print("=== 卡牌系统演示 ===")
|
||
|
||
# 1. 创建占位卡牌
|
||
print("\n1. 创建占位卡牌")
|
||
cards = create_placeholder_unit_cards()
|
||
print(f"创建了 {len(cards)} 张占位卡牌:")
|
||
for i, card in enumerate(cards[:3]): # 只显示前3张
|
||
print(f" {i+1}. {card}")
|
||
print(f" ... 还有 {len(cards)-3} 张卡牌")
|
||
|
||
# 2. 创建游戏引擎和测试游戏
|
||
print("\n2. 创建游戏引擎")
|
||
engine = GameEngine(debug_mode=True)
|
||
|
||
game_state = engine.create_test_game(
|
||
"德军指挥官", Nation.GERMANY, Nation.ITALY,
|
||
"美军指挥官", Nation.USA, Nation.UK
|
||
)
|
||
|
||
print(f"游戏创建成功:")
|
||
print(f" 玩家1: {game_state.player1.name} ({game_state.player1.major_nation}/{game_state.player1.minor_nation})")
|
||
print(f" 玩家2: {game_state.player2.name} ({game_state.player2.major_nation}/{game_state.player2.minor_nation})")
|
||
|
||
# 3. 显示初始手牌
|
||
print("\n3. 初始手牌")
|
||
player1_hand = engine.get_player_hand(0)
|
||
player2_hand = engine.get_player_hand(1)
|
||
|
||
print(f"玩家1手牌 ({len(player1_hand)}张):")
|
||
for card in player1_hand:
|
||
print(f" - {card}")
|
||
|
||
print(f"玩家2手牌 ({len(player2_hand)}张):")
|
||
for card in player2_hand:
|
||
print(f" - {card}")
|
||
|
||
return engine, game_state
|
||
|
||
|
||
def demo_strategic_deployment():
|
||
"""演示战略调度阶段"""
|
||
print("\n=== 战略调度阶段演示 ===")
|
||
|
||
engine, game_state = demo_basic_card_system()
|
||
|
||
# 玩家1进行战略调度 - 不重抽任何牌
|
||
print("\n1. 玩家1战略调度(不重抽)")
|
||
new_cards = engine.perform_strategic_deployment(0, [])
|
||
print(f"玩家1没有重抽任何卡牌")
|
||
|
||
# 玩家2进行战略调度 - 重抽2张牌
|
||
print("\n2. 玩家2战略调度(重抽2张牌)")
|
||
player2_hand = engine.get_player_hand(1)
|
||
cards_to_mulligan = player2_hand[:2]
|
||
|
||
print("重抽前的卡牌:")
|
||
for card in cards_to_mulligan:
|
||
print(f" - {card}")
|
||
|
||
new_cards = engine.perform_strategic_deployment(1, cards_to_mulligan)
|
||
|
||
print("重抽后的新卡牌:")
|
||
for card in new_cards:
|
||
print(f" - {card}")
|
||
|
||
return engine, game_state
|
||
|
||
|
||
def demo_main_game_flow():
|
||
"""演示正式游戏流程"""
|
||
print("\n=== 正式游戏流程演示 ===")
|
||
|
||
engine, game_state = demo_strategic_deployment()
|
||
|
||
# 开始正式游戏
|
||
print("\n开始正式游戏")
|
||
engine.start_main_game()
|
||
|
||
# 显示游戏统计信息
|
||
stats = engine.get_game_statistics()
|
||
print(f"\n当前游戏状态:")
|
||
print(f" 回合: {stats['current_turn']}")
|
||
print(f" 阶段: {stats['phase']}")
|
||
print(f" 当前玩家: {stats['active_player']}")
|
||
|
||
# 显示双方资源状态
|
||
print(f"\n玩家1状态:")
|
||
print(f" Kredits: {stats['player1_stats']['kredits']}")
|
||
print(f" 手牌: {stats['player1_stats']['card_stats']['hand_size']}张")
|
||
print(f" 牌库: {stats['player1_stats']['card_stats']['cards_in_deck']}张")
|
||
|
||
print(f"\n玩家2状态:")
|
||
print(f" Kredits: {stats['player2_stats']['kredits']}")
|
||
print(f" 手牌: {stats['player2_stats']['card_stats']['hand_size']}张")
|
||
print(f" 牌库: {stats['player2_stats']['card_stats']['cards_in_deck']}张")
|
||
|
||
return engine, game_state
|
||
|
||
|
||
def demo_card_playing():
|
||
"""演示打牌功能"""
|
||
print("\n=== 打牌功能演示 ===")
|
||
|
||
engine, game_state = demo_main_game_flow()
|
||
|
||
# 玩家1的回合
|
||
current_player_id = game_state.active_player_id
|
||
current_player = game_state.get_current_player()
|
||
|
||
print(f"\n{current_player.name} 的回合")
|
||
print(f"可用Kredits: {current_player.kredits}")
|
||
|
||
# 获取可打出的卡牌
|
||
playable_cards = engine.get_playable_cards(current_player_id)
|
||
print(f"可打出的卡牌 ({len(playable_cards)}张):")
|
||
for card in playable_cards:
|
||
print(f" - {card}")
|
||
|
||
# 尝试打出一张单位卡
|
||
if playable_cards:
|
||
card_to_play = None
|
||
for card in playable_cards:
|
||
if hasattr(card, 'unit_definition_id'): # 找到一张单位卡
|
||
card_to_play = card
|
||
break
|
||
|
||
if card_to_play:
|
||
print(f"\n尝试打出: {card_to_play}")
|
||
initial_kredits = current_player.kredits
|
||
|
||
success = engine.play_unit_card(current_player_id, card_to_play)
|
||
|
||
if success:
|
||
final_kredits = current_player.kredits
|
||
print(f"打牌成功!")
|
||
print(f" 消耗Kredits: {card_to_play.stats.cost}")
|
||
print(f" 剩余Kredits: {final_kredits}")
|
||
|
||
# 显示战场状态
|
||
battlefield_state = engine.get_battlefield_state()
|
||
print(f"\n战场状态:")
|
||
if current_player_id == 0:
|
||
units = battlefield_state['player1_support']['units']
|
||
print(f" 玩家1支援线: {len(units)}个单位")
|
||
for unit in units[-1:]: # 显示最后部署的单位
|
||
print(f" - {unit}")
|
||
else:
|
||
units = battlefield_state['player2_support']['units']
|
||
print(f" 玩家2支援线: {len(units)}个单位")
|
||
for unit in units[-1:]: # 显示最后部署的单位
|
||
print(f" - {unit}")
|
||
else:
|
||
print("打牌失败!")
|
||
|
||
return engine, game_state
|
||
|
||
|
||
def demo_turn_progression():
|
||
"""演示回合进行"""
|
||
print("\n=== 回合进行演示 ===")
|
||
|
||
engine, game_state = demo_card_playing()
|
||
|
||
# 结束当前玩家回合
|
||
current_player = game_state.get_current_player()
|
||
print(f"\n{current_player.name} 结束回合")
|
||
engine.end_turn(game_state.active_player_id)
|
||
|
||
# 显示新的回合状态
|
||
stats = engine.get_game_statistics()
|
||
print(f"\n新回合状态:")
|
||
print(f" 回合: {stats['current_turn']}")
|
||
print(f" 当前玩家: {stats['active_player']}")
|
||
|
||
new_current_player = game_state.get_current_player()
|
||
print(f" {new_current_player.name} 的Kredits: {new_current_player.kredits}")
|
||
print(f" 手牌数量: {len(engine.get_player_hand(game_state.active_player_id))}")
|
||
|
||
|
||
def main():
|
||
"""主演示函数"""
|
||
try:
|
||
demo_basic_card_system()
|
||
demo_strategic_deployment()
|
||
demo_main_game_flow()
|
||
demo_card_playing()
|
||
demo_turn_progression()
|
||
|
||
print("\n=== 演示完成 ===")
|
||
print("卡牌系统基本功能正常运行!")
|
||
|
||
except Exception as e:
|
||
print(f"\n演示过程中出现错误: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main() |