Ejemplo n.º 1
0
 public RankingList(TetrisSave current, bool isHighTime) : this(current)
 {
     if (isHighTime)
     {
         tctlList.SelectedTab = ppTimeList;
     }
 }
Ejemplo n.º 2
0
        private void OnGameOver()
        {
            Game.Over();
            GameTimer.Enabled = false;

            TetrisSave test;

            if (Game.Score > Game.Score2)
            {
                test = new TetrisSave("---", Game.Score, DateTime.Now - Game.GameStarted);//////////////////////
            }
            else//Game.Score<=Game.Score2
            {
                test = new TetrisSave("---", Game.Score2, DateTime.Now - Game.GameStarted);//////////////////////
            }

            if (Saver.HighScores.CanAdd(test) || Saver.HighTimes.CanAdd(test))
            {
                NRDialog = new NewRecordDialog();
                if (NRDialog.ShowDialog() == DialogResult.OK)
                {
                    test.UserName = NRDialog.UserName;
                    Saver.Save(test);

                    RForm = new RecordsForm(test);
                    if (RForm.ShowDialog() == DialogResult.OK)
                    {
                        NewGame();
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public RecordsForm(TetrisSave current, bool isHighTime) : this(current)
 {
     if (isHighTime)
     {
         ListsTabControl.SelectedTab = TimesTabPage;
     }
 }
Ejemplo n.º 4
0
        private void OnGameOver()
        {
            tetrisGame.Over();
            tmrGame.Enabled = false;

            TetrisSave test = new TetrisSave("---", tetrisGame.Score, DateTime.Now - tetrisGame.GameStarted);

            //判断是否可以上榜
            if (Saver.highScores.CanAdd(test) || Saver.highTimes.CanAdd(test))
            {
                newRecordDialog = new NewRecord();
                if (newRecordDialog.ShowDialog() == DialogResult.OK)
                {
                    //存档
                    test.UserName = newRecordDialog.UserName;
                    Saver.Save(test);

                    //打开排行榜
                    rankingList = new RankingList(test);
                    if (rankingList.ShowDialog() == DialogResult.OK)
                    {
                        NewGame();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public override bool Equals(object obj)
        {
            TetrisSave tetrisSave = (TetrisSave)obj;

            return(UserName == tetrisSave.UserName &&
                   GameDuration == tetrisSave.GameDuration &&
                   Score == tetrisSave.Score);
        }
Ejemplo n.º 6
0
 public SavesList()
 {
     Saves = new TetrisSave[10];
     for (int i = 0; i < 10; i++)
     {
         Saves[i]           = new TetrisSave("---", 0, new TimeSpan(0));
         Saves[i].UserName  = "******";
         Saves[i].GameEnded = new DateTime(0);
     }
 }
Ejemplo n.º 7
0
        private void OnGameOver()
        {
            Game.Over();
            GameTimer.Enabled = false;

            TetrisSave test = new TetrisSave("---", Game.Score, DateTime.Now - Game.GameStarted);

            if (Saver.HighScores.CanAdd(test) || Saver.HighTimes.CanAdd(test))
            {
                Saver.Save(test);
            }
        }
Ejemplo n.º 8
0
 public SavesList()
 {
     Saves = new TetrisSave[listLength];
     for (int i = 0; i < listLength; i++)
     {
         Saves[i] = new TetrisSave("---", 0, new TimeSpan(0))
         {
             UserName  = "******",
             GameEnded = new DateTime(0)
         };
     }
 }
Ejemplo n.º 9
0
            public RankingListItem(TetrisSave save, bool highLight) : base()
            {
                Text = save.UserName;
                SubItems.Add(save.Score.ToString());
                SubItems.Add(save.GameDuration.ToString(@"mm\:ss"));
                SubItems.Add(save.GameEnded.ToShortDateString());

                if (highLight)
                {
                    UseItemStyleForSubItems = true;
                    BackColor = Color.FromArgb(255, 242, 242);
                    ForeColor = Color.FromArgb(160, 0, 0);
                    Font      = new Font("YaHei", (float)10.5, FontStyle.Bold);
                }
            }
Ejemplo n.º 10
0
        public RankingList(TetrisSave current)
        {
            InitializeComponent();

            //读取存档并显示数据
            for (int i = 0; i < 10; i++)
            {
                TetrisSave newRecord;

                newRecord = Saver.highScores[i];
                lvwScoreList.Items.Add(new RankingListItem(newRecord, newRecord.Equals(current)));

                newRecord = Saver.highTimes[i];
                lvwTimeList.Items.Add(new RankingListItem(newRecord, newRecord.Equals(current)));
            }
        }
Ejemplo n.º 11
0
        public TSLVItem(TetrisSave sv, bool hilight) : base()
        {
            Save = sv;
            Text = sv.UserName;
            SubItems.Add(sv.Score.ToString());
            SubItems.Add(TimeSpanToStr(sv.GameDuration));
            SubItems.Add(sv.GameEnded.ToShortDateString());

            if (hilight)
            {
                this.UseItemStyleForSubItems = true;
                this.BackColor = Color.FromArgb(255, 242, 242);
                this.ForeColor = Color.FromArgb(160, 0, 0);
                Font           = new Font(this.Font, FontStyle.Bold);
            }
        }
Ejemplo n.º 12
0
 //按游戏时长进行冒泡排序
 protected override void Sort()
 {
     for (int i = 0; i < listLength; i++)
     {
         int maxInd = i;
         for (int j = i; j < listLength; j++)
         {
             if (Saves[j].GameDuration > Saves[maxInd].GameDuration)
             {
                 maxInd = j;
             }
         }
         TetrisSave tmp = Saves[maxInd];
         Saves[maxInd] = Saves[i];
         Saves[i]      = tmp;
     }
 }
Ejemplo n.º 13
0
 protected override void Sort()
 {
     for (int i = 0; i < 10; i++)
     {
         int maxInd = i;
         for (int j = i; j < 10; j++)
         {
             if (Saves[j].Score > Saves[maxInd].Score)
             {
                 maxInd = j;
             }
         }
         TetrisSave tmp = Saves[maxInd];
         Saves[maxInd] = Saves[i];
         Saves[i]      = tmp;
     }
 }
Ejemplo n.º 14
0
        public static void Load()
        {
            List <TetrisSave> loaded = new List <TetrisSave>();

            //加载存档
            using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                using (BinaryReader br = new BinaryReader(fs))
                {
                    while (br.PeekChar() != -1)
                    {
                        TetrisSave tetrisSave = new TetrisSave
                        {
                            UserName     = br.ReadString(),
                            Score        = br.ReadInt32(),
                            GameDuration = new TimeSpan(br.ReadInt64()),
                            GameEnded    = new DateTime(br.ReadInt64())
                        };
                        loaded.Add(tetrisSave);
                    }
                }

            //填补空白,存档文件必须具有正确格式,否则会出bug
            while (loaded.Count < 2 * listLength)
            {
                loaded.Add(new TetrisSave("---", 0, new TimeSpan(0)));
            }

            //传入数据
            TetrisSave[] scoreList = new TetrisSave[listLength];
            for (int i = 0; i < listLength; i++)
            {
                scoreList[i] = loaded[i];
            }
            highScores.Write(scoreList);

            TetrisSave[] timeList = new TetrisSave[listLength];
            for (int i = 0; i < listLength; i++)
            {
                timeList[i] = loaded[listLength + i];
            }
            highTimes.Write(timeList);
        }
Ejemplo n.º 15
0
        public RecordsForm(TetrisSave current)
        {
            InitializeComponent();

            for (int i = 0; i < 10; i++)
            {
                TetrisSave tmp = Saver.HighScores[i];
                bool       eq  = (tmp.UserName == current.UserName &&
                                  tmp.GameDuration == current.GameDuration &&
                                  tmp.Score == current.Score);

                ScoresListView.Items.Add(new TSLVItem(tmp, eq));

                tmp = Saver.HighTimes[i];
                eq  = (tmp.UserName == current.UserName &&
                       tmp.GameDuration == current.GameDuration &&
                       tmp.Score == current.Score);

                TimesListView.Items.Add(new TSLVItem(tmp, eq));
            }
        }
Ejemplo n.º 16
0
        public override void Add(TetrisSave s)
        {
            int i;

            for (i = 9; i >= 1; --i)
            {
                if (Saves[i - 1].Score >= s.Score)
                {
                    break;
                }
                Saves[i] = Saves[i - 1];
            }
            if (Saves[0].Score > s.Score)
            {
                Saves[i] = s;
            }
            else
            {
                Saves[0] = s;
            }
        }
Ejemplo n.º 17
0
        public override void Add(TetrisSave s)
        {
            int i;

            for (i = 9; i >= 1; --i)
            {
                if (Saves[i - 1].GameDuration >= s.GameDuration)
                {
                    break;
                }
                Saves[i] = Saves[i - 1];
            }
            if (Saves[0].GameDuration > s.GameDuration)
            {
                Saves[i] = s;
            }
            else
            {
                Saves[0] = s;
            }
        }
Ejemplo n.º 18
0
        //向存档中插入数据
        public override void Add(TetrisSave tetrisSave)
        {
            int i;

            for (i = listLength - 1; i >= 1; i--)
            {
                if (Saves[i - 1].GameDuration >= tetrisSave.GameDuration)
                {
                    break;
                }
                Saves[i] = Saves[i - 1];
            }
            if (Saves[0].GameDuration > tetrisSave.GameDuration)
            {
                Saves[i] = tetrisSave;
            }
            else
            {
                Saves[0] = tetrisSave;
            }
        }
Ejemplo n.º 19
0
        public static void Load()
        {
            using (FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                using (BinaryReader br = new BinaryReader(fs))
                {
                    List <TetrisSave> loaded = new List <TetrisSave>();
                    while (br.PeekChar() != -1)
                    {
                        TetrisSave sv = new TetrisSave();
                        sv.UserName     = br.ReadString();
                        sv.Score        = br.ReadInt32();
                        sv.GameDuration = new TimeSpan(br.ReadInt64());
                        sv.GameEnded    = new DateTime(br.ReadInt64());
                        loaded.Add(sv);
                    }

                    while (loaded.Count < 20)
                    {
                        loaded.Add(new TetrisSave("---", 0, new TimeSpan(0)));
                    }

                    TetrisSave[] sc = new TetrisSave[10], tm = new TetrisSave[10];
                    for (int i = 0; i < 10; ++i)
                    {
                        sc[i] = loaded[i];
                    }
                    for (int i = 0; i < 10; ++i)
                    {
                        tm[i] = loaded[10 + i];
                    }

                    for (int i = 0; i < 10; ++i)
                    {
                        System.Diagnostics.Trace.WriteLine(tm[i].ToString());
                    }

                    HighScores.Write(sc);
                    HighTimes.Write(tm);
                }
        }
Ejemplo n.º 20
0
        public static void Save(TetrisSave tetrisSave)
        {
            //判断并记录
            bool added = false;

            if (highScores.CanAdd(tetrisSave))
            {
                highScores.Add(tetrisSave); added = true;
            }
            if (highTimes.CanAdd(tetrisSave))
            {
                highTimes.Add(tetrisSave); added = true;
            }
            if (!added)
            {
                return;
            }

            //写入数据
            using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                using (BinaryWriter bw = new BinaryWriter(fs))
                {
                    for (int i = 0; i < listLength; i++)
                    {
                        bw.Write(highScores[i].UserName);
                        bw.Write(highScores[i].Score);
                        bw.Write(highScores[i].GameDuration.Ticks);
                        bw.Write(highScores[i].GameEnded.Ticks);
                    }
                    for (int i = 0; i < listLength; i++)
                    {
                        bw.Write(highTimes[i].UserName);
                        bw.Write(highTimes[i].Score);
                        bw.Write(highTimes[i].GameDuration.Ticks);
                        bw.Write(highTimes[i].GameEnded.Ticks);
                    }
                }
        }
Ejemplo n.º 21
0
        public static void Save(TetrisSave s)
        {
            bool added = false;

            if (HighScores.CanAdd(s))
            {
                HighScores.Add(s); added = true;
            }
            if (HighTimes.CanAdd(s))
            {
                HighTimes.Add(s); added = true;
            }

            if (!added)
            {
                return;
            }

            using (FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write))
                using (BinaryWriter bw = new BinaryWriter(fs))
                {
                    for (int i = 0; i < 10; ++i)
                    {
                        bw.Write(HighScores[i].UserName);
                        bw.Write(HighScores[i].Score);
                        bw.Write(HighScores[i].GameDuration.Ticks);
                        bw.Write(HighScores[i].GameEnded.Ticks);
                    }
                    for (int i = 0; i < 10; ++i)
                    {
                        bw.Write(HighTimes[i].UserName);
                        bw.Write(HighTimes[i].Score);
                        bw.Write(HighTimes[i].GameDuration.Ticks);
                        bw.Write(HighTimes[i].GameEnded.Ticks);
                    }
                }
        }
Ejemplo n.º 22
0
 public abstract bool CanAdd(TetrisSave s);
Ejemplo n.º 23
0
 public override bool CanAdd(TetrisSave s)
 {
     Sort();
     return(Saves[9].Score < s.Score);
 }
Ejemplo n.º 24
0
 public abstract void Add(TetrisSave s);
Ejemplo n.º 25
0
 public override bool CanAdd(TetrisSave s)
 {
     Sort();
     return(Saves[9].GameDuration < s.GameDuration);
 }
Ejemplo n.º 26
0
 public override bool CanAdd(TetrisSave tetrisSave)
 {
     Sort();
     //与最后一名比较
     return(Saves[listLength - 1].Score < tetrisSave.Score);
 }
Ejemplo n.º 27
0
 public override bool CanAdd(TetrisSave tetrisSave)
 {
     Sort();
     //与最后一名比较
     return(Saves[listLength - 1].GameDuration < tetrisSave.GameDuration);
 }