Example #1
0
        public IEnumerable <Powerball> FindBestMatches(Powerball draw)
        {
            var file = ReadFile();

            foreach (var m in file)
            {
                if (m.Nmbers[0] == draw.Nmbers[0])
                {
                    m.Match++;
                }
                if (m.Nmbers[1] == draw.Nmbers[1])
                {
                    m.Match++;
                }
                if (m.Nmbers[2] == draw.Nmbers[2])
                {
                    m.Match++;
                }
                if (m.Nmbers[3] == draw.Nmbers[3])
                {
                    m.Match++;
                }
                if (m.Nmbers[4] == draw.Nmbers[4])
                {
                    m.Match++;
                }
            }

            return(file);
        }
Example #2
0
        public void Drawing(Data.FileRepo power)
        {
            var service = new Services();
            var result  = service.Draw(power);
            var p       = new Data.Powerball();

            var PowerBallTicket = service.CreatePowerBallTicket();

            var list = service.FindBestMatches(PowerBallTicket);

            var orderedList = list.OrderBy(c => c.Match);

            if (result == true)
            {
                Console.Clear();
                Console.WriteLine("Wow, you actually won the PowerBall, are you cheating????");
            }
            else
            {
                Console.Clear();
                foreach (var h in list)
                {
                    Console.WriteLine($"ID: {h.ID} \t Numbers: {h.Nmbers[0]} {h.Nmbers[1]} {h.Nmbers[2]}" +
                                      $" {h.Nmbers[3]} {h.Nmbers[4]}  PowerBall:  {h.Powerballnum}    Matches:  {h.Match}");
                }
                Console.WriteLine("You didn't win the PowerBall, please try again!");
                Console.WriteLine("The file will now clear.");
            }
            power.ClearFile(p);
            Console.ReadKey();
        }
Example #3
0
        public void Selection(Data.Powerball powerball, Data.FileRepo c)
        {
            int selection = 0;

            do
            {
                selection = SelectFromMenu();
                switch (selection)

                {
                case 1:
                    AddPick();
                    break;

                case 2:
                    QuickDraw();
                    break;

                case 3:
                    ListInfo(c);
                    break;

                case 4:
                    Drawing(c);
                    break;

                case 5:
                    continue;
                }
            } while (selection > 0 && selection < 5);
            Console.WriteLine("Done");
        }
Example #4
0
        public void ClearFile(Powerball classinfo)
        {
            string filePath = @"C:\Users\Mason\Downloads\PowerBallNums.txt";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
Example #5
0
        public Data.Powerball AddPick()
        {
            var powerball = new Data.Powerball();
            var file      = new Data.FileRepo();


            for (int i = 0; i < 5; i++)
            {
                bool contain = true;
                while (contain == true)
                {
                    int input = ReadIntInRange($"Please enter in a number between 1-69 for Set {i + 1}: ", 1, 69);

                    if (powerball.Nmbers.Contains(input))
                    {
                        Console.WriteLine("Please enter in a unique number!");
                        contain = true;
                    }
                    else
                    {
                        powerball.Nmbers.Add(input);
                        contain = false;
                    }
                }
            }


            int powerInput = ReadIntInRange($"Please enter in a number between 1-26 for your Powerball Number: ", 1, 26);

            powerball.Powerballnum = powerInput;

            // this part is going to set the id, which means grabbing the file and finding the max of all ids.

            var max = file.ReadFile();



            int count = max.Count();

            if (count == 0)
            {
                powerball.ID = 1;
            }
            else if (count > 0)
            {
                var maxID = max.Max(m => m.ID);
                powerball.ID = maxID + 1;
            }
            //now this will write the file

            file.WriteFile(powerball);

            Console.WriteLine($"This is your ID for the ticket you just created: {powerball.ID}");
            Console.ReadKey();

            return(powerball);
        }
Example #6
0
        // THIS CAN USE CONSOLE BUT NOT FILE IO

        public void Run()
        {
            var c = new Data.FileRepo();
            var p = new Data.Powerball();


            Selection(p, c);
            SelectFromMenu();
        }
Example #7
0
        // this is going to be methods

        // NO CONSOLE OR FILE IO


        // this can be used for powerball and for quick pick
        public Data.Powerball RandomTicket()
        {
            var random = new Random();

            var powerball = new Data.Powerball();
            var file      = new Data.FileRepo();


            for (int i = 0; i < 5; i++)
            {
                bool contain = true;

                while (contain == true)
                {
                    int check = random.Next(1, 69);

                    if (powerball.Nmbers.Contains(check))
                    {
                        check   = random.Next(1, 69);
                        contain = true;
                    }
                    else
                    {
                        powerball.Nmbers.Add(check);
                        contain = false;
                    }
                }
            }


            powerball.Powerballnum = random.Next(1, 26);

            var max = file.ReadFile();



            int count = max.Count();

            if (count == 0)
            {
                powerball.ID = 1;
            }
            else if (count > 0)
            {
                var maxID = max.Max(m => m.ID);
                powerball.ID = maxID + 1;
            }

            //if need be write to file.

            // not really sure how I'm going to print off the id, unless I make a method in controller to print it off
            // Console.WriteLine($"This is your ID for the ticket you just created: {powerball.ID}");


            return(powerball);
        }
Example #8
0
        // NO CONSOLE OR UI CODE


        //class info is just the get set stuff from powerball
        public void WriteFile(Powerball classinfo)
        {
            string path = @"C:\Users\Mason\Downloads\PowerBallNums.txt";

            if (!File.Exists(path))
            {
                File.Create(path);
            }


            using (StreamWriter writer = File.AppendText(path))
            {
                writer.WriteLine($"{classinfo.ID},{string.Join(",", classinfo.Nmbers)},{classinfo.Powerballnum}");
            }
        }
Example #9
0
        public IEnumerable <Powerball> ReadFile()
        {
            var    power = new Powerball();
            string path  = @"C:\Users\Mason\Downloads\PowerBallNums.txt";

            if (!File.Exists(path))
            {
                File.Create(path);
            }

            Dictionary <string, Powerball> powerBall = new Dictionary <string, Powerball>();

            string[] rows = File.ReadAllLines(path);
            {
                for (int i = 0; i < rows.Length; i++)
                {
                    List <int> powers = new List <int>();

                    string[] columns = rows[i].Split(',');

                    if (columns.Length == 1)
                    {
                        break;
                    }

                    else
                    {
                        powers.Add(int.Parse(columns[1]));
                        powers.Add(int.Parse(columns[2]));
                        powers.Add(int.Parse(columns[3]));
                        powers.Add(int.Parse(columns[4]));
                        powers.Add(int.Parse(columns[5]));

                        powerBall.Add(columns[0], new Powerball
                        {
                            ID           = int.Parse(columns[0]),
                            Nmbers       = powers,
                            Powerballnum = int.Parse(columns[6])
                        });
                    }
                }
            }
            return(powerBall.Values);
        }
Example #10
0
        // this class is going to be where the interface is implemented and used for testing. actually not really sure if it needs to be used. pretty confused on everythign.


        //public Powerball Create(Powerball pick)
        //{

        //    //var p = new Powerball();


        //}

        public IEnumerable <Powerball> FindBestMatches(Powerball draw)
        {
            throw new NotImplementedException();
        }