Exemple #1
0
        /// <summary>
        /// Display results of a round
        /// </summary>
        private void displayResults()
        {
            if (m_keyPressed.Count < 2)                     // Need to launch again
            {
                MessageBox.Show("Il y a eu une erreur, ou les deux joueurs n'ont pas joué, nous allons recommencer !", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
                initializeAndLaunch();                      // Relaunch
            }
            else                                            // Define only one key for each player
            {
                int i = 0;
                // We don't use the boolean anymore, let's reuse them
                Key joueur1_key = Key.A, joueur2_key = Key.A;   // Compilator oblige to initialize
                m_j1 = false; m_j2 = false;
                while (!(m_j1 && m_j2) && i < m_keyPressed.Count)
                {
                    if (m_keyPressed[i] == Key.Q || m_keyPressed[i] == Key.S || m_keyPressed[i] == Key.D)
                    {
                        joueur1_key = m_keyPressed[i];
                        m_j1        = true;
                    }
                    else if (m_keyPressed[i] == Key.K || m_keyPressed[i] == Key.L || m_keyPressed[i] == Key.M)
                    {
                        joueur2_key = m_keyPressed[i];
                        m_j2        = true;
                    }
                    i++;
                }                    // End while

                if (!(m_j1 && m_j2)) // If one of the players didn't play
                {
                    MessageBox.Show("Il y a eu une erreur (2), ou les deux joueurs n'ont pas joué, nous allons recommencer !", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
                    initializeAndLaunch();                  // Relaunch
                }
                else                                        // All is ok, go to results
                {
                    viewbox.Visibility     = Visibility.Hidden;
                    resultsGrid.Visibility = Visibility.Visible;

                    GameResultUserControl joueur1_UserControl = new GameResultUserControl(joueur1_key);
                    GameResultUserControl joueur2_UserControl = new GameResultUserControl(joueur2_key);

                    resultsGrid.Children.Add(joueur1_UserControl);
                    resultsGrid.Children.Add(joueur2_UserControl);

                    joueur1_UserControl.SetValue(Grid.RowProperty, 2);
                    joueur2_UserControl.SetValue(Grid.RowProperty, 2);

                    joueur1_UserControl.SetValue(Grid.ColumnProperty, 1);
                    joueur2_UserControl.SetValue(Grid.ColumnProperty, 3);

                    getWinner(joueur1_key, joueur2_key);    // Get who win ?
                }
            }
        }
        /// <summary>
        /// Display results of a round
        /// </summary>
        private void displayResults() {
            if (m_keyPressed.Count < 2) {                   // Need to launch again
                MessageBox.Show("Il y a eu une erreur, ou les deux joueurs n'ont pas joué, nous allons recommencer !", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
                initializeAndLaunch();                      // Relaunch
            }
            else {                                          // Define only one key for each player
                int i = 0;
                // We don't use the boolean anymore, let's reuse them
                Key joueur1_key = Key.A, joueur2_key = Key.A;   // Compilator oblige to initialize
                m_j1 = false; m_j2 = false;
                while (!(m_j1 && m_j2) && i < m_keyPressed.Count) {
                    if (m_keyPressed[i] == Key.Q || m_keyPressed[i] == Key.S || m_keyPressed[i] == Key.D) {
                        joueur1_key = m_keyPressed[i];
                        m_j1 = true;
                    }
                    else if (m_keyPressed[i] == Key.K || m_keyPressed[i] == Key.L || m_keyPressed[i] == Key.M) {
                        joueur2_key = m_keyPressed[i];
                        m_j2 = true;
                    }
                    i++;
                }   // End while

                if (!(m_j1 && m_j2)) {                      // If one of the players didn't play
                    MessageBox.Show("Il y a eu une erreur (2), ou les deux joueurs n'ont pas joué, nous allons recommencer !", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
                    initializeAndLaunch();                  // Relaunch
                }
                else {                                      // All is ok, go to results
                    viewbox.Visibility = Visibility.Hidden;
                    resultsGrid.Visibility = Visibility.Visible;

                    GameResultUserControl joueur1_UserControl = new GameResultUserControl(joueur1_key);
                    GameResultUserControl joueur2_UserControl = new GameResultUserControl(joueur2_key);

                    resultsGrid.Children.Add(joueur1_UserControl);
                    resultsGrid.Children.Add(joueur2_UserControl);

                    joueur1_UserControl.SetValue(Grid.RowProperty, 2);
                    joueur2_UserControl.SetValue(Grid.RowProperty, 2);

                    joueur1_UserControl.SetValue(Grid.ColumnProperty, 1);
                    joueur2_UserControl.SetValue(Grid.ColumnProperty, 3);

                    getWinner(joueur1_key, joueur2_key);    // Get who win ?
                }
            }
        }