Esempio n. 1
0
        private void addShip(Ship newShip)
        {
            int n;

            n = newShip.defineShipType();
            //If current ship amount of docks is higher, than current harbor capacity
            if (n > currentCapacity)
            {
                //Add to queue, if it isn't already ship from the queue
                if ((shipQueue.Count == 0) || (newShip != shipQueue.Peek()))
                {
                    NotifyOrder?.Invoke("Корабль добавлен в очередь");
                    shipQueue.Enqueue(newShip);
                }
            }
            else
            {
                //If it is ship from the queue, than remove it from the queue
                if ((shipQueue.Count > 0) && (newShip == shipQueue.Peek()))
                {
                    shipQueue.Dequeue();
                    if (newShip is SmallShip)
                    {
                        NotifyOrder?.Invoke("Малый корабль вышел из очереди и поступил на обслуживание");
                    }
                    else if (newShip is MiddleShip)
                    {
                        NotifyOrder?.Invoke("Средний корабль вышел из очереди и поступил на обслуживание");
                    }
                    else
                    {
                        NotifyOrder?.Invoke("Большой корабль вышел из очереди и поступил на обслуживание");
                    }
                }
                //Reducing current harbor capacity
                currentCapacity -= n;
                if (newShip is SmallShip)
                {
                    NotifyAll?.Invoke("Малый корабль поступил на обслуживание");
                }
                else if (newShip is MiddleShip)
                {
                    NotifyAll?.Invoke("Средний корабль поступил на обслуживание");
                }
                else
                {
                    NotifyAll?.Invoke("Большой корабль поступил на обслуживание");
                }
                NotifyAll?.Invoke($"Время обслуживания {newShip.timeInService} часов");
                //Defining time out of current ship
                newShip.timeOut = currentTime + newShip.timeInService;
                //Adding current ship to service list
                shipService.Add(newShip);
            }
        }
Esempio n. 2
0
        public void addShip(Ship newShip)
        {
            int n;

            n = newShip.defineShipType();
            if (n > currentCapacity)
            {
                if ((shipQueue.Count == 0) || (newShip != shipQueue.Peek()))
                {
                    NotifyOrder?.Invoke("Корабль добавлен в очередь");
                    shipQueue.Enqueue(newShip);
                }
            }
            else
            {
                if ((shipQueue.Count > 0) && (newShip == shipQueue.Peek()))
                {
                    shipQueue.Dequeue();
                    if (newShip is SmallShip)
                    {
                        NotifyOrder?.Invoke("Малый корабль вышел из очереди и поступил на обслуживание");
                    }
                    else if (newShip is MiddleShip)
                    {
                        NotifyOrder?.Invoke("Средний корабль вышел из очереди и поступил на обслуживание");
                    }
                    else
                    {
                        NotifyOrder?.Invoke("Большой корабль вышел из очереди и поступил на обслуживание");
                    }
                }

                currentCapacity -= n;
                if (newShip is SmallShip)
                {
                    NotifyAll?.Invoke("Малый корабль поступил на обслуживание");
                }
                else if (newShip is MiddleShip)
                {
                    NotifyAll?.Invoke("Средний корабль поступил на обслуживание");
                }
                else
                {
                    NotifyAll?.Invoke("Большой корабль поступил на обслуживание");
                }
                NotifyAll?.Invoke($"Время обслуживания {newShip.timeInService} часов");
                newShip.timeOut = currentTime + newShip.timeInService;
                shipService.Add(newShip);
            }
        }