示例#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;
                }
            }
        }
    }
示例#3
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);
        }
    }
示例#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);
            }
        }
    }
 /// <summary>
 /// 盤面にコマを置く
 /// </summary>
 /// <param name="topId"></param>
 /// <param name="obj"></param>
 /// <param name="xIndex"></param>
 /// <param name="yIndex"></param>
 public void PutATop(int topId, GameObject obj, BoardIndex index)
 {
     board.SetBoardInf(topId, obj, true, index);
 }