public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            client = MobileServiceHelper.DefaultService;

            // Set the URL textbox and Key textbox to contain the default URL and Key.
            URLText.Text = client.applicationURL;
            KeyText.Text = client.applicationKey;
        }
Exemple #2
0
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();

            MoveResponse aMove;

            // Perform any additional setup after loading the view, typically from a nib.
            client = MobileServiceHelper.DefaultService;
            // Initial the board to be all empty.
            TicBoard = new string[10];
            for (int i = 0; i <= 9; i++)
            {
                TicBoard[i] = "?";
            }

            // If backend plays first.
            if (serviceSymbol == "X")
            {
                SecondPiece.Text      = humanSymbol;
                SecondLabel.Text      = "Human";
                SecondLabel.TextColor = UIColor.Yellow;
                FirstPiece.Text       = serviceSymbol;
                FirstLabel.Text       = "Azure";
                FirstLabel.TextColor  = UIColor.Blue;
                FirstLabel2.Text      = serviceImple;
                FirstLabel2.TextColor = serviceColor;

                try {
                    // Show backend game piece label before requesting move.
                    ShowServicePiece();
                    aMove = await CallAPIPost(TicBoard);

                    // Set the output string to the response for debugging purpose.
                    OutputLabel.Text = aMove.ToString();

                    // If the response contains a move, then perform it.
                    if (aMove.hasMove)
                    {
                        MakeServiceMove(aMove.getMoveNumber(), serviceSymbol);
                    }
                    // After the move, show human game piece label.
                    ShowHumanPiece();
                } catch (Exception ex) {
                    // Display the exception message.
                    OutputLabel.Text            = "";
                    StatusLabel.Text            = ex.Message;
                    StatusLabel.BackgroundColor = UIColor.Red;
                }
            }
            // If human plays first.
            else
            {
                SecondPiece.Text       = serviceSymbol;
                SecondLabel.Text       = "Azure";
                SecondLabel.TextColor  = UIColor.Blue;
                SecondLabel2.Text      = serviceImple;
                SecondLabel2.TextColor = serviceColor;
                FirstPiece.Text        = humanSymbol;
                FirstLabel.Text        = "Human";
                FirstLabel.TextColor   = UIColor.Yellow;

                ShowHumanPiece();
            }
        }