示例#1
0
        /// <summary>
        /// adds a customer to the end
        /// </summary>
        /// <param name="newCustomer"></param>
        public void AddToQueue(CustomerNode newCustomer)
        {
            //if there are no customers
            if (amountOfCustomers == 0)
            {
                //the first customer is set to the new customer
                firstCustomer = newCustomer;
            }
            else
            {
                //temp variable ot store the customers
                CustomerNode currentCustomer = firstCustomer;

                //checking until the final customer
                for (int i = 0; i < amountOfCustomers - 1; i++)
                {
                    //going to the next customer
                    currentCustomer = currentCustomer.GetNextCustomer();
                }

                //adding a customer to the end of the queue
                currentCustomer.SetNextCustomer(newCustomer);
            }

            //increasing the number of customers
            amountOfCustomers++;
        }
示例#2
0
        /// <summary>
        /// removes the front customer
        /// </summary>
        public void RemoveHead()
        {
            //if there is at least one customer
            if (amountOfCustomers > 0)
            {
                //the first customer is set to the next customer
                firstCustomer = firstCustomer.GetNextCustomer();

                //decreasing the number of customers
                amountOfCustomers--;
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            //temp variable for the customers
            CustomerNode currentCustomer = firstCustomer;

            //checking each customer
            for (int i = 0; i < amountOfCustomers; i++)
            {
                //upadting each customer
                currentCustomer.UpdateCustomer(gameTime, false);

                //getting the next customer
                currentCustomer = currentCustomer.GetNextCustomer();
            }
        }
示例#4
0
 /// <summary>
 /// This subprogram adds onto the queue by placing aother customer to the last
 /// customer in line
 /// </summary>
 /// <param name="nextCustomer">the customer that is put in the queue</param>
 public void SetNextCustomer(CustomerNode nextCustomer)
 {
     this.nextCustomer = nextCustomer;
 }
示例#5
0
        /// <summary>
        /// This subprogram updates the shop
        /// </summary>
        /// <param name="gameTime">helps with recording time</param>
        public void UpdateShop(GameTime gameTime)
        {
            //increasing the timer
            simTimer += (float)gameTime.ElapsedGameTime.Milliseconds;

            //moving the customer
            shopView.CustomerMovement(addingCustomer, areCashiersBusy, cashiers, customerName);

            //updates Top 5 wait times
            stats.UpdateTopFive(inCustomerQue);
            top5WaitTimes = stats.ReturnTopFive();

            //if it has not been 300 seconds
            if (simTimer < TIME_OF_SIM)
            {
                //a customer is not being added
                addingCustomer = false;

                //incrementing the timer for a new customer
                addNewCustomerTimer += (float)gameTime.ElapsedGameTime.Milliseconds;

                //if it has been more than 3 seconds, add a new customer
                if (addNewCustomerTimer >= TIME_FOR_ADD_CUSTOMER)
                {
                    //adding a customer
                    addingCustomer = true;

                    //restarting the timer
                    addNewCustomerTimer = NO_TIME;

                    //getting the new customer
                    tempCustomer = new CustomerNode(customerNum);

                    //getting the name of the customer
                    customerName = tempCustomer.GetOrder();

                    //add a customer to the outside line
                    outCustomerQue.AddToQueue(tempCustomer);

                    //adding a custoemr to the shole queue list
                    wholeQueue.AddToQueue(tempCustomer);

                    //adding to the number of customers
                    customerNum++;

                    //if inside is not full then
                    if (inCustomerQue.GetCustomerAmount() <= MAX_NUM_IN)
                    {
                        //the head of the oud door queue is put as the tail of the indoor queue
                        inCustomerQue.AddToQueue(outCustomerQue.GetFirstCustomer());

                        //removing the out queue head
                        outCustomerQue.RemoveHead();
                    }
                }



                //checking each cashier
                for (int i = NO_VALUE; i < cashiers.Length; i++)
                {
                    //if the cashier is not busy
                    if (cashiers[i] == null)
                    {
                        //the next available vcustooemr is brought to the cashier
                        cashiers[i] = inCustomerQue.GetFirstCustomer();

                        //the front customer is dequeued
                        inCustomerQue.RemoveHead();

                        break; // changed, copy this
                    }


                    //if the cashier is no
                    if (cashiers[i] != null)
                    {
                        //updating the customer at the cashier
                        cashiers[i].UpdateCustomer(gameTime, true);

                        //if the customer is served
                        if (cashiers[i].IsCustomerServed == true)
                        {
                            //adding to the total wait time of the customers
                            totalWaitTime += cashiers[i].ReturnTotalTime();

                            //increasing the number of customers served
                            numServed++;

                            //getting the average wait time
                            averageWaitTime = stats.UpdateAveWaitTime(totalWaitTime / ONE_SECOND, numServed);

                            //checking to see if there is a min wait time or new max time
                            minTime = stats.GetMinWaitTime(cashiers[i].ReturnTotalTime());
                            maxTime = stats.GetMaxWaitTime(cashiers[i].ReturnTotalTime());

                            //removingthe front customer
                            wholeQueue.RemoveHead();

                            break;
                        }
                    }
                }
                inCustomerQue.Update(gameTime);
                outCustomerQue.Update(gameTime);
                wholeQueue.Update(gameTime);
            }
            else
            {
                isSimOver = true;
            }
        }