// Mocking methods

        private int LoadPreSortedData() // speeds up debugging by not having to re sort file
        {
            FinalLine        f      = new FinalLine();
            StreamReader     r      = new StreamReader(SourceFile);
            List <FinalLine> sorted = new List <FinalLine>();

            FileInfo  fi           = new FileInfo(SourceFile);
            long      size         = fi.Length; // size in bits
            long      bytesRead    = 0;
            int       percent      = 0;
            const int bytesPerChar = 1; //ASCII
            string    line;

            while (!r.EndOfStream)
            {
                line = r.ReadLine();
                f.ReadLine(line);
                sorted.Add(new FinalLine(f));
                bytesRead += (line.Length + 2) * bytesPerChar; // +2 to account for return char and new line

                if (percent < bytesRead * 100 / size)
                {
                    percent++;
                    bgw.ReportProgress(percent);
                }
            }

            r.Close();
            Records.AddFirst(sorted);
            return(Records.First().Count());
        }
示例#2
0
        public void StartGame()
        {
            _gamePanel.gameObject.SetActive(true);

            var newRecord = Records.First?.Value ?? new Record {
                Level = 0, Score = 0
            };

            Records.AddFirst(newRecord);
            var level = Records.First.Value.Level;

            InitLevelData(level);
        }
        private int FirstPass(StationDictionary stations) // reads in data and converts to numerical form
        {
            StreamReader r = new StreamReader(SourceFile);
            FinalLine    f = new FinalLine();

            FileInfo fi   = new FileInfo(SourceFile);
            long     size = fi.Length; //bytes in file

            long bytesRead = 0;
            int  percent   = 0;

            string line;

            const int bytesPerChar = 1; // UTF-8

            while (!r.EndOfStream)
            {
                line = r.ReadLine();
                if (f.TryInitialise(line, stations))
                {
                    Records.AddFirst(new List <FinalLine> {
                        new FinalLine(f)
                    });
                }

                bytesRead += (line.Length + 2) * bytesPerChar; // +2 to account for return and new line

                if (percent < (bytesRead * split) / size)
                {
                    percent++;
                    bgw.ReportProgress(percent);
                }
            }

            r.Close();
            return(Records.Count());
        }