Exemple #1
0
        public static HangmanDifficulty CreateDifficulty()
        {
            var hdwHandler = new HangmanDifficultyWindow();

            hdwHandler.ShowDialog();

            return(hdwHandler._difficulty);
        }
        private void InitializeDifficultyComboBox()
        {
            foreach (var difficulty in HangmanDifficulty.List)
            {
                DifficultyComboBox.Items.Add(difficulty.Name);
            }

            DifficultyComboBox.Items.Add("Custom...");
            DifficultyComboBox.SelectedIndex = 0;
            _previousIndex = 0;

            DifficultyComboBox.SelectionChanged += (sender, args) =>
            {
                if (DifficultyComboBox.SelectedIndex == DifficultyComboBox.Items.Count - 1)
                {
                    var difficulty = HangmanDifficultyWindow.CreateDifficulty();
                    if (difficulty != null)
                    {
                        _previousIndex = DifficultyComboBox.SelectedIndex;

                        _hangmanHandler.Difficulty = difficulty;

                        HangmanDifficulty.List.Add(difficulty);

                        DifficultyComboBox.Items.RemoveAt(DifficultyComboBox.SelectedIndex);

                        DifficultyComboBox.Items.Add(difficulty.Name);
                        DifficultyComboBox.Items.Add("Custom...");

                        DifficultyComboBox.SelectedItem = difficulty.Name;
                    }
                    else
                    {
                        DifficultyComboBox.SelectedIndex = _previousIndex;
                    }
                }

                else
                {
                    _previousIndex = DifficultyComboBox.SelectedIndex;
                    foreach (var difficulty in HangmanDifficulty.List)
                    {
                        if (difficulty.Name == (string)DifficultyComboBox.SelectedValue)
                        {
                            _hangmanHandler.Difficulty = difficulty;
                        }
                    }
                }
                Console.WriteLine(_hangmanHandler.Difficulty.ToString());
            };
        }