Exemplo n.º 1
0
        public EndGameDialog(IWheel wheel)
        {
            InitializeComponent();
            lbl_Outcome.Text =
                $@"{wheel.GetCurrentPlayer()} successfully solved the phrase:""{wheel.GetCurrentPhrase()}""";

            var sortedPlayers = wheel.GetAllPlayers().ToList().OrderByDescending(p => p.Score).ToList();

            for (int i = 1; i <= sortedPlayers.Count; i++)
            {
                switch (i)
                {
                case 1:
                    lbl_Player1.Text    = $@"Winner: {sortedPlayers[i-1]} - {sortedPlayers[i-1].Score:C0}";
                    lbl_Player1.Visible = true;
                    break;

                case 2:
                    lbl_Player2.Text    = $@"2nd Place: {sortedPlayers[i-1]} - {sortedPlayers[i-1].Score:C0}";
                    lbl_Player2.Visible = true;
                    break;

                case 3:
                    lbl_Player3.Text    = $@"3rd Place: {sortedPlayers[i-1]} - {sortedPlayers[i-1].Score:C0}";
                    lbl_Player3.Visible = true;
                    break;

                case 4:
                    lbl_Player4.Text    = $@"4th Place: {sortedPlayers[i-1]} - {sortedPlayers[i-1].Score:C0}";
                    lbl_Player4.Visible = true;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        /*
         *                                                                                      ,,   ,,
         * `7MM"""YMM                             mm       `7MMF'  `7MMF'                        `7MM `7MM
         * MM    `7                             MM         MM      MM                            MM   MM
         * MM   d `7M'   `MF'.gP"Ya `7MMpMMMb.mmMMmm       MM      MM   ,6"Yb. `7MMpMMMb.   ,M""bMM   MM  .gP"Ya `7Mb,od8 ,pP"Ybd
         * MMmmMM   VA   ,V ,M'   Yb  MM    MM  MM         MMmmmmmmMM  8)   MM   MM    MM ,AP    MM   MM ,M'   Yb  MM' "' 8I   `"
         * MM   Y  , VA ,V  8M""""""  MM    MM  MM         MM      MM   ,pm9MM   MM    MM 8MI    MM   MM 8M""""""  MM     `YMMMa.
         * MM     ,M  VVV   YM.    ,  MM    MM  MM         MM      MM  8M   MM   MM    MM `Mb    MM   MM YM.    ,  MM     L.   I8
         * .JMMmmmmMMM   W     `Mbmmd'.JMML  JMML.`Mbmo    .JMML.  .JMML.`Moo9^Yo.JMML  JMML.`Wbmd"MML.JMML.`Mbmmd'.JMML.   M9mmmP'
         */

        /// <summary>
        /// Button event handler to send a request for the user to join the game
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_join_Click(object sender, EventArgs e)
        {
            try
            {
                // Create the channel
                DuplexChannelFactory <IWheel> channel = new DuplexChannelFactory <IWheel>(this, "WheelService");
                wheel = channel.CreateChannel();
                // if the user is added update ui
                if (wheel.AddPlayer(textBox_UserName.Text, out user))
                {
                    players = wheel.GetAllPlayers().ToList();
                    UpdatePlayers();
                    button_join.Enabled = false;
                }
                // otherwise show an error message
                else
                {
                    if (wheel.GetAllPlayers().Length == MAX_PLAYERS)
                    {
                        MessageBox.Show(@"ERROR: No room for any additional players");
                    }
                    else if (wheel.GameStarted())
                    {
                        MessageBox.Show(@"ERROR: Game in progress. Please try again later.");
                    }
                    else
                    {
                        MessageBox.Show(@"ERROR: Alias in use. Please try again.");
                    }
                    // Alias rejected by the service so nullify service proxies
                    wheel = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Callback method that updates the players UI and declares a winner if applicable
 /// </summary>
 /// <param name="messages">Contains updated player info</param>
 public void PlayersUpdated(Player[] messages)
 {
     if (thread.Thread == System.Threading.Thread.CurrentThread)
     {
         try
         {
             // If game is over
             if (wheel.GameOver())
             {
                 try
                 {
                     if (endDialog != null)
                     {
                         return;
                     }
                     int    playerCount = wheel.GetAllPlayers().Length;
                     Player winner;
                     if (playerCount == 0)
                     {
                         return;
                     }
                     else if (playerCount == 1)
                     {
                         winner = wheel.GetAllPlayers()[0];
                     }
                     else
                     {
                         winner = wheel.GetAllPlayers().OrderByDescending(p => p.Score).FirstOrDefault();
                     }
                     winnerSound.Play();
                     endDialog = new EndGameDialog(wheel);
                     endDialog.ShowDialog(this);
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show($@"Error getting winner: {ex.Message}");
                 }
                 wheel.LeaveGame();
                 Close();
                 return;
             }
             // if the wheel is spinning do not update the current player
             // otherwise the GUI will attempt to make additional threads and display errors
             if (!isSpinning)
             {
                 GetCurrentPlayer();
             }
             players = messages.ToList();
             UpdatePlayerScores();
             lbl_PuzzleDisplay.Text = wheel.GetCurrentState();
             btn_answer.Enabled     = isUsersTurn;
             UpdateLetters();
             Refresh();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else
     {
         this.BeginInvoke(new GuiUpdateDelegate(this.PlayersUpdated), new object[] { messages });
     }
 }