Esempio n. 1
0
    //勝者を取得
    IEnumerator DownloadWinner(string state)
    {
        //勝者を取得
        if (loginDataManager.play_id == -1)
        {
            yield break;
        }
        else
        {
            //駒の状態を取得						/plays/対戦ID/state
            string url = define.URL + "plays/" + loginDataManager.play_id + "/winner";
            WWW    www = new WWW(url);
            //接続待ち
            yield return(www);

            if (www.error != null)
            {
                Debug.Log("Error!");
            }
            else
            {
                //接続成功
                Debug.Log("DownloadWinner Success");
                //JSON
                var jsonData = MiniJSON.Json.Deserialize(www.text) as Dictionary <string, object>;
                winner_id = System.Convert.ToInt32(jsonData ["winner"]);
                if (winner_id == loginDataManager.user_id)
                {
                    winner_text.text = "あなたの勝利です";
                }
                else
                {
                    winner_text.text = UserNameManager.GetInst().GetUserNameForID(winner_id) + "の勝利です";
                }
                if (state == "exit")
                {
                    turn_player_text.text = "相手が退室しました";
                    if (loginDataManager.watcher_flag == true)
                    {
                        //相手が退室
                        int loser_id = -1;                        //退室したプレイヤーのID
                        if (winner_id == UserNameManager.GetInst().first_player_user_ID)
                        {
                            loser_id = UserNameManager.GetInst().last_player_user_ID;
                        }
                        else if (winner_id == UserNameManager.GetInst().last_player_user_ID)
                        {
                            loser_id = UserNameManager.GetInst().first_player_user_ID;
                        }
                        turn_player_text.text = UserNameManager.GetInst().GetUserNameForID(loser_id) + "が退室しました";
                    }
                }
            }
        }
    }
Esempio n. 2
0
    public string GetUserNameForID(int id)
    {
        string str = null;

        if (id == UserNameManager.GetInst().first_player_user_ID)
        {
            //先手
            str = UserNameManager.GetInst().first_player_user_name;
        }
        else
        {
            str = UserNameManager.GetInst().last_player_user_name;
        }
        return(str);
    }
Esempio n. 3
0
 public void SetIsTurnPlayerMe(bool b)
 {
     is_turn_plyer_me = b;
     //UIの更新
     if (b == true)
     {
         turn_player_text.text = "あなたのターンです";
     }
     else
     {
         turn_player_text.text = "相手のターンです";
     }
     if (loginDataManager.watcher_flag == true)
     {
         turn_player_text.text = UserNameManager.GetInst().GetUserNameForID(turn_player_id) + "のターンです";
     }
 }
Esempio n. 4
0
 // Use this for initialization
 void Start()
 {
     inst = this;        //作成時にインスタンスをスタティック変数に保持
 }
Esempio n. 5
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);
            }
        }
    }
Esempio n. 6
0
    //部屋の状態を取得
    IEnumerator DownloadPlayState()
    {
        if (loginDataManager.play_id == -1)
        {
            yield break;
        }
        else
        {
            //駒の状態を取得						/plays/対戦ID/state
            string url = define.URL + "plays/" + loginDataManager.play_id + "/state";
            WWW    www = new WWW(url);
            //接続待ち
            yield return(www);

            if (www.error != null)
            {
                Debug.Log("Error!");
            }
            else
            {
                //接続成功
                Debug.Log("DownloadPlayData Success");
                //JSON
                var    jsonData = MiniJSON.Json.Deserialize(www.text) as Dictionary <string, object>;
                string state    = (string)(jsonData ["state"]);
                if (state == "playing")
                {
                    battle_flag = true;
                    //名前の取得
                    UserNameManager.GetInst().ReceiveUserName();
                }
                else
                {
                    turn_player_text.text = state;
                    battle_flag           = false;
                    if (state == "exit")
                    {
                        //相手が退室
                        turn_player_text.text = "相手が退室しました";
                        if (loginDataManager.watcher_flag == true)
                        {
                            string lose_user_name = null;
                            if (winner_id == UserNameManager.GetInst().first_player_user_ID)
                            {
                                lose_user_name = UserNameManager.GetInst().last_player_user_name;
                            }
                            else if (winner_id == UserNameManager.GetInst().last_player_user_ID)
                            {
                                lose_user_name = UserNameManager.GetInst().first_player_user_name;
                            }
                            turn_player_text.text = lose_user_name + "が退室しました";
                        }
                        BattleEnd(state);
                    }
                    if (state == "finish")
                    {
                        //ゲーム終了
                        turn_player_text.text = "ゲーム終了です";
                        BattleEnd(state);
                    }
                }
            }
        }
    }