/// <summary> /// subprogram uses merge sort and temporary variables to go through every person in the linked list /// sorts all the customer based of the wait time (from least to greatest) /// updates the top 5 array /// </summary> /// <param name="updatedQueue"></param> public void UpdateTopFive(CustomerQueue updatedQueue) { //temporary customerqueue variable CustomerQueue tempQueue = updatedQueue; //temporary list that will store all the nodes from the linked list List <double> numList = new List <double>(); List <string> nameList = new List <string>(); //while the linked list is not at the end //populates the temp list for (int i = 0; i < tempQueue.GetCustomerAmount(); i++) { //adds the names and time list numList.Add(tempQueue.GetFirstCustomer().ReturnTotalTime()); nameList.Add(tempQueue.GetFirstCustomer().GetOrder()); //removes that node from the linked list tempQueue.RemoveHead(); } // calls the merge sort method (sorts the list) MergeSort(numList, nameList); //sets the 2 arrays (times and names) using the array from the temp list for (int i = 0; i < numList.Count; i++) { top5[i] = nameList[i] + Convert.ToString(numList[i]); } }
/// <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; } }