Exemplo n.º 1
0
 public void InitializeDB(int no, bool playable, string name,
                          Firebase.Database.DatabaseReference playerReference)
 {
     myNo          = no;
     isPlayable    = playable;
     myName        = name;
     myDB          = new FirebaseConnector(playerReference, !playable);
     nameText.text = name;
     if (isPlayable)
     {
         Debug.Log("playable!");
         myDB.AddAsync("Name", myName);
         myDB.AddAsync(selectDBname, -1);
     }
     transform.Find("Chatter").GetComponent <Chatter>().InitializeChatDB(
         playerReference.Child("Chat"), playable);
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (!isPlayable)
        {
            return;
        }

        message = fielder.GetMessage();
        if (message == null || message.Equals(""))
        {
            return;
        }

        //SendMessageBox(message);
        SendMessageBox2(message);
        connector.AddAsync(messageKey, message);
        fielder.CleanInputField("メッセージ", "");
    }
Exemplo n.º 3
0
    void ServeCards(bool randomSelect)
    {
        FirebaseConnector tempConnector = new FirebaseConnector(connector.MyReference.Parent);

        trickLimit = deckCards.Count / playerCnt;
        for (int i = 0; i < playerCnt; i++)
        {
            Dictionary <string, object> cardDict = new Dictionary <string, object>();
            for (int j = 0; j < trickLimit; j++)
            {
                int index = Random.Range(0, deckCards.Count);
                cardDict.Add(Card.dbName + j.ToString(), deckCards[index].DataDictionary());
                deckCards.RemoveAt(index);
            }

            tempConnector.AddAsync(string.Format("Player{0}/{1}", i, GamePlayer.handDBname),
                                   cardDict);
        }
    }
Exemplo n.º 4
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;
        }
    }
Exemplo n.º 5
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;
        }
    }