Ejemplo n.º 1
0
 public MineField(FieldConfiguration config)
 {
     CurrentConfiguration = config;
     initializing         = true;
     BorderStyle          = BorderStyle.Fixed3D;
     Rows             = CurrentConfiguration.Height;
     Columns          = CurrentConfiguration.Width;
     GameState        = MinesweeperGameState.Unknown;
     RemainingSquares = Rows * Columns;
     RemainingBombs   = CurrentConfiguration.MinesCount;
     initializing     = false;
 }
        public static bool NewHighscoreReached(FieldConfiguration config, int currentScore)
        {
            bool newHighscoreReached = false;

            KeyValuePair <int, string> currentHighscore = GetHighscoreByConfigName(config);

            if (!string.IsNullOrEmpty(currentHighscore.Value))
            {
                newHighscoreReached = currentScore < currentHighscore.Key && currentScore > 0 && currentScore <= 999;
            }

            return(newHighscoreReached);
        }
Ejemplo n.º 3
0
        protected void UpdateSelectorValues(string activeConfigName)
        {
            FieldConfiguration config = FieldConfiguration.GetConfigurationByName(activeConfigName);

            if (config != null)
            {
                widthSelectionTextBox.Text  = config.Width.ToString();
                heightSelectionTextBox.Text = config.Height.ToString();
                minesSelectionTextBox.Text  = config.MinesCount.ToString();
            }
            else
            {
                widthSelectionTextBox.Text  = ConfigurationManager.CustomConfigWidth.ToString();
                heightSelectionTextBox.Text = ConfigurationManager.CustomConfigHeight.ToString();
                minesSelectionTextBox.Text  = ConfigurationManager.CustomConfigBombs.ToString();
            }
        }
        private static string GetPlayerNameOnNewHighScore(FieldConfiguration activeConfig, int currentScore, IWin32Window invoker)
        {
            string result = null;

            if (NewHighscoreReached(activeConfig, currentScore))
            {
                using (HighscoresForm highscoreSelectionForm = new HighscoresForm(activeConfig, currentScore))
                {
                    highscoreSelectionForm.ShowDialog(invoker);
                    result = highscoreSelectionForm.PlayerName;
                    if (string.IsNullOrEmpty(result))
                    {
                        result = "Anonymous";
                    }
                }
            }
            return(result);
        }
        public static void TrySetPlayerNameOnNewHighscore(FieldConfiguration activeConfig, int currentScore, IWin32Window invoker)
        {
            string playerName = GetPlayerNameOnNewHighScore(activeConfig, currentScore, invoker);

            if (playerName != null)
            {
                KeyValuePair <int, string> newHighscore = new KeyValuePair <int, string>(currentScore, playerName);
                if (activeConfig.ConfigurationName == FieldConfiguration.BeginnerConfigString)
                {
                    HighscoreBeginner = newHighscore;
                }
                else if (activeConfig.ConfigurationName == FieldConfiguration.IntermediateConfigString)
                {
                    HighscoreIntermediate = newHighscore;
                }
                else if (activeConfig.ConfigurationName == FieldConfiguration.AdvancedConfigString)
                {
                    HighscoreAdvanced = newHighscore;
                }
            }
        }
Ejemplo n.º 6
0
        protected void OnPresetComboBoxSelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox comboBoxSender = sender as ComboBox;

            if (comboBoxSender != null)
            {
                string selectedConfig = comboBoxSender.SelectedItem.ToString();
                if (selectedConfig.CompareTo(FieldConfiguration.CustomConfigString) != 0)
                {
                    DisableCustomSelectors();
                }
                else
                {
                    EnableCustomSelectors();
                }
                UpdateSelectorValues(comboBoxSender.SelectedItem.ToString());
                SelectedConfig = FieldConfiguration.GetConfigurationByName(selectedConfig);
                if (SelectedConfig == null)
                {
                    SelectedConfig = new FieldConfiguration(this.widthSelectionTextBox.Text, this.heightSelectionTextBox.Text, this.minesSelectionTextBox.Text);
                }
            }
        }
 public static KeyValuePair <int, string> GetHighscoreByConfigName(FieldConfiguration config)
 {
     return(GetHighscoreByConfigName(config.ConfigurationName));
 }