public static MoveMessage buildMessage(byte[] update)
 {
     JObject jsonObj = JObject.Parse(System.Text.Encoding.UTF8.GetString(update, 0, update.Length));
     MoveMessage msg = new MoveMessage();
     msg.sender = jsonObj["sender"].ToString();
     msg.type = jsonObj["type"].ToString();
     if(msg.type == "move")
     {
         msg.TextBoxName = jsonObj["TextBoxName"].ToString();
         msg.piece = jsonObj["piece"].ToString();
     }
     return msg;
 }
        /// <summary>
        /// Play the selected piece.
        /// </summary>
        /// <param name="tbTapped">The (TextBlock) that was played</param>
        private void Play(TextBlock tbTapped, MoveMessage msg)
        {
            // Make sure the status text is clear, because if we update the status message we want the
            // user to notice it
            tbStatus.Text = String.Empty;

            // The user can tap on the gameboard without clicking "New Game". In this case we may
            // need to initialize the board if it has not been initialized already.
            // Initialization is signified by the _pieceMap not being null.
            if (_pieceMap == null)
                InitializeBoard();

            // Set the square to the user's gamepiece
            tbTapped.Text = msg.piece;

            // Record the updated value for that square
            _pieceMap[tbTapped.Name] = tbTapped.Text;

            // Based on the above move, it is possible that the game has been won
            if (SomebodyWon)
            {
                GameOver();
            }
            else
            {
                /// Is there still a piece for the Opponent to play?
                if (PiecesAvailable())
                {
                    if (msg.sender != GlobalContext.localUsername)
                    {
                        UpdateStatus("Your turn!");
                    }
                }
                else
                {
                    // Nobody wins - end the game
                    GameOver();
                    UpdateStatus("Nobody Won!");
                }

            }
        }
 internal void UpdateUiFromMove(MoveMessage msg)
 {
     TextBlock tb = (TextBlock)gBoard.FindName(msg.TextBoxName);
     Play(tb, msg);
     moveCount++;
     UnLockGameboard();
 }