Beispiel #1
0
        public bool GameStop()
        {
            RequestUpdateStop = true;

            TimerEnabled = !TimerEnabled;
            MeasuredTime = DateTime.Now - StartTime;

            CurrentRecord.RecordTime = MeasuredTime;

            RegisterUser RegisterWnd = new RegisterUser();

            RegisterWnd.Title      = "Result Registration";
            RegisterWnd.PlayerName = CurrentRecord.Name;
            //RegisterWnd.Message1.Content = string.Format("Your record is   {0} ({1} hits) => {2}", CurrentRecord.GetTimeAsText(), CurrentRecord.GetNumHit(), CurrentRecord.GetPenaltiedTimeAsText());
            RegisterWnd.Message1.Content = string.Format("あなたの記録は {0}", CurrentRecord.GetTimeAsText());
            int order, total;

            Records.GetRanking(CurrentRecord, out order, out total);
            //RegisterWnd.Message2.Content = string.Format("Ranking :  {0} out of {1}.", order + 1, total + 1);
            RegisterWnd.Message2.Content = string.Format("あなたは {1} 人中 {0} 位です!", order + 1, total + 1);
            if (RegisterWnd.ShowDialog() == true)
            {
                CurrentRecord.Name = RegisterWnd.PlayerName;
                Records.SaveAndAdd(CurrentRecord);
                CurrentRecord        = null;
                RequestUpdateRanking = true;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        public bool GameRegister()
        {
            if (TimerEnabled)
            {
                return(false);
            }

            CurrentRecord = new PlayRecord();
            RegisterUser RegisterWnd = new RegisterUser();

            RegisterWnd.Title            = "Player Registration";
            RegisterWnd.PlayerName       = CurrentRecord.Name;
            RegisterWnd.Message1.Content = "";
            RegisterWnd.Message2.Content = "";

            if (RegisterWnd.ShowDialog() == true)
            {
                CurrentRecord.Name = RegisterWnd.UserName.Text;
                return(true);
            }
            else
            {
                CurrentRecord = null;
                return(false);
            }
        }
Beispiel #3
0
 public void ReadFiles()
 {
     string[] files = System.IO.Directory.GetFiles(GetPath());
     foreach (string file in files)
     {
         string ext  = System.IO.Path.GetExtension(file);
         string name = System.IO.Path.GetFileNameWithoutExtension(file);
         if (ext == ".xml" && name.Substring(0, 6) == "record")
         {
             try
             {
                 using (System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open))
                 {
                     PlayRecord item = serializer.Deserialize(stream) as PlayRecord;
                     if (item == null)
                     {
                         item = new PlayRecord();
                     }
                     RecordSet.Add(item);
                 }
             }
             catch (Exception e)
             {
                 System.Windows.Forms.MessageBox.Show(e.ToString(), file);
                 return;
             }
         }
     }
 }
Beispiel #4
0
 public PlayRecord[] GetTopRanking(int count)
 {
     PlayRecord[] rank = new PlayRecord[count];
     PlayRecord[] list = RecordSet.ToArray();
     Array.Sort(list);
     for (int i = 0; i < count; i++)
     {
         rank[i] = list[i];
     }
     return(rank);
 }
Beispiel #5
0
 public void GetRanking(PlayRecord item, out int order, out int total)
 {
     order = 0;
     for (int i = 0; i < RecordSet.Count; i++)
     {
         if (RecordSet[i].CompareTo(item) < 0)
         {
             order++;
         }
     }
     total = RecordSet.Count;
 }
Beispiel #6
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException();
            }
            PlayRecord other = obj as PlayRecord;

            TimeSpan time1 = GetPenaltiedTime();
            TimeSpan time2 = other.GetPenaltiedTime();

            return((time1 < time2) ? -1 : 1);
        }
Beispiel #7
0
        public bool SaveAndAdd(PlayRecord item)
        {
            DateTime time     = DateTime.Now;
            string   filename = string.Format("record{0:0000}{1:00}{2:00}_{3:00}{4:00}{5:00}.xml", time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second);

            try
            {
                using (System.IO.FileStream stream = new System.IO.FileStream(GetPath() + filename, System.IO.FileMode.Create))
                {
                    serializer.Serialize(stream, item);
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString(), filename);
                return(false);
            }
            RecordSet.Add(item);
            return(true);
        }