Exemplo n.º 1
0
 public void BuyItem(Booth booth)
 {
     if (booth.Inventory.Count != 0)
     {
         Inventory.Add(booth.Inventory.First());
     }
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            //PRODUCES ITEM IN ITEMPRODUCTION EVERY SECOND | Stores ALL items in ItemProduction until fetched by booth
            ItemProduction.ProduceItem();
            ItemProduction.SetTimerAndProduceItems();

            // Creates customer from CustomerFactory (Customers are waking up from a good night sleep)
            Customer wizardCustomer  = CustomerFactory.CreateCustomer(CustomerClass.Wizard, "WizardCustomer");
            Customer peasantCustomer = CustomerFactory.CreateCustomer(CustomerClass.Peasant, "PeasantCustomer");
            Customer warriorCustomer = CustomerFactory.CreateCustomer(CustomerClass.Warrior, "WarriorCustomer");

            // Booths at Bazaar preparing for a new day
            Booth        booth1    = new Booth(10, 0);
            Booth        booth2    = new Booth(5, 1);
            List <Booth> boothList = new List <Booth> {
                booth1, booth2
            };

            // The customers arrives at the Bazaar
            List <Person> customers = new List <Person> {
                wizardCustomer, peasantCustomer, warriorCustomer
            };

            Controller controller = new Controller();

            // The Booths at the Bazaar begins to get items from the supplier
            controller.InitiateBoothFetch(boothList);

            Thread[] itemForSaleThread = new Thread[boothList.Count];
Exemplo n.º 3
0
        public void PutItemUpForSale(Booth booth)
        {
            if (booth.Inventory.Count != 0)
            {
                lock (_lock)
                {
                    IItem item = booth.Inventory.First();

                    _view.ItemForSale(item, booth);
                }
            }
        }
Exemplo n.º 4
0
 public void MakeTransaction(Booth booth, Customer customer)
 {
     if (booth.Inventory.Count != 0)
     {
         customer.BuyItem(booth);
         booth.RemoveFirstItemFromInventory();
         lock (_lock)
         {
             _view.ItemBought(customer.GetLastItem(), customer, booth);
         }
         booth.DailyQuota--;
     }
 }
Exemplo n.º 5
0
 public void ItemForSale(IItem item, Booth booth)
 {
     Console.WriteLine("item#" + item.GetItemNumber() + " " + item.GetDescription() + " can now be bought from " +
                       booth.GetDescription());
 }
Exemplo n.º 6
0
 public void ItemBought(IItem item, Person customerName, Booth booth)
 {
     Console.WriteLine("\t\t\t" + customerName.GetDescription() + " bought " + "Item#"
                       + item.GetItemNumber() + item.GetDescription() + " from " + booth.GetDescription());
 }