Ejemplo n.º 1
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.º 2
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].GameDuration > Saves[maxInd].GameDuration)
             {
                 maxInd = j;
             }
         }
         TetrisSave tmp = Saves[maxInd];
         Saves[maxInd] = Saves[i];
         Saves[i]      = tmp;
     }
 }
Ejemplo n.º 3
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.º 4
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.º 5
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.º 6
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.º 7
0
 public override bool CanAdd(TetrisSave s)
 {
     Sort();
     return(Saves[9].GameDuration < s.GameDuration);
 }
Ejemplo n.º 8
0
 public override bool CanAdd(TetrisSave s)
 {
     Sort();
     return(Saves[9].Score < s.Score);
 }
Ejemplo n.º 9
0
 public abstract bool CanAdd(TetrisSave s);
Ejemplo n.º 10
0
 public abstract void Add(TetrisSave s);