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;
            }
        }
    }
示例#2
0
    private ShogiBoard opponentTopStage;  /* 相手の持ち駒情報   */

    void Start()
    {
        turnManager = GetComponent <PunTurnManager>();
        turnManager.TurnManagerListener = this;
        turnManager.TurnDuration        = 30f;

        PhotonNetwork.IsMessageQueueRunning = true;

        GameManager.Instance.RefTopTableList(ref topTableList);
        GameManager.Instance.RefTopAlignInfo(ref alignInfo);
        opponentAlignInfo = new int[GameDef.BOARD_CELLS + 1];
        //ボードのインスタンス化
        board         = new ShogiBoard(GameDef.BOARD_CELLS, new Vector2(BoardObj.transform.position.x, BoardObj.transform.position.z));
        redCellObj    = new GameObject[GameDef.BOARD_CELLS + 1, GameDef.BOARD_CELLS + 1];
        blueCellObj   = new GameObject[GameDef.BOARD_CELLS + 1, GameDef.BOARD_CELLS + 1];
        yellowCellObj = new GameObject[GameDef.BOARD_CELLS + 1, GameDef.BOARD_CELLS + 1];
        whiteCellObj  = new GameObject[GameDef.BOARD_CELLS + 1, GameDef.BOARD_CELLS + 1];
        GameObject redCellPref    = Resources.Load <GameObject>("GameObjects/BattleScene/RedCellObject");
        GameObject blueCellPref   = Resources.Load <GameObject>("GameObjects/BattleScene/BlueCellObject");
        GameObject yellowCellPref = Resources.Load <GameObject>("GameObjects/BattleScene/YellowCellObject");
        GameObject whiteCellPref  = Resources.Load <GameObject>("GameObjects/BattleScene/WhiteCellObject");

        PopupPanel.SetActive(false);
        //配置情報をもとに盤面を初期化する
        //コマ配置情報をもとにコマを再配置する
        GameObject topPref = Resources.Load <GameObject>("GameObjects/BattleScene/Top");

        for (int i = 1; i <= GameDef.BOARD_CELLS; i++)
        {
            if (alignInfo[i] == 0)
            {
                continue;
            }

            GameObject top = Instantiate(topPref);
            //マテリアル設定
            Material[] mats = top.GetComponent <MeshRenderer>().materials;
            mats[0] = Resources.Load <Material>("Materials/" + topTableList.Find(topTable => topTable.Id == alignInfo[i]).AssetName);
            top.GetComponent <MeshRenderer>().materials = mats;

            BattleTopCtrl topCtrl = top.GetComponent <BattleTopCtrl>();
            BoardIndex    index   = new BoardIndex(i, GameDef.BOARD_CELLS);
            Vector2       tmpVec  = board.GetBoardPosByIndex(index);
            top.transform.position = new Vector3(tmpVec.x, 1, tmpVec.y);
            topCtrl.topId          = alignInfo[i];
            topCtrl.isMine         = true;
            topCtrl.SetIsMine(true);
            topCtrl.SetIsMyTurn(false);
            board.SetBoardInf(alignInfo[i], top, true, index);
        }

        for (int i = 1; i <= GameDef.BOARD_CELLS; i++)
        {
            for (int j = 1; j <= GameDef.BOARD_CELLS; j++)
            {
                BoardIndex index   = new BoardIndex(i, j);
                Vector2    tmpVal  = board.GetBoardPosByIndex(index);
                Vector3    tmpVal2 = new Vector3(tmpVal.x, 1, tmpVal.y);

                //色付きセル(黄色、赤)を配置する
                GameObject redCell = Instantiate(redCellPref, tmpVal2, Quaternion.identity);
                redCellObj[i, j] = redCell;
                GameObject yellowCell = Instantiate(yellowCellPref, tmpVal2, Quaternion.identity);
                yellowCellObj[i, j] = yellowCell;
                GameObject blueCell = Instantiate(blueCellPref, tmpVal2, Quaternion.identity);
                blueCellObj[i, j] = blueCell;
                GameObject whiteCell = Instantiate(whiteCellPref, tmpVal2, Quaternion.identity);
                whiteCellObj[i, j] = whiteCell;

                //赤セルを少し下げておく
                redCellObj[i, j].transform.position = new Vector3(redCellObj[i, j].transform.position.x,
                                                                  0.5f,
                                                                  redCellObj[i, j].transform.position.z);
                //青セルを少し下げておく
                blueCellObj[i, j].transform.position = new Vector3(blueCellObj[i, j].transform.position.x,
                                                                   0.5f,
                                                                   blueCellObj[i, j].transform.position.z);
                //黄セルを少し下げておく
                yellowCellObj[i, j].transform.position = new Vector3(yellowCellObj[i, j].transform.position.x,
                                                                     0.5f,
                                                                     yellowCellObj[i, j].transform.position.z);
            }
        }

        //コマ置き場のインスタンス化
        myTopStage = new ShogiBoard(3, new Vector2(myTopStageObj.transform.position.x,
                                                   myTopStageObj.transform.position.z));
        opponentTopStage = new ShogiBoard(3, new Vector2(oppenentsTopStageObj.transform.position.x,
                                                         oppenentsTopStageObj.transform.position.z));
        //初期位置は塗っておく
        for (int i = 1; i <= 5; i++)
        {
            BoardIndex index = new BoardIndex(i, 5);
            PaintCell(index, true);
        }

        //すでに部屋に相手がいる場合はゲーム開始します
        if (PhotonNetwork.CurrentRoom.PlayerCount == 2)
        {
            machingPanel.SetActive(false);
            StartCoroutine(StartGameSequence());
        }
        else
        {
            machingPanel.SetActive(true);
        }
    }
示例#3
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;
            }
        }
    }
示例#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);
        }
    }
    private GameObject[,] yellowCellObj; /* 黄色いセル       */

    void Start()
    {
        /* 変数初期化 */
        List <TopTable> topTableList = new List <TopTable>();

        GameManager.Instance.RefTopTableList(ref topTableList);

        /* 初期情報登録 */
        topDic = GameManager.Instance.GetPossessingTops();
        GameManager.Instance.RefTopAlignInfo(ref topArignInfo);
        board         = new ShogiBoard(GameDef.BOARD_CELLS, shogiBoard.transform.position);
        topCntText    = new Text[topTableList.Count + 1];
        redCellObj    = new GameObject[GameDef.BOARD_CELLS + 1, GameDef.BOARD_CELLS + 1];
        yellowCellObj = new GameObject[GameDef.BOARD_CELLS + 1, GameDef.BOARD_CELLS + 1];

        /* ロードリソース */
        GameObject image          = Resources.Load <GameObject>("GameObjects/Image");
        GameObject itemPref       = Resources.Load <GameObject>("GameObjects/PrepareScene/Tops/Top");
        GameObject topCntTextObj  = Resources.Load <GameObject>("UI/Text");
        GameObject redCellPref    = Resources.Load <GameObject>("GameObjects/PrepareScene/RedCellObject");
        GameObject yellowCellPref = Resources.Load <GameObject>("GameObjects/PrepareScene/YellowCellObject");

        /* 所持コマ情報をもとにScrollViewにコマを格納する */
        foreach (TopTable top in topTableList)
        {
            //所持コマ0個の場合はimageを生成しない
            if (topDic[top.Id] == 0)
            {
                continue;
            }

            //imageを生成する
            GameObject tmp        = Instantiate(image);
            Sprite     itemSprite = Resources.Load <Sprite>("Images/" + top.AssetName);
            tmp.GetComponent <Image>().sprite = itemSprite;
            tmp.transform.SetParent(content);
            tmp.transform.localPosition = new Vector3(tmp.transform.position.x,
                                                      tmp.transform.position.y,
                                                      0);
            tmp.transform.localScale = new Vector3(1, 1, 1);
            tmp.AddComponent <ContentClickListener>().topId = top.Id;

            //textを生成する
            GameObject tmpTextObj = Instantiate(topCntTextObj);
            topCntText[top.Id] = tmpTextObj.GetComponent <Text>();
            tmpTextObj.transform.SetParent(tmp.transform);
            tmpTextObj.transform.localScale = new Vector3(1, 1, 1);
            tmpTextObj.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(0, 7.6f, 0);
            topCntText[top.Id].text = "×  " + topDic[top.Id];
        }

        /* コマ配置情報をもとにコマを再配置する */
        for (int i = 1; i <= GameDef.BOARD_CELLS; i++)
        {
            if (topArignInfo[i] == 0)
            {
                continue;
            }

            GameObject top = Instantiate(itemPref);

            //マテリアル設定
            Material[] mats = top.GetComponent <MeshRenderer>().materials;
            mats[0] = Resources.Load <Material>("Materials/" + topTableList.Find(topTable => topTable.Id == topArignInfo[i]).AssetName);
            top.GetComponent <MeshRenderer>().materials = mats;

            BoardIndex index  = new BoardIndex(i, GameDef.BOARD_CELLS);
            Vector2    tmpVec = board.GetBoardPosByIndex(index);
            top.transform.position = new Vector3(tmpVec.x, tmpVec.y, -6.85f);
            PrepareTopCtrl prepareTopCtrl = top.GetComponent <PrepareTopCtrl>();
            prepareTopCtrl.topId         = topArignInfo[i];
            prepareTopCtrl.movePermitFlg = false;
            prepareTopCtrl.SetTopIndex(index);
            board.SetBoardInf(topArignInfo[i], top, true, index);
        }

        /* カラーセルを配置する */
        for (int i = 1; i <= GameDef.BOARD_CELLS; i++)
        {
            for (int j = 1; j <= GameDef.BOARD_CELLS; j++)
            {
                BoardIndex index   = new BoardIndex(i, j);
                Vector2    tmpVal  = board.GetBoardPosByIndex(index);
                Vector3    tmpVal2 = new Vector3(tmpVal.x, tmpVal.y, -6.85f);

                //色付きセル(黄色、赤)を配置する
                GameObject redCell = Instantiate(redCellPref, tmpVal2, Quaternion.identity);
                redCellObj[i, j] = redCell;
                GameObject yellowCell = Instantiate(yellowCellPref, tmpVal2, Quaternion.identity);
                yellowCellObj[i, j] = yellowCell;

                //赤セルのみを少し下げておく
                redCellObj[i, j].transform.position = new Vector3(redCellObj[i, j].transform.position.x,
                                                                  redCellObj[i, j].transform.position.y,
                                                                  -6.0f);
            }
        }
    }