コード例 #1
0
        private void btnChoice_Click(object sender, EventArgs e)
        {
            //Play click sound
            System.Media.SystemSounds.Exclamation.Play();
            //Get the user and computer choices and set them into their respective players
            Winner winner;

            playerUser.Choice     = ConvertIntegerToChoice(GetUserDecisionFromButton((Button)sender));
            playerComputer.Choice = ConvertIntegerToChoice(rGen.Next(1, 4));

            //Decide who the winner is
            if (playerUser.Choice == playerComputer.Choice)
            {
                winner = Winner.Draw;
            }
            else if (playerUser.Choice.CanBeat(playerComputer.Choice))
            {
                winner = Winner.User;
            }
            else
            {
                winner = Winner.Computer;
            }

            //Increment counters and display winner and stats
            playerUser.OnWinnerAnnounced(winner);
            playerComputer.OnWinnerAnnounced(winner);
            DisplayStats();
            DisplayWinner(winner);
        }