Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        //Firebase.Database.DataSnapshot snapshot = null;
        switch (stateNo)
        {
        case (int)PlayerState.SetUp:

            if (myDB.SnapData == null)
            {
                return;
            }

            handCards.allFront = isPlayable;
            heartBox.allFront  = true;
            DownloadMyHandDB(myDB.SnapData);
            myDB.RemoveReadData();
            if (handCards.Count == 0)
            {
                myDB.ReadQuery(handDBname);
                return;
            }
            Debug.Log("read!");

            PrepareNewPlay();
            stateNo = (int)PlayerState.Idle;
            break;

        case (int)PlayerState.BeginMyPhase:
            if (isPlayable)
            {
                GetSelectableIndexes();
                handCards.Highlight(selectableIndexes);
                handCards.EmphasizeOne(selectableIndexes[selectIndex]);
            }
            else
            {
                myDB.ReadQuery(selectDBname);
            }
            stateNo = (int)PlayerState.MyPhase;
            break;

        case (int)PlayerState.MyPhase:
            if (isPlayable)
            {
                if (SelectCard())
                {
                    stateNo = (int)PlayerState.EndMyPhase;
                    myDB.AddAsync(selectDBname, selectableIndexes[selectIndex]);
                    myDB.Push(queryCountDBname, master.ClientNo.ToString());
                    myDB.ReadQuery(queryCountDBname);
                }
            }
            else
            {
                if (myDB.SnapData == null)
                {
                    return;
                }
                if (int.Parse(myDB.SnapData.GetRawJsonValue()) == -1)
                {
                    myDB.ReadQuery(selectDBname);
                }
                else
                {
                    stateNo = (int)PlayerState.EndMyPhase;
                    handCards.MoveTo(ref fieldBox,
                                     int.Parse(myDB.SnapData.GetRawJsonValue()));
                    fieldBox.ListView();
                    handCards.ListView();
                    myDB.Push(queryCountDBname, master.ClientNo.ToString());
                    myDB.ReadQuery(selectDBname);
                }
                myDB.RemoveReadData();
            }
            break;

        case (int)PlayerState.EndMyPhase:
            //return;
            if (myDB.SnapData == null)
            {
                return;
            }
            if (isPlayable)
            {
                if (myDB.SnapData.ChildrenCount < master.PlayerCnt)
                {
                    myDB.ReadQuery(queryCountDBname);
                }
                else
                {
                    selectIndex = 0;
                    Debug.Log("idle");
                    stateNo = (int)PlayerState.Idle;
                    myDB.AddAsync(selectDBname, -1);
                    Debug.Log(myDB.SnapData.ChildrenCount);
                }
            }
            else
            {
                if (int.Parse(myDB.SnapData.GetRawJsonValue()) != -1)
                {
                    myDB.ReadQuery(selectDBname);
                }
                else
                {
                    stateNo = (int)PlayerState.Idle;
                }
            }
            myDB.RemoveReadData();
            break;

        case (int)PlayerState.Idle:

            break;
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        switch (stateNo)
        {
        case (int)KeeperState.NameReception:
            playerName = textFielder.GetMessage();
            if (playerName == null || playerName.Length > nameMaxLength)
            {
                return;
            }

            stateNo = (int)KeeperState.RoomReception;
            textFielder.StartCoroutine(textFielder.SwitchDialog(true, string.Format(
                                                                    "OK、" + playerName
                                                                    + "さん。プレイしたい部屋はどこだい。({0}文字以内)",
                                                                    nameMaxLength)));
            textFielder.CleanInputField("部屋名を入力してね", "TestRoom");
            break;

        case (int)KeeperState.RoomReception:
            roomName = textFielder.GetMessage();
            if (roomName == null || roomName.Length > nameMaxLength)
            {
                return;
            }
            Debug.Log(roomName);
            //connector.ReadQuery(roomName + "/" + playersDir, true);
            connector.ReadQuery(roomName, true);    //直下読み込み
            stateNo = (int)KeeperState.Inquiry;
            textFielder.StartCoroutine(textFielder.SwitchDialog(true,
                                                                "問い合わせ中..."));
            break;

        case (int)KeeperState.Inquiry:
            if (connector.SnapData == null)
            {
                return;
            }

            if (connector.SnapData.Value == null)
            {
                MakeRoom();
                playerNo   = 0;
                roomParent = true;
                stateNo    = (int)KeeperState.Wanting;
                connector.AddAsync(roomName + "/" + roomStateDir, (int)RoomState.Wanting);
            }
            else if (connector.SnapData.Child(playersDir).ChildrenCount
                     >= GameMaster.maxPlayers ||
                     connector.SnapData.Child(roomStateDir).GetRawJsonValue().Equals("1"))
            {
                textFielder.StartCoroutine(textFielder.SwitchDialog(true, string.Format(
                                                                        "おっと、そこは満席みたいだな。他の部屋はどうだい。({0}文字以内)",
                                                                        nameMaxLength)));
                textFielder.CleanInputField("部屋名を入力してね", roomName);
                stateNo = (int)KeeperState.RoomReception;
                connector.RemoveReadData();
                return;
            }
            else
            {
                EnterRoom();
                playerNo   = (int)connector.SnapData.Child(playersDir).ChildrenCount;
                roomParent = false;
                stateNo    = (int)KeeperState.PlayWaiting;
            }

            connector.RemoveReadData();
            connector.AddAsync(roomName + "/" + playersDir + "/" + playerNo.ToString(),
                               playerName);
            break;

        case (int)KeeperState.Wanting:
            string command = textFielder.GetMessage();
            if (!onReady)
            {
                return;
            }
            if ((command == null || !command.Equals("S")) &&
                !Input.GetKeyDown(KeyCode.S))
            {
                return;
            }

            connector.AddAsync(roomName + "/" + roomStateDir, (int)RoomState.Playing);
            stateNo = (int)KeeperState.SetupGameMaster;
            break;

        case (int)KeeperState.SetupGameMaster:
            if (playerNameArray.Length > GameMaster.maxPlayers)
            {
                playerNameArray = playerNameArray.Take(GameMaster.maxPlayers).ToArray();
            }
            master.InitializeDB(nowPlayerCnt, roomParent, playerNameArray, playerNo,
                                connector.MyReference.Child(roomName + "/Master"));
            stateNo = (int)KeeperState.Idle;
            connector.MyReference.Child(roomName + "/" + playersDir).ChildRemoved
                += (object sender, Firebase.Database.ChildChangedEventArgs args) =>
                {
                if (stateNo != (int)KeeperState.Idle)
                {
                    return;
                }

                InterruptGame();
                };
            textFielder.StartCoroutine(textFielder.SwitchDialog(false));
            textFielder.CleanInputField("メッセージ", "");
            break;
        }
    }