| 10 | } |
| 11 | |
| 12 | void PuzzleGame::loadPuzzle(const PuzzleConfig& config) |
| 13 | { |
| 14 | m_puzzle = config; |
| 15 | |
| 16 | // 先将所有棋子标记为死亡 |
| 17 | for (int i = 0; i < 32; i++) { |
| 18 | m_ChessPieces[i].init(i); |
| 19 | m_ChessPieces[i].m_bDead = true; |
| 20 | } |
| 21 | |
| 22 | // 根据配置恢复存活棋子的位置 |
| 23 | for (const auto& p : config.pieces) { |
| 24 | if (p.id >= 0 && p.id < 32) { |
| 25 | m_ChessPieces[p.id].m_nRow = p.row; |
| 26 | m_ChessPieces[p.id].m_nCol = p.col; |
| 27 | m_ChessPieces[p.id].m_bDead = false; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // 设置先手和AI方 |
| 32 | m_bIsRed = config.redFirst; |
| 33 | m_bAiIsRed = !config.playerIsRed; |
| 34 | |
| 35 | // 如果用户执黑,翻转视角 |
| 36 | setPerspectiveFlipped(!config.playerIsRed); |
| 37 | |
| 38 | m_ChessSteps.clear(); |
| 39 | m_nSelectID = -1; |
| 40 | m_bIsOver = false; |
| 41 | m_bIsShowStep = true; |
| 42 | m_bTimerAutoStarted = false; |
| 43 | |
| 44 | update(); |
| 45 | |
| 46 | // 如果AI先手,立即让AI走棋 |
| 47 | if (m_bIsRed == m_bAiIsRed) { |
| 48 | machineChooseAndMovePieces(); |
| 49 | } |
| 50 | } |