//棋盤初始化
    private void ChessBoardInitialize(int num)
    {
        //查找棋譜資料裡是否有相應編號
        for (int i = 0; i < boardRecordData.m_data.Count; i++)
        {
            if (boardRecordData.m_data[i].number == num)
            {
                break;                                          //找到相應編號後繼續程序
            }
            if (i == boardRecordData.m_data.Count)
            {
                throw new System.Exception("[ERROR]棋譜資料內無相應編號");
            }
        }

        //棋盤配置
        for (int i = 0; i < boardRecordData.m_data[num].boardRecord.Count; i++)
        {
            AnimalChessName _chessName = boardRecordData.m_data[num].boardRecord[i].chessName; //取得棋子名稱
            Vector2         _pos       = boardRecordData.m_data[num].boardRecord[i].pos;       //取得棋子位置
            Camps           _camps     = boardRecordData.m_data[num].boardRecord[i].camps;     //取得棋子陣營
            bool            _isKing    = boardRecordData.m_data[num].boardRecord[i].isKing;    //是否為王

            ChessboardManager.Instance.CreateChess(_chessName, ChessboardManager.Instance.cellsBoard[(int)_pos.x, (int)_pos.y], _camps, _isKing);
        }
    }
示例#2
0
    //設置棋子於指定位置
    //[input] name=棋子名稱 / pos=位置 / player=玩家陣營(True=正面方/False=反面方) / isKing=是否為王
    public void CreateChess(AnimalChessName name, CellBehavior cell, Camps player, bool isKing)
    {
        GameObject    chessGo     = Instantiate(chessPrefab, cell.GetComponent <RectTransform>()); //創建指定的棋子物件
        ChessBehavior ChessScript = chessGo.GetComponent <ChessBehavior>();                        //取得棋子腳本

        ChessScript.ChessInitialize(Dict_ChessAttribute[name], player, isKing);                    //套用棋子屬性設定

        cell.chessScript = ChessScript;                                                            //將棋子腳本註冊至所在的棋格上
    }