Ejemplo n.º 1
0
        public void SaveToFile(BestTimes BestTime)
        {
            if (File.Exists(_Path))
            {
                File.Delete(_Path);
            }

            if (BestTime != null)
            {
                if (IsPlayerChangeTheRecord(BestTime.BestTime))
                {
                    _BestTimesList[Configuration.Configuration.GameConfiguration.Level].BestTime    = BestTime.BestTime;
                    _BestTimesList[Configuration.Configuration.GameConfiguration.Level].WinDateTime = BestTime.WinDateTime;
                    _BestTimesList[Configuration.Configuration.GameConfiguration.Level].WinnerName  = BestTime.WinnerName;
                }
            }


            try
            {
                MemoryStream    stream     = new MemoryStream();
                BinaryFormatter serializer = new BinaryFormatter();
                serializer.Serialize(stream, _BestTimesList);

                FileStream savedData = new FileStream(_Path, FileMode.Create, FileAccess.Write, FileShare.None);
                byte[]     buffer    = stream.ToArray();
                savedData.Write(buffer, 0, buffer.Length);

                stream.Close();
                savedData.Close();
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        private void Win(object sender, EventArgs e)
        {
            Smiley.IsHappy       = false;
            Smiley.IsGlassWeared = true;
            Smiley.IsSad         = false;

            if (dialogWin == null)
            {
                dialogWin = new WinnerName();
            }
            else
            {
                dialogWin = null;
                return;
            }

            dialogWin.ShowDialog();
            BestTimes newTime = new BestTimes();

            newTime.BestTime = GameTime.Value;

            if (dialogWin.UserNameText.Text.Length == 0)
            {
                newTime.WinnerName = "Anonymouse";
            }
            else
            {
                newTime.WinnerName = dialogWin.UserNameText.Text;
            }
            newTime.WinDateTime = DateTime.Now;

            BestTimeList.Statisticts.SaveToFile(newTime);
            GameBestTimes.PerformClick();
            GameNew.PerformClick();
        }
Ejemplo n.º 3
0
        private BestTimeList()
        {
            _Path          = "BestTime";
            _BestTimesList = new Dictionary <Configuration.GameLevel, BestTimes>();

            if (File.Exists(_Path))
            {
                this.LoadFromFile(_Path);
            }
            else
            {
                BestTimes tmp = new BestTimes {
                    BestTime = 0, WinnerName = "Anonymouse", WinDateTime = DateTime.Now
                };
                if (!_BestTimesList.ContainsKey(Configuration.GameLevel.Beginner))
                {
                    _BestTimesList.Add(Configuration.GameLevel.Beginner,
                                       new BestTimes {
                        BestTime = 0, WinnerName = "Anonymouse", WinDateTime = DateTime.Now
                    });
                }

                if (!_BestTimesList.ContainsKey(Configuration.GameLevel.Intermediate))
                {
                    _BestTimesList.Add(Configuration.GameLevel.Intermediate,
                                       new BestTimes {
                        BestTime = 0, WinnerName = "1", WinDateTime = DateTime.Now
                    });
                }

                if (!_BestTimesList.ContainsKey(Configuration.GameLevel.Advanced))
                {
                    _BestTimesList.Add(Configuration.GameLevel.Advanced,
                                       new BestTimes {
                        BestTime = 0, WinnerName = "2", WinDateTime = DateTime.Now
                    });
                }
                SaveToFile(null);
            }
        }