Пример #1
0
 /// <summary>
 /// Constructor of form
 /// </summary>
 /// <param name="profile">Game profile for write information</param>
 /// <param name="locale">Locale</param>
 public NewProfile(GameProfile profile, Locale locale)
 {
     this.profile = profile;
     this.locale  = locale;
     InitializeComponent();
     SetLocale(locale);
     ButtonCreateProfile.Enabled = false;
 }
Пример #2
0
        /// <summary>
        /// Save game result in score method
        /// </summary>
        /// <param name="profile">Game profile</param>
        /// <param name="locale">Locale</param>
        public static void SaveGameResultInScore(GameProfile profile, Locale locale)
        {
            profile.PlayerLocale = locale.Localization;
            var saveResult = SaveLoadProfile.Save(profile);

            if (saveResult.IsError)
            {
                MessageBox.Show(locale.GetSavesSavingErrorText(), locale.GetErrorText());
            }
        }
Пример #3
0
 /// <summary>
 /// Save profile method
 /// </summary>
 /// <param name="profile">Game profile</param>
 /// <returns>Result of save profile</returns>
 private static ProfileActionResult SaveProfile(GameProfile profile)
 {
     try
     {
         return(SaveFileStream(profile));
     }
     catch (Exception)
     {
         return(GetFaultedResult());
     }
 }
Пример #4
0
 /// <summary>
 /// Show score method
 /// </summary>
 /// <param name="profile">Game profile</param>
 /// <param name="locale">Locale</param>
 public static void ShowScore(GameProfile profile, Locale locale)
 {
     MessageBox.Show($"{locale.GetProfileText()}: {profile.PlayerName}\n\n\n" +
                     $"-------{locale.GetLowDifficultText()}-------\n" +
                     $"{locale.GetWinsCountText()}: {profile.LowLevelScore.Win}\n" +
                     $"{locale.GetLosesCountText()}: {profile.LowLevelScore.Lose}\n" +
                     $"{locale.GetDrawCountText()}: {profile.LowLevelScore.Draw}\n\n" +
                     $"-------{locale.GetHardDifficultText()}-------\n" +
                     $"{locale.GetWinsCountText()}: {profile.HardLevelScore.Win}\n" +
                     $"{locale.GetLosesCountText()}: {profile.HardLevelScore.Lose}\n" +
                     $"{locale.GetDrawCountText()}: {profile.HardLevelScore.Draw}\n",
                     locale.GetScoreMenuText());
 }
Пример #5
0
        /// <summary>
        /// Save file stream method
        /// </summary>
        /// <param name="profile">Game profile</param>
        /// <returns>Result of save file stream</returns>
        private static ProfileActionResult SaveFileStream(GameProfile profile)
        {
            //XmlSerializer formatter = new XmlSerializer(typeof(GameProfile));
            BinaryFormatter     formatter    = new BinaryFormatter();
            ProfileActionResult actionResult = new ProfileActionResult();

            using (FileStream fs = new FileStream(GetFileSavePath(), FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, profile);
                actionResult.IsError = false;
            }
            return(actionResult);
        }
Пример #6
0
        /// <summary>
        /// Main form load event method
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event</param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (!SaveLoadProfile.CheckExistFileSave())
            {
#pragma warning disable IDE0067 // Dispose objects before losing scope
                NewProfile addUserForm = new NewProfile(profile, locale);
#pragma warning restore IDE0067 // Dispose objects before losing scope
                addUserForm.ShowDialog();
                if (!GameDataBus.ProfileIsCreated)
                {
                    Close();
                    return;
                }
                profile = GameDataBus.TempProfile;
            }
            else
            {
                profile = GameDataBus.LoadGameResultInScore(locale);
            }

            locale = CreateLocale(profile.PlayerLocale);
            SetLocale(locale);
            SetLanguageFlags(locale.Localization);
        }
Пример #7
0
 /// <summary>
 /// Save to file method
 /// </summary>
 /// <param name="profile">Game profile</param>
 public static ProfileActionResult Save(GameProfile profile)
 {
     return(SaveProfile(profile));
 }