示例#1
0
    /// <summary>
    /// コマを失う
    /// </summary>
    /// <param name="obj"></param>
    public void LostATop(GameObject obj)
    {
        int id = obj.GetComponent <BattleTopCtrl>().topId;

        //持ち駒リストに追加する
        for (int i = 1; i <= 3; i++)
        {
            for (int j = 1; j <= 3; j++)
            {
                BoardIndex index = new BoardIndex(j, i);
                //コマがなければそこに移動
                if (!opponentTopStage.ChkBoardTop(index))
                {
                    opponentTopStage.SetBoardInf(id, obj, false, index);
                    Vector2 tmpPos = opponentTopStage.GetBoardPosByIndexChild(index);

                    //オブジェクトを移動
                    obj.transform.position = new Vector3(tmpPos.x, 1, tmpPos.y);
                    obj.GetComponent <BattleTopCtrl>().SetIsMine(false);
                    obj.GetComponent <BattleTopCtrl>().SetIndex(index);
                    return;
                }
            }
        }
    }
示例#2
0
    /// <summary>
    /// コマを獲得する
    /// </summary>
    public void GetATop(GameObject obj)
    {
        int id = obj.GetComponent <BattleTopCtrl>().topId;

        //持ち駒リストに追加する
        for (int i = 3; i >= 1; i--)
        {
            for (int j = 3; j >= 1; j--)
            {
                BoardIndex index = new BoardIndex(j, i);
                //コマがなければそこに移動
                if (!myTopStage.ChkBoardTop(index))
                {
                    myTopStage.SetBoardInf(id, obj, true, index);
                    Vector2 tmpPos = myTopStage.GetBoardPosByIndexChild(index);

                    //オブジェクトを移動
                    obj.transform.position = new Vector3(tmpPos.x, 1, tmpPos.y);
                    obj.GetComponent <BattleTopCtrl>().SetIsMine(true);
                    obj.GetComponent <BattleTopCtrl>().SetIndex(index);
                    return;
                }
            }
        }
    }
    void Update()
    {
        //レイを飛ばして当たっていれば移動許可フラグを立てる
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                if (hit.transform.gameObject == this.gameObject)
                {
                    movePermitFlg = true;
                    board.DelBoardInf(index);

                    indexies = board.GetMovableIndex(topId, index);

                    prepareSceneManager.CellHighLight(indexies);
                    foreach (BoardIndex index in indexies)
                    {
                        Vector2 tmpVal  = board.GetBoardPosByIndex(index);
                        Vector3 tmpVal2 = new Vector3(tmpVal.x, tmpVal.y, -6.85f);
                    }
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            if (movePermitFlg)
            {
                Vector2 tmpPos = Input.mousePosition;
                Vector3 pos    = Camera.main.WorldToScreenPoint(transform.position);
                Vector3 a      = new Vector3(tmpPos.x, tmpPos.y, pos.z);
                pos                = Camera.main.ScreenToWorldPoint(a);
                tmpPos             = board.GetCellPosByPos(pos, ref index);
                transform.position = new Vector3(tmpPos.x, tmpPos.y, pos.z);


                indexies = board.GetMovableIndex(topId, index);
                prepareSceneManager.CellHighLight(indexies);

                //持っている間少しでかくする
                transform.localScale = 1.2f * scale;

                //位置が下すぎる場合はホバーする
                if (pos.y < 0.58f)
                {
                    hideFlg            = true;
                    transform.position = pos;
                }
                else
                {
                    hideFlg = false;
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (movePermitFlg)
            {
                //離したら大きさを戻す
                transform.localScale = scale;

                //盤面も初期化しておく
                prepareSceneManager.CellHighLight(new List <BoardIndex>());

                //非表示状態のときは削除する
                if (hideFlg)
                {
                    //コマをしまった
                    prepareSceneManager.EndOutATop(topId);

                    Destroy(gameObject);
                }
                //ドロップ位置が5行目ではない場合は削除する
                else if (index.yIndex != 5)
                {
                    //コマをしまった
                    prepareSceneManager.EndOutATop(topId);

                    Destroy(gameObject);
                }
                //ドロップ位置にコマがない場合、盤面情報に登録する
                else if (!board.ChkBoardTop(index))
                {
                    prepareSceneManager.PutATop(topId, gameObject, index);
                }
                //コマがある場合はそのコマを削除し、上書きする
                else
                {
                    int delId = board.GetTopIdByIndex(index);

                    //コマをしまった
                    prepareSceneManager.EndOutATop(delId);

                    GameObject obj = board.DelBoardInf(index);

                    Destroy(obj);
                    prepareSceneManager.PutATop(topId, gameObject, index);
                }

                movePermitFlg = false;
            }
        }
    }
示例#4
0
    /// <summary>
    /// 盤面アップデート
    /// </summary>
    /// <param name="inf"></param>
    private void BoardUpDate(TopMoveInf inf)
    {
        BoardIndex source;

        //持ち駒かどうかによってソースは変わる
        if (inf.IsBring)
        {
            source = ComvOppenentIndexChild(inf.source);
        }
        else
        {
            source = ComvOpponentIndex(inf.source);
        }
        BoardIndex distination = ComvOpponentIndex(inf.destination);


        //行先にコマがあれば削除して相手の持ち駒とする
        if (board.ChkBoardTop(distination))
        {
            GameObject obj = board.GetObjByIndex(distination);
            board.DelBoardInf(distination);

            int id = obj.GetComponent <BattleTopCtrl>().topId;
            LostATop(obj);
        }

        //盤面情報更新
        if (inf.IsBring)
        {
            GameObject obj = opponentTopStage.GetObjByIndex(source);
            //相手からの情報なので相手の持ち駒を削除
            opponentTopStage.DelBoardInf(source);

            int     topId  = obj.GetComponent <BattleTopCtrl>().topId;
            Vector2 tmpVec = board.GetBoardPosByIndex(distination);
            obj.transform.position = new Vector3(tmpVec.x, 1, tmpVec.y);
            board.SetBoardInf(topId, obj, false, distination);
            PaintCell(new BoardIndex(distination.xIndex, distination.yIndex), false);
        }
        else
        {
            GameObject obj = board.GetObjByIndex(source);

            board.DelBoardInf(source);

            int     topId  = obj.GetComponent <BattleTopCtrl>().topId;
            Vector2 tmpVec = board.GetBoardPosByIndex(distination);
            obj.transform.position = new Vector3(tmpVec.x, 1, tmpVec.y);
            board.SetBoardInf(topId, obj, false, distination);

            //とびがないかチェック(狙撃手はとび確認不要)
            if (topId != 9)
            {
                List <BoardIndex> indexList =
                    board.GetCellIndexBitweenCells(source, distination);

                foreach (BoardIndex index in indexList)
                {
                    PaintCell(index, false);
                }
            }
            PaintCell(new BoardIndex(distination.xIndex, distination.yIndex), false);
        }
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        /* 自分のターンかつ自分のコマのみ移動可能 */
        if (!isMyTurn || !isMine)
        {
            return;
        }

        //レイを飛ばして当たっていれば移動許可フラグを立てる
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                if (hit.transform.gameObject == this.gameObject)
                {
                    movePermitFlg = true;
                    befIndex      = index;
                    if (isBring)
                    {
                        battleSceneManager.UseATop(index);

                        //空のインデックスをすべて取得する
                        indexies = board.GetEmptyBoardIndex();
                    }
                    //盤面上のコマを動かしたとき
                    else
                    {
                        board.DelBoardInf(index);

                        //可動インデックスをすべて取得する
                        indexies = board.GetMovableIndex(topId, index);
                    }

                    //取得したインデックスをすべてハイライトする
                    battleSceneManager.CellHighLight(indexies);
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            if (movePermitFlg)
            {
                inputPos = Input.mousePosition;
                this.pos = Camera.main.WorldToScreenPoint(transform.position);
                Vector3 a = new Vector3(inputPos.x, inputPos.y, pos.z);
                this.pos           = Camera.main.ScreenToWorldPoint(a);
                tmpPos             = board.GetCellPosByPos(new Vector2(this.pos.x, this.pos.z), ref index);
                transform.position = new Vector3(tmpPos.x, 1, tmpPos.y);

                //持っている間少しでかくする
                transform.localScale = 1.2f * scale;

                //範囲外の場合、またはコマを置くことができない場合はセルフィットしない
                if (this.pos.x < -1.0f ||
                    this.pos.x > 1.0f ||
                    this.pos.z < -1.0f ||
                    this.pos.z > 1.0f)
                {
                    reverseFlg         = true;
                    transform.position = this.pos;
                }
                else if (!ChkIsMovableIndex(index))
                {
                    reverseFlg         = true;
                    transform.position = this.pos;
                }
                else
                {
                    reverseFlg = false;
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (movePermitFlg)
            {
                //離したら大きさを戻す
                transform.localScale = scale;

                //盤面のハイライトを初期化しておく
                battleSceneManager.CellHighLight(new List <BoardIndex>());

                //リバース状態のときは元の位置に戻す
                if (reverseFlg)
                {
                    index = befIndex;
                    //コマ置き場→盤面
                    if (isBring)
                    {
                        battleSceneManager.GetATop(gameObject);
                    }
                    //盤面→盤面
                    else
                    {
                        battleSceneManager.PutATop(topId, gameObject, befIndex);
                        Vector2 tmpVec = board.GetBoardPosByIndex(befIndex);
                        gameObject.transform.position = new Vector3(tmpVec.x, gameObject.transform.position.y, tmpVec.y);
                    }
                }
                //ドロップ位置にコマがない場合、盤面情報に登録する
                else if (!board.ChkBoardTop(index))
                {
                    battleSceneManager.PutATop(topId, gameObject, index);

                    //ターンエンド手続き
                    battleSceneManager.TurnEnd(befIndex, index, isBring);

                    //とびがないかチェック(狙撃手はとび確認不要)
                    if (topId != 9)
                    {
                        List <BoardIndex> indexList =
                            board.GetCellIndexBitweenCells(befIndex, index);

                        foreach (BoardIndex index in indexList)
                        {
                            battleSceneManager.PaintCell(index, true);
                        }
                    }
                    battleSceneManager.PaintCell(index, true);

                    //持ち駒を置くことができるのはここのパスのみ
                    if (isBring)
                    {
                        isBring = false;
                    }
                }
                //コマがある場合はそのコマを削除し、上書きする
                else
                {
                    GameObject obj = board.DelBoardInf(index);
                    battleSceneManager.GetATop(obj);
                    battleSceneManager.PutATop(topId, gameObject, index);

                    //ターンエンド手続き
                    battleSceneManager.TurnEnd(befIndex, index, false);

                    //とびがないかチェック(狙撃手はとび確認不要)
                    if (topId != 9)
                    {
                        List <BoardIndex> indexList =
                            board.GetCellIndexBitweenCells(befIndex, index);

                        foreach (BoardIndex index in indexList)
                        {
                            battleSceneManager.PaintCell(index, true);
                        }
                    }
                    battleSceneManager.PaintCell(index, true);
                }

                movePermitFlg = false;
            }
        }
    }