Ejemplo n.º 1
0
    //WWWManagerで接続成功後のデータを受け取る関数
    //サーバから取得した部屋情報を処理する
    void ReceiveRoomDataForJsonData(Dictionary <string, object> jsonData)
    {
        //部屋一覧をリセット
        Guide.AllDeleteFromTag(define.RoomListTag);
        var jsonAllRoomsData = (Dictionary <string, object>)jsonData["room_data"];      //取得した全部屋のDictionary
        //ソート
        //SortedDictionary<string,int> (new Comparer() )を使う?
        List <int> list = CreateSortRoomsList(jsonAllRoomsData);
        //ソートした順番に表示する
        int old_search_no = -1;        //直前のno 重複をなくす

        foreach (int search_no in list)
        {
            if (search_no == old_search_no)
            {
                continue;                //既に表示している
            }
            old_search_no = search_no;
            //全データからソートされた値と一致するデータを探す
            var roomData = FindRoomForNo(search_no, jsonAllRoomsData);
            if (roomData != null)
            {
                //部屋情報からボタンを作成し一覧に追加
                CreateRoomButtonForOneRoomData(roomData, search_no);
            }
        }
    }
Ejemplo n.º 2
0
    //GET
    //駒の状態を取得
    IEnumerator DownloadPiecesData()
    {
        string url = define.URL;

        if (loginDataManager.login_flag == false)
        {
            url = (define.URL + "get_pieces.json");            //test用
        }
        else
        {
            url += "plays/" + loginDataManager.play_id.ToString() + "/pieces";
        }
        WWW www = new WWW(url);

        //接続待ち
        yield return(www);

        if (www.error != null)
        {
            Debug.Log("Error!");
        }
        else
        {
            //接続成功
            Debug.Log("DOWNLOAD Piece Success");
            Debug.Log(www.text);
            Debug.Log(www.url);
            //JSON
            //1~40 駒のID
            var jsonAllPieceData = MiniJSON.Json.Deserialize(www.text) as Dictionary <string, object>;
            //初期化
            InitBoardPosArray();
            HavePiecesList.Clear();
            HavePiecesListEnemy.Clear();
            Guide.AllDeleteFromTag(define.LastMoverTag);            //最後に移動した駒表示ガイドを削除
            bool create_flag = false;
            //各駒の情報
            for (int i = 0; i < define.PieceNum; i++)
            {
                var jsonOnePieceData = (Dictionary <string, object>)jsonAllPieceData[(i + 1).ToString()];
                if (PiecesArrayID[i] == null)               //初めて呼ばれた時は作成する
                {
                    GameObject piece = CreatePiece();
                    PiecesArrayID[i] = piece;
                    create_flag      = true;
                }
                //コンポーネントの取得
                PieceBase comp = PiecesArrayID[i].GetComponent <PieceBase> ();
                //ID設定
                comp.SetID(i + 1);
                //位置設定
                int pos_x = System.Convert.ToInt32(jsonOnePieceData["posx"]);
                int pos_y = System.Convert.ToInt32(jsonOnePieceData["posy"]);
                if (create_flag == false)               //初期化時ではない
                {
                    //このターン移動した駒を判定
                    if (comp.board_pos_x != pos_x || comp.board_pos_y != pos_y)
                    {
                        comp.last_move_flag = true;
                    }
                    if (comp.last_move_flag == true)
                    {
                        Guide.CreateGuide(pos_x, pos_y, GuideKind.LAST_MOVER);
                        comp.SetBoardPos(pos_x, pos_y);
                        //駒をアニメーション移動
                        //持ち駒ではなく盤面にあるかチェック
                        if (BoardManager.CheckOutRangeBoardPointXY(pos_x, pos_y) == false)
                        {
                            comp.SetMoveTargetPos(pos_x, pos_y);
                            SetPieceMoveAnimStart(PiecesArrayID[i]);
                        }
                    }
                }
                else
                {
                    comp.SetLocalPos(pos_x, pos_y);
                }
                comp.last_move_flag = false;
                int user_id = loginDataManager.user_id;
                if (loginDataManager.login_flag == false)
                {
                    //test用
                    user_id = 5;
                }
                if (loginDataManager.watcher_flag == true)
                {
                    //観戦者なら先手視点
                    user_id = UserNameManager.GetInst().first_player_user_ID;
                }
                int owner_ID = System.Convert.ToInt32(jsonOnePieceData["owner"]);
                comp.owner_ID = owner_ID;
                if (owner_ID == user_id)
                {
                    //自軍
                    comp.SetEnemyFlag(false);
                }
                else
                {
                    //敵
                    comp.SetEnemyFlag(true);
                }
                //成り
                bool promote_flag = System.Convert.ToBoolean(jsonOnePieceData["promote"]);
                comp.SetPromote(promote_flag);
                //駒の名前と敵判定と成りの情報から種類を決定
                int kind = PieceKind.ChangeKindStringToint((string)jsonOnePieceData["name"]);
                comp.SetKind(kind);
                //盤面配列に記録
                if (BoardManager.CheckOutRangeBoardPointXY(pos_x, pos_y) == false)              //盤面上の駒なら 取った駒は座標0,0
                {
                    int tx = pos_x - 1;
                    int ty = pos_y - 1;
                    BoardPosArray[ty, tx] = PiecesArrayID[i];
                    comp.SetHaveFlag(false);                    //持ち駒ではなくす
                }
                else
                {
                    //盤面に無い駒は持ち駒とする
                    comp.SetHaveFlag(true);
                    if (comp.enemy_flag == true)
                    {
                        HavePiecesList.Add(PiecesArrayID[i]);
                    }
                    else
                    {
                        HavePiecesListEnemy.Add(PiecesArrayID[i]);
                    }
                }
            }
            //王手判定
            CheckOhte();
            Guide.AllGuideDelete();             //ガイド削除
            //持ち駒を並べる
            if (create_flag == true)
            {
                //最初はアニメーション移動あり 観戦者用
                UpdateHavePiece(true);
            }
            else
            {
                UpdateHavePiece(false);
            }
            //盤
            if (GameManager.GetInstance().first_player_flag == false)
            {
                //後手なら盤を180度回転させる
                board.transform.localEulerAngles = new Vector3(0, 0, 180.0f);
            }
            else
            {
                board.transform.localEulerAngles = new Vector3(0, 0, 0.0f);
            }
        }
    }