示例#1
0
        private static void sortChosenCandy(CandyStorage db, string selectedCandy, int userId)
        {
            // Getting all of the user's candy by their ID
            var usersCandy = db.GetCandyByUserId(userId);
            // Getting the first candy that matches what the user picked and what's in the list
            var candyList = usersCandy.FirstOrDefault(x => x.Name == selectedCandy);

            // If there's a matching candy in the list
            if (candyList != null)
            {
                var candyToUpdate = usersCandy
                                    .Where(x => x.Name == selectedCandy)
                                    // making sure that we eat the candy that we received first so that we don't waste candy
                                    .OrderBy(x => x.DateReceived)
                                    .First();
                // Since our GetCandyByUserId method only returns "isEaten = false" candy
                candyToUpdate.isEaten = true;
                updateEatenCandy(db, candyToUpdate);
            }
            else
            {
                // AddEatCandyMenu(db, userId);
                Console.WriteLine("Please choose a candy from the list! Lets try this again");
                Console.ReadLine();
            }
        }
示例#2
0
        public static void SeedCandy()
        {
            var candyDb = new CandyStorage();

            var dummyCandies = new List <Candy>
            {
                new Candy("Reeses", "Chocolate", DateTime.Now, "Mars", 1),
                new Candy("Reeses", "Chocolate", DateTime.Now, "Mars", 1),
                new Candy("Skittles", "Sour", DateTime.Now, "Mars", 2),
                new Candy("Skittles", "Sour", DateTime.Now, "Mars", 2),
                new Candy("Snickers", "Chocolate", DateTime.Now, "Hershey", 3),
                new Candy("Snickers", "Chocolate", DateTime.Now, "Hershey", 3),
                new Candy("Snickers", "Chocolate", DateTime.Now, "Mars", 4),
                new Candy("Baby Ruth", "Chocolate", DateTime.Now, "Mars", 1),
                new Candy("Kit Kat", "Chocolate", DateTime.Now, "Mars", 2),
                new Candy("Air Heads", "Sour", DateTime.Now, "Haribo", 3),
                new Candy("Almond Joy", "Chocolate", DateTime.Now, "Nestle", 4),
                new Candy("Almond Joy", "Chocolate", DateTime.Now, "Nestle", 4),
                new Candy("Starburst", "Fruity", DateTime.Now, "Nestle", 1),
                new Candy("M&M", "Chocolate", DateTime.Now, "Mars", 2),
                new Candy("Gummy Worms", "Fruit Gummy", DateTime.Now, "Trolli", 3),
                new Candy("Hershey Kisses", "Chocolate", DateTime.Now, "Hershey", 4),
                new Candy("Kinder Egg", "Chocolate", DateTime.Now, "Nestle", 1),
                new Candy("Flake", "Chocolate", DateTime.Now, "Cadbury", 2),
                new Candy("Candy Corn", "Other", DateTime.Now, "Mars", 3),
                new Candy("Licorice", "Salty", DateTime.Now, "Mars", 4),
            };

            foreach (var candy in dummyCandies)
            {
                candyDb.SaveNewCandy(candy);
            }
        }
示例#3
0
        public static void AddEatCandyMenu(CandyStorage db, int userId)
        {
            var myCandy = db.GetCandyByUserId(userId);

            if (myCandy.Count > 0)
            {
                View EatCandyMenuView = new View()
                                        .AddMenuOption("Just so that we're clear, you want to eat some candy from your collection, right?")
                                        .AddMenuText("Press Esc to exit.");
                Console.Write(EatCandyMenuView.GetFullMenu());
                var userSelection         = Console.ReadKey().KeyChar.ToString();
                var userSelectionToNumber = int.Parse(userSelection);

                if (userSelectionToNumber == 1)
                {
                    ListingUserCandy(db, userId);
                }
                else
                {
                    Console.WriteLine("Error");
                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("Yikes it looks like you're out of candy!");
                Console.ReadLine();
            }
        }
        public static void AddRandomCandyMenu(CandyStorage db, int userId)
        {
            var flavorString = GetUsersCandyFlavors(db, userId);

            if (flavorString.Count < 1)
            {
                Console.WriteLine("You have no Candy.  Press any Key to return to the Main Menu");
                Console.ReadLine();
                return;
            }

            View addRandomCandyFlavors = new View()

                                         .AddMenuText(error ? "Could not locate that Flavor, Try again:" : "Please select the Flavor of candy you wish to eat from the list:")
                                         .AddMenuOptions(flavorString)
                                         .AddMenuText("Press Esc to return to the Main Menu");

            Console.Write(addRandomCandyFlavors.GetFullMenu());
            var userSelection = Console.ReadKey();

            if (userSelection.Key == ConsoleKey.Escape)
            {
                return;
            }

            var selectedCandyFlavor = GetFlavorFromMenu(userSelection, flavorString);

            EatRandomCandy(db, selectedCandyFlavor, userId);
        }
示例#5
0
        //Trade Logic
        internal static void TradeCandy(CandyStorage db, int userId, Users CandyTradeWho, string CandyRecieveWhat, string CandyGiveWhat)
        {
            var MyCandyBag   = db.GetCandyByUserId(userId);
            var PieceToTrade = MyCandyBag.Find(x => x.Name.ToLower() == CandyGiveWhat.ToLower());

            var TheirCandyBag = db.GetCandyByUserId(CandyTradeWho.Id);
            var PieceToGet    = TheirCandyBag.Find(x => x.Name.ToLower() == CandyRecieveWhat.ToLower());

            if (PieceToGet != null && PieceToTrade != null)
            {
                PieceToGet.UserId   = userId;
                PieceToTrade.UserId = CandyTradeWho.Id;
                Console.WriteLine($"You traded your {PieceToTrade.Name} for {CandyTradeWho.Name}'s {PieceToGet.Name}!");
                Console.ReadLine();
            }
            else if (PieceToGet == null)
            {
                Console.WriteLine($"Error.  {CandyTradeWho.Name} does not have any {CandyRecieveWhat} to trade.");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine($"Error. You do not have any {CandyGiveWhat} to trade.");
                Console.ReadLine();
            }
        }
示例#6
0
        private static void updateEatenCandy(CandyStorage db, Candy candyToUpdate)
        {
            var candyUserAte = db.UpdateCandy(candyToUpdate);

            Console.WriteLine($"\nYummy! that {candyUserAte.Name} was absolutely delicious!");
            Console.WriteLine("\nPress the Enter key to continue.");
            Console.ReadLine();
        }
        private static void UpdateRandomCandy(CandyStorage db, Candy candyToUpdate)
        {
            var UpdatedCandy = db.UpdateCandy(candyToUpdate);

            Console.WriteLine($"\nYou just ate a {UpdatedCandy.Name} that was recieved on {UpdatedCandy.DateReceived}");
            Console.WriteLine("\nPress the Enter key to continue.");
            Console.ReadLine();
        }
        // Return the Distinct Flavor Categories for a user
        private static List <string> GetUsersCandyFlavors(CandyStorage db, int userId)
        {
            var usersCandy       = db.GetCandyByUserId(userId);
            var userCandyFlavors = usersCandy
                                   .Select(candy => candy.FlavorCategory)
                                   .Distinct()
                                   .ToList();

            return(userCandyFlavors);
            //return string.Join(", ", userCandyFlavors);
        }
示例#9
0
        internal static void AddNewCandy(CandyStorage db, string newCandyName, string newCandyFlavor, string newCandyManufacturer, int newCandyQuantity, int userId)
        {
            for (int i = 0; i < newCandyQuantity; i++)
            {
                var newCandy   = new Candy(newCandyName, newCandyFlavor, DateTime.Now, newCandyManufacturer, userId);
                var savedCandy = db.SaveNewCandy(newCandy);
            }

            Console.WriteLine($"You now you own {newCandyQuantity} piece(s) of {newCandyName} candy!");
            Console.WriteLine("Press the 'Enter' key to continue.");
            Console.ReadLine();
        }
示例#10
0
 public void GetCandyObj()
 {
     PP   = GameObject.Find("PitPats");
     PPCS = PP.GetComponent <CandyStorage>();
     BB   = GameObject.Find("Booster Bars");
     BBCS = BB.GetComponent <CandyStorage>();
     RW   = GameObject.Find("Red and Whites");
     RWCS = RW.GetComponent <CandyStorage>();
     HS   = GameObject.Find("Her-She's");
     HSCS = HS.GetComponent <CandyStorage>();
     SP   = GameObject.Find("SmallPleasers");
     SPCS = SP.GetComponent <CandyStorage>();
 }
示例#11
0
        private static void EatRandomCandy(CandyStorage db, string candyFlavor, int userId)
        {
            // Get All users Candy and see if we can match one in the list with what they typed, if not show menu again?
            var usersFlavorCandy = db.GetCandyByUserId(userId);
            var flavorsList      = usersFlavorCandy.FirstOrDefault(f => f.FlavorCategory == candyFlavor);

            // Found a candy flavor match so lets filter and sort by earliest date and send that to UpdateCandy Method
            if (flavorsList != null)
            {
                error = false; // Set our flag back to false
                // List<Candy> filtered by the Flavor the user typed
                var usersCandyToUpdate = usersFlavorCandy
                                         .Where(candy => candy.FlavorCategory == candyFlavor)
                                         .ToList();

                // Now let us get a Random piece of candy from the list of candies filtered by Flavor
                var userRandomCandy = usersCandyToUpdate[random.Next(usersCandyToUpdate.Count)];

                // Get the count of that flavor candy by name.  Need to filter by oldest of more than one
                var randomCandyCount = usersCandyToUpdate.Where(candy => candy.Name == userRandomCandy.Name).Count();

                if (randomCandyCount > 1)
                {
                    var randomCandyToUpdate = usersFlavorCandy
                                              .Where(candy => candy.Name == userRandomCandy.Name)
                                              .OrderBy(candy => candy.DateReceived)
                                              .FirstOrDefault();
                    // Update isEaten to true and pass the updated Candy on to the CandyStorage
                    randomCandyToUpdate.isEaten = true;
                    UpdateRandomCandy(db, randomCandyToUpdate);
                }
                else
                {
                    var randomCandyToUpdate = usersFlavorCandy
                                              .Where(candy => candy.Name == userRandomCandy.Name)
                                              .FirstOrDefault();
                    // Update isEaten to true and pass the updated Candy on to the CandyStorage
                    randomCandyToUpdate.isEaten = true;
                    UpdateRandomCandy(db, randomCandyToUpdate);
                }
            }
            else
            {
                // Must have typed a flavor wrong or couldn't find what you typed
                error = true;
                AddRandomCandyMenu(db, userId);
            }
        }
示例#12
0
        public static void AddTradeCandyMenu(CandyStorage db, int userId, Users user, List <Users> candyUsers)
        {
            //Screen for choosing who to trade with
            var  yourName          = user.Name;
            var  allNames          = candyUsers.Select(u => u.Name).ToList();
            var  everyoneButYou    = allNames.Remove(yourName);
            View candyMenuTradeWho = new View()
                                     .AddMenuText($"Hello {user.Name}. Who would you like to trade with?")
                                     .AddMenuOptions(candyUsers.Select(u => u.Name).ToList());

            Console.Write(candyMenuTradeWho.GetFullMenu());
            var selectedTradeUser = Console.ReadKey();
            var userInput         = selectedTradeUser.KeyChar.ToString();
            var ParsedTradeUser   = int.Parse(userInput);
            var CandyTradeWho     = DisplayUserMenu.GetUser(ParsedTradeUser, candyUsers);

            if (CandyTradeWho.Id == userId)
            {
                Console.WriteLine("\nYou want to trade with yourself?  That seems like a dumb waste of your time, but knock yourself out. . .");
                Console.ReadLine();
            }

            //Screen for choosing what candy you want
            var  theirCandyBag        = db.GetCandyByUserId(CandyTradeWho.Id);
            var  listTheirCandyBag    = theirCandyBag.Select(x => x.Name).ToList();
            var  showTheirCandyBag    = string.Join("\n", listTheirCandyBag);
            View candyMenuRecieveWhat = new View()
                                        .AddMenuText($"This is what is in {CandyTradeWho.Name}'s candy bag:")
                                        .AddMenuText(showTheirCandyBag)
                                        .AddMenuText("What would you like to get in this trade?");

            Console.Write(candyMenuRecieveWhat.GetFullMenu());
            var CandyRecieveWhat = Console.ReadLine();

            //Screen for choosing which candy to give in return
            var  myCandyBag        = db.GetCandyByUserId(userId);
            var  listMyCandyBag    = myCandyBag.Select(x => x.Name).ToList();
            var  showMyCandyBag    = string.Join("\n", listMyCandyBag);
            View candyMenuGiveWhat = new View()
                                     .AddMenuText("This is what is in your candy bag:")
                                     .AddMenuText(showMyCandyBag)
                                     .AddMenuText("What would you like to give in this trade?");

            Console.Write(candyMenuGiveWhat.GetFullMenu());
            var CandyGiveWhat = Console.ReadLine();

            TradeCandy(db, userId, CandyTradeWho, CandyRecieveWhat, CandyGiveWhat);
        }
示例#13
0
        internal static void AddCandyMenus(CandyStorage db, int userId)
        {
            int newCandyQuantity = 0;

            var newCandyName = AddCandyMenuName();

            var newCandyFlavor = AddCandyMenuFlavor();

            var newCandyManufacturer = AddCandyMenuManufacturer();

            do
            {
                newCandyQuantity = AddCandyMenuQuantity();
            } while (newCandyQuantity < 1);

            AddNewCandy(db, newCandyName, newCandyFlavor, newCandyManufacturer, newCandyQuantity, userId);
        }
示例#14
0
        internal static void ListingUserCandy(CandyStorage db, int userId)
        {
            // Getting all of the user's candy by their ID
            var myCandy = db.GetCandyByUserId(userId);
            // Getting only the candy's name from that list
            var candyNames = myCandy.Select(candy => candy.Name).ToList();
            // Showing the user all of their candy options eat
            View chooseCandyView = new View()
                                   .AddMenuText("Which candy do you want to eat?")
                                   .AddMenuOptions(candyNames)
                                   .AddMenuText("Press Esc to return to the Main Menu");

            Console.WriteLine(chooseCandyView.GetFullMenu());
            // Getting the number from the user's choice
            var candySelected = Console.ReadKey();
            // Calling a method that converts the int to a string
            var userChosenCandy = candyIntToString(candySelected, candyNames);

            sortChosenCandy(db, userChosenCandy, userId);
        }