예제 #1
0
    //棋子移動
    private IEnumerator Cor_ChessMove()
    {
        //TODO:棋子移動特效

        ChessBehavior originChess = ChessboardManager.Instance.playerMoveAction.OriginChess; //所選棋子
        CellBehavior  targetCell  = ChessboardManager.Instance.playerMoveAction.TargetCell;  //目標格

        ChessboardManager.Instance.Move(originChess, targetCell, true);                      //棋子移動程序

        if ((originChess.chessPlayer == Camps.正面方 && originChess.isKing && targetCell.cTag == CellTag.正面方升變棋盤格) ||
            (originChess.chessPlayer == Camps.反面方 && originChess.isKing && targetCell.cTag == CellTag.反面方升變棋盤格))
        {
            if (conquerPlayer == Camps.無)
            {
                conquerPlayer = nowPlayer;                           //若王走到底, 則記錄玩家陣營至下一回合判斷勝負
            }
        }

        StartCoroutine(Cor_LevelUp(originChess, targetCell, ChessboardManager.Instance.playerMoveAction.moveMode)); //升變
        StartCoroutine(Cor_Eat());                                                                                  //吃子

        yield return(new WaitUntil(() => (pcs_eat && pcs_levelUp)));                                                //吃子與升變程序都完成時

        pcs_eat     = false;
        pcs_levelUp = false;

        StepEnd = true; //玩家下棋指令結束
    }
예제 #2
0
 //清空行動狀態
 public void ActionClear()
 {
     OriginChess = null;
     TargetCell  = null;
     EattedChess = null;
     isSet       = false;
 }
예제 #3
0
    //滑鼠點擊事件
    private void MouseClick()
    {
        if (dragingCell == null && clickedCell != null && clickedCell.chessScript != null && clickedCell.chessScript.chessPlayer == GameController.Instance.nowPlayer) //若尚未點擊 且 所點擊格子不為null 且 所點擊的格子上有棋子 且 棋子為我方的
        {
            dragingCell = clickedCell;                                                                                                                                 //設定拖曳指定格子

            GameObject prefab = clickedCell.chessScript.gameObject;                                                                                                    //取得欲生成虛擬圖案的模板圖樣
            GameObject go     = Instantiate(prefab, dragingItemParent);                                                                                                //生成虛擬圖樣

            //初始化位置&尺寸
            RectTransform rt = go.GetComponent <RectTransform>();
            rt.anchorMin = new Vector2(0, 0);
            rt.anchorMax = new Vector2(0, 0);
            rt.sizeDelta = UIManager.Instance.cellSize;

            //初始化顏色
            ChessBehavior chessScript          = go.GetComponent <ChessBehavior>();
            Color         originalColor_frame  = chessScript.frameImage.color;
            Color         originalColor_animal = chessScript.animalIcon.color;

            chessScript.frameImage.color = new Color(originalColor_frame.r, originalColor_frame.g, originalColor_frame.b, UIManager.Instance.dragingChessAlpha);
            chessScript.animalIcon.color = new Color(originalColor_animal.r, originalColor_animal.g, originalColor_animal.b, UIManager.Instance.dragingChessAlpha);

            StartCoroutine(DragingChess(go.transform)); //開始拖曳
        }
    }
예제 #4
0
    private Vector2 _p;                                                            //光標位置

    #endregion
    #region 內建變數 --------------------------------------------------------------------------------------------------------------

    void Awake()
    {
        if (_instance == null)
        {
            _instance = this;
        }
    }
예제 #5
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;                                                            //將棋子腳本註冊至所在的棋格上
    }
예제 #6
0
 //棋子移動(多載2/2) 指定棋子到格子
 public void Move(ChessBehavior originChess, CellBehavior targetCell, bool clearOriginCell)
 {
     if (originChess.transform.parent == null)
     {
         _Move(null, originChess, targetCell, clearOriginCell);
     }
     else
     {
         _Move(originChess.transform.parent.GetComponent <CellBehavior>(), originChess, targetCell, clearOriginCell);
     }
 }
    //加入打入預備棋
    public void AddDropPawnChess(ChessBehavior originChess, Camps changeTo)
    {
        GameObject   cellGo = Instantiate(ChessboardManager.Instance.cellPrefab, this.transform);
        CellBehavior cell   = cellGo.GetComponent <CellBehavior>();

        dropPawnCells.Add(cell);                                                                                                                           //加入打入預備棋格物件

        cell.cTag = CellTag.打入預備格;                                                                                                                         //設定格子類型
        cell.pos  = new Vector2(-100, -100);                                                                                                               //設定格子位置

        AutoLayout();                                                                                                                                      //自動調整尺寸

        ChessboardManager.Instance.Move(originChess, cell, false);                                                                                         //將棋子移動到打入預備格

        originChess.ChessInitialize(ChessboardManager.Instance.Dict_ChessAttribute[originChess.GetAttribure.dropPawnChess], changeTo, originChess.isKing); //若棋子被吃掉後會改變型態, 則更新棋子狀態
    }
예제 #8
0
    public bool moveMode; //移動模式(true = 一般 / false = 打入)

    //建構子
    public PlayerMoveAction(ChessBehavior origin, CellBehavior target, bool mode)
    {
        isSet       = true;
        OriginChess = origin;
        TargetCell  = target;
        moveMode    = mode;

        //檢測目標格是否有對方棋子, 若有則設定為被吃掉的棋子
        if (target.chessScript != null && target.chessScript.chessPlayer != GameController.Instance.nowPlayer)
        {
            EattedChess = target.chessScript;
        }
        else
        {
            EattedChess = null;
        }
    }
예제 #9
0
    //加入打入預備棋格
    private IEnumerator Cor_AddDropPawnCell()
    {
        //TODO:加入預備棋格特效

        ChessBehavior targetChess = ChessboardManager.Instance.playerMoveAction.EattedChess;

        //加入打入預備棋區域
        if (targetChess.chessPlayer == Camps.反面方) //被吃掉的是反面方棋子
        {
            ChessboardManager.Instance.dropPawnPanel_player1.AddDropPawnChess(targetChess, Camps.正面方);
        }
        else //被吃掉的是正面方棋子
        {
            ChessboardManager.Instance.dropPawnPanel_player2.AddDropPawnChess(targetChess, Camps.反面方);
        }

        yield return(null);
    }
예제 #10
0
    //升變
    private IEnumerator Cor_LevelUp(ChessBehavior chess, CellBehavior targetCell, bool moveMode)
    {
        if (!moveMode)
        {
            goto Ending;            //打入不會觸發升變, 故直接結束程序
        }
        if ((chess.chessPlayer == Camps.正面方 && targetCell.cTag != CellTag.正面方升變棋盤格) ||
            (chess.chessPlayer == Camps.反面方 && targetCell.cTag != CellTag.反面方升變棋盤格))
        {
            goto Ending;                                                                            //若目標格並非升變格
        }
        if (chess.GetAttribure.levelUpChess == chess.GetAttribure.chessName)
        {
            goto Ending;                                                                  //若升變指定棋子=自身時, 表示不發生升變
        }
        //TODO : 升變特效
        yield return(null);

        chess.ChessInitialize(ChessboardManager.Instance.Dict_ChessAttribute[chess.GetAttribure.levelUpChess], nowPlayer, chess.isKing);

Ending:
        pcs_levelUp = true;
    }
예제 #11
0
    //[Private]棋子移動
    private void _Move(CellBehavior originCell, ChessBehavior originChess, CellBehavior targetCell, bool clearOriginCell)
    {
        //位置移位
        originChess.transform.SetParent(targetCell.transform);
        originChess.transform.localPosition = Vector2.zero;

        //腳本移位
        targetCell.chessScript = originChess;
        if (originCell != null && clearOriginCell)
        {
            originCell.chessScript = null;
        }

        //重設尺寸
        originChess.GetComponent <RectTransform>().sizeDelta = Vector2.zero;

        //"打入"的狀況將棋格消除
        if (originCell.cTag == CellTag.打入預備格)
        {
            originCell.GetComponentInParent <DropPawnPanelManager>().dropPawnCells.Remove(originCell);
            Destroy(originCell.gameObject);
        }
    }
예제 #12
0
    //-------------------------------------------------------------------------------------------------------------------

    //可移動格邏輯判斷演算
    //傳入的棋格物件(欲判斷棋格)
    private void ActiveCellJudgement(CellBehavior focusCell, List <CellBehavior> resultList)
    {
        //Debug.Log(string.Format("[Func Test] Cell[{0}, {1}]", pos[0], pos[1]));

        if (focusCell.chessScript == null)
        {
            return;                                       //若棋格不含棋子物件時, 返回null並跳出
        }
        ChessBehavior focusChess = focusCell.chessScript; //棋格上的棋子腳本

        if (focusCell.cTag == CellTag.打入預備格)              //打入的狀況
        {
            if (chessScript == null)
            {
                resultList.Add(this);                      //若棋格上無棋子即可打入
            }
        }
        else //一般下棋的狀況
        {
            //滿足條件時要執行的程式
            UnityEngine.Events.UnityAction resultAction = () =>
            {
                if (chessScript != null && chessScript.chessPlayer == GameController.Instance.nowPlayer)
                {
                    return;                                                                                      //若格子上的棋子為自己陣營的棋子時, 不可移動
                }
                //ChessboardManager.Instance.activePosList.Add(pos);
                resultList.Add(this);
                return;
            };

            for (int i = 0; i < focusChess.directionType.Count; i++) //遍歷指定棋子的所有可走方向, 若有符合者則追加至可移動列表(ChessboardManager的activePosList)
            {
                switch (focusChess.directionType[i])
                {
                case DirectionType.左上:
                    if (focusCell.pos.x - 1 == pos.x && focusCell.pos.y + 1 == pos.y)
                    {
                        resultAction();
                    }
                    break;

                case DirectionType.:
                    if (focusCell.pos.x == pos.x && focusCell.pos.y + 1 == pos.y)
                    {
                        resultAction();
                    }
                    break;

                case DirectionType.右上:
                    if (focusCell.pos.x + 1 == pos.x && focusCell.pos.y + 1 == pos.y)
                    {
                        resultAction();
                    }
                    break;

                case DirectionType.左:
                    if (focusCell.pos.x - 1 == pos.x && focusCell.pos.y == pos.y)
                    {
                        resultAction();
                    }
                    break;

                case DirectionType.右:
                    if (focusCell.pos.x + 1 == pos.x && focusCell.pos.y == pos.y)
                    {
                        resultAction();
                    }
                    break;

                case DirectionType.左下:
                    if (focusCell.pos.x - 1 == pos.x && focusCell.pos.y - 1 == pos.y)
                    {
                        resultAction();
                    }
                    break;

                case DirectionType.:
                    if (focusCell.pos.x == pos.x && focusCell.pos.y - 1 == pos.y)
                    {
                        resultAction();
                    }
                    break;

                case DirectionType.右下:
                    if (focusCell.pos.x + 1 == pos.x && focusCell.pos.y - 1 == pos.y)
                    {
                        resultAction();
                    }
                    break;
                }
            }
        }
    }