Example #1
0
        public void OnShootClicked(object sender, EventArgs args)
        {
            //doesn't let the button go if nothing is selected
            if (SelectedButton == null)
            {
                return;
            }

            string compChoice = GetRandCompChoice();

            bool didCompTie = SelectedButton.Text == compChoice;
            bool didCompWin = DidYouLose(SelectedButton.Text, compChoice);

            if (didCompTie)
            {
                Title.Text = TIE_TEXT;
                DisplayAlert("Tie!", $"The computer chose {compChoice} too.", "Play again");
                SelectedButton.MarkTie();
            }
            else if (didCompWin)
            {
                Title.Text = LOSS_TEXT;
                DisplayAlert("You lost!", $"The computer chose {compChoice}. :'(", "Play again");
                SelectedButton.MarkLost();
            }
            else
            {
                Title.Text = WIN_TEXT;
                DisplayAlert("You won!", $"The computer chose {compChoice}. :D", "Play again");
                SelectedButton.MarkWon();
            }
            SelectedButton = null;
        }
Example #2
0
        public void OnChoiceClicked(object sender, EventArgs args)
        {
            GameButton clicked = (GameButton)sender;

            //deselects a currently selected button
            if (SelectedButton == clicked)
            {
                Title.Text = STARTING_TEXT;
                clicked.MarkInactive();
                SelectedButton = null;
                return;
            }

            //resets children's colors
            foreach (GameButton child in ButtonsGrid.Children)
            {
                child.MarkInactive();
            }

            clicked.MarkActive();
            Title.Text = ACTION_CHOSEN_TEXT;

            //to use in later references
            SelectedButton = clicked;
        }