Example #1
0
    /// 自分自身をクリックした時の処理
    public void OnClickSelf()
    {
        if (isPlayer1 == tebanManager.isPlayer1Teban)
        {
            // 駒の進む方向を決定
            if (isPlayer1)
            {
                direction = -1;
            }
            else
            {
                direction = 1;
            }

            Debug.Log("Button click!");

            int posSuji = (int)(transform.position.x / boardManager.scale);      //盤の座標をプログラムの座標に変換 suji, dan -> y, x
            int posDan  = -(int)(transform.position.y / boardManager.scale) + 5; //盤の座標をプログラムの座標に変換 suji, dan -> y, x

            Debug.Log("posDan " + posDan);                                       // suji, dan -> y, x
            Debug.Log("posSuji " + posSuji);                                     // suji, dan -> y, x

            // 画面上の処理
            boardManager.DeactivateButtonAll();                 // ボタンを全部消す

            // 内部の処理
            boardManager.te.koma = boardManager.CheckKomaName(gameObject.name.ToString()); // 駒を指定

            if (!isSelected)                                                               // 駒が未選択の場合
            {
                isSelected = true;
                boardManager.ResetFlagOtherThanSelf(gameObject);                        // 他の駒のisSelectedをfalseにする

                //盤上の駒の場合
                if (1 <= posDan && posDan <= 4 && 1 <= posSuji && posSuji <= 3)
                {
                    Debug.Log("盤上の駒");

                    boardManager.te.from.dan  = posDan;
                    boardManager.te.from.suji = posSuji;

                    // 駒の動ける範囲を確認
                    for (int i = 0; i < movableArea.Length; i++)
                    {
                        if (movableArea [i] == true)
                        {
                            switch (i)
                            {
                            case 0:
                                if (boardManager.IsMovable(isPlayer1, posDan + 1 * direction, posSuji - 1 * direction))                                 // suji, dan -> y, x
                                {
                                    boardManager.ActivateButton(posDan + 1 * direction, posSuji - 1 * direction);                                       // suji, dan -> y, x
                                }
                                break;

                            case 1:
                                if (boardManager.IsMovable(isPlayer1, posDan + 1 * direction, posSuji))
                                {
                                    boardManager.ActivateButton(posDan + 1 * direction, posSuji);
                                }
                                break;

                            case 2:
                                if (boardManager.IsMovable(isPlayer1, posDan + 1 * direction, posSuji + 1 * direction))
                                {
                                    boardManager.ActivateButton(posDan + 1 * direction, posSuji + 1 * direction);
                                }
                                break;

                            case 3:
                                if (boardManager.IsMovable(isPlayer1, posDan, posSuji - 1 * direction))
                                {
                                    boardManager.ActivateButton(posDan, posSuji - 1 * direction);
                                }
                                break;

                            case 4:
                                if (boardManager.IsMovable(isPlayer1, posDan, posSuji + 1 * direction))
                                {
                                    boardManager.ActivateButton(posDan, posSuji + 1 * direction);
                                }
                                break;

                            case 5:
                                if (boardManager.IsMovable(isPlayer1, posDan - 1 * direction, posSuji - 1 * direction))
                                {
                                    boardManager.ActivateButton(posDan - 1 * direction, posSuji - 1 * direction);
                                }
                                break;

                            case 6:
                                if (boardManager.IsMovable(isPlayer1, posDan - 1 * direction, posSuji))
                                {
                                    boardManager.ActivateButton(posDan - 1 * direction, posSuji);
                                }
                                break;

                            case 7:
                                if (boardManager.IsMovable(isPlayer1, posDan - 1 * direction, posSuji + 1 * direction))
                                {
                                    boardManager.ActivateButton(posDan - 1 * direction, posSuji + 1 * direction);
                                }
                                break;

                            default:
                                Debug.Log("Initial Pos Error");
                                break;
                            }
                        }
                    }
                }
                else                     // 手駒の場合
                {
                    boardManager.te.from.dan  = 0;
                    boardManager.te.from.suji = 0;
                    boardManager.ActivateButtonInEmpty();                       // 開いているマスのボタンを有効にする
                }
            }
            else                        // 駒が選択済の場合
            {
                isSelected = false;
            }
        }
    }