public void SaveBoardToProperties()
    {
        Hashtable boardProps = board.GetBoardAsCustomProperties();

        boardProps.Add("pt", this.PlayerIdToMakeThisTurn);  // "pt" is for "player turn" and contains the ID/actorNumber of the player who's turn it is
        boardProps.Add("t#", this.TurnNumber);
        boardProps.Add("tx#", board.TilesX);
        boardProps.Add("ty#", board.TilesY);
        boardProps.Add(GetPlayerPointsPropKey(this.LocalPlayer.ID), this.MyPoints); // we always only save "our" points. this will not affect the opponent's score.


        // our turn will be over if 2 tiles are clicked/flipped but not the same. in that case, we update the other player if inactive
        bool webForwardToPush = false;

        if (board.AreTwoTilesFlipped() && !board.AreTheSameTilesFlipped())
        {
            Player otherPlayer = this.Opponent;
            if (otherPlayer != null)
            {
                boardProps.Add(PropTurn, otherPlayer.ID); // used to identify which player's turn the NEXT is. the WebHooks might send a PushMessage to that user.
                if (otherPlayer.IsInactive)
                {
                    webForwardToPush = true;            // this will send the props to the WebHooks, which in turn will push a message to the other player.
                }
            }
        }


        //Debug.Log(string.Format("saved board to room-props {0}", SupportClass.DictionaryToString(boardProps)));
        this.OpSetCustomPropertiesOfRoom(boardProps, webForwardToPush);
    }
Exemple #2
0
    private void UpdateInGameTexts()
    {
        if (this.GameClientInstance == null || this.GameClientInstance.State != ClientState.Joined)
        {
            return;
        }

        if (this.GameClientInstance.CurrentRoom != null)
        {
            GUIText pointsGuiText = this.InGameScoresText.guiText;

            Player other = this.GameClientInstance.Opponent;
            if (other == null)
            {
                pointsGuiText.text = string.Format("");
            }
            else
            {
                pointsGuiText.text = string.Format("you: {0} {2}: {1}", this.GameClientInstance.MyPoints, this.GameClientInstance.OthersPoints, other.Name);
            }
        }


        string     theText = null;
        GameObject txt     = this.InGameInfoText;

        if (this.GameClientInstance.GameWasAbandoned)
        {
            theText = "Your opponent left for good.";
        }
        else if (!this.GameClientInstance.GameCanStart)
        {
            theText = "Please wait for opponent.";
        }
        else if (board.IsBoardEmpty)
        {
            if (this.GameClientInstance.IsMyScoreHigher)
            {
                theText = "Game completed. You won!!";
            }
            else if (this.GameClientInstance.IsScoreTheSame)
            {
                theText = "Game completed. It's a draw!";
            }
            else
            {
                theText = "Game completed. You lost.";
            }
        }
        else if (this.GameClientInstance.IsMyTurn)
        {
            if (!board.IsOneTileFlipped())
            {
                theText = "Your Turn. Pick 1st Tile.";
            }

            if (board.AreTwoTilesFlipped())
            {
                if (board.AreTheSameTilesFlipped())
                {
                    theText = "Yay! Matching Tiles!";
                }
                else
                {
                    theText = "Sorry. No Match. End of Turn.";
                }
            }
            else if (board.IsOneTileFlipped())
            {
                theText = "Your Turn. Pick 2nd Tile.";
            }
        }
        else
        {
            theText = "Other's Turn. Please wait.";
        }

        if (string.IsNullOrEmpty(theText))
        {
            txt.guiText.enabled = false;
        }
        else
        {
            txt.guiText.enabled = true;
            txt.guiText.text    = theText;
        }
    }