예제 #1
0
 // Empty constructor
 public Location()
 {
     nm          = "EMPTY";
     coords      = new int[] { 0, 0 };
     breweryCost = 500;
     ingredients = Ingredient.GetAllIngredients();
 }
예제 #2
0
 // Basic constructor
 public Location(string inNm, int[] inCoords)
 {
     nm          = inNm;
     coords      = inCoords;
     breweryCost = 500;
     ingredients = Ingredient.GetAllIngredients();
 }
예제 #3
0
        // ----- BuyIngredients ---------------------------
        //
        // Buy ingredients for a specific brewery
        //
        // ------------------------------------------------
        public static void BuyIngredients()
        {
            int breweryIdx, ingIdx, maxQty, px, qty;

            Brewery    selectedBrewery;
            Location   selectedLocation;
            Ingredient selectedIngredient;

            // List available breweries
            for (int i = 0; i < company.breweries.Count; i++)
            {
                Console.WriteLine("{0}) {1}",
                                  i + 1, company.breweryLocations[i].nm);
            }
            Console.WriteLine("Q) Abort");

            // Prompt user for input
            breweryIdx = GetUserInput(company.breweries.Count);
            if (breweryIdx == -1)
            {
                return;
            }

            selectedBrewery  = company.breweries[breweryIdx];
            selectedLocation = company.breweryLocations[breweryIdx];

            // List all available ingredients and prices
            List <Ingredient> ingList = Ingredient.GetAllIngredients();

            for (int i = 0; i < ingList.Count; i++)
            {
                Console.WriteLine("{0}) ${2} | {1}",
                                  i + 1, ingList[i].nm,
                                  selectedLocation.GetPrice(ingList[i].nm));
            }

            // Prompt user for ingredient input
            ingIdx = GetUserInput(ingList.Count);
            if (ingIdx == -1)
            {
                return;
            }
            selectedIngredient = ingList[ingIdx];

            // Prompt user for quantity
            px     = selectedLocation.GetPrice(selectedIngredient.nm);
            maxQty = company.cash / px;
            Console.WriteLine("How many \"{0}\" for {1} each?",
                              selectedIngredient.nm, px);
            Console.WriteLine("(0-{0})", maxQty);
            try
            {
                do
                {
                    qty = Convert.ToInt32(Console.ReadLine());
                    if (qty < 0 || qty > maxQty)
                    {
                        Console.WriteLine("Outside acceptable range.");
                        Console.ReadKey();
                    }
                }while (qty < 0 || qty > maxQty);
            }
            catch (FormatException e)
            {
                Console.WriteLine("Invalid selection.");
                Console.ReadKey();
                return;
            }

            // Charge the company's cash and add the ingredient
            if (!company.Charge(px * qty))
            {
                Console.WriteLine("Insufficient funds.");
                Console.ReadKey();
                return;
            }
            else
            {
                selectedBrewery.Add(selectedIngredient, qty);
                Console.WriteLine("Purchased {0} units of \"{1}\".",
                                  qty, selectedIngredient.nm);
                Console.ReadKey();
            }
        }