public void Simulate() { NotifyAll += DisplayMessage; NotifyOrder += DisplayMessage; currentTime = 0; Random random = new Random(); Queue <SmallShip> smallShipList = new Queue <SmallShip>(); Queue <MiddleShip> middleShipList = new Queue <MiddleShip>(); Queue <BigShip> bigShipList = new Queue <BigShip>(); SmallShip.minTimeInPort = 1; SmallShip.maxTimeInPort = 3; SmallShip.amountOfDock = 1; MiddleShip.minTimeInPort = 4; MiddleShip.maxTimeInPort = 6; MiddleShip.amountOfDock = 2; BigShip.minTimeInPort = 6; BigShip.maxTimeInPort = 10; BigShip.amountOfDock = 3; for (int i = 0; i < 6; i++) { SmallShip newShip = new SmallShip(); smallShipList.Enqueue(newShip); } for (int i = 0; i < 4; i++) { MiddleShip newShip = new MiddleShip(); middleShipList.Enqueue(newShip); } for (int i = 0; i < 1; i++) { BigShip newShip = new BigShip(); bigShipList.Enqueue(newShip); } int randMin = 1; int randMax = 2; do { if (currentTime % 2 == 0) { //System.Threading.Thread.Sleep(); switch (random.Next(1, 4)) { case 1: if (smallShipList.Count > 0) { NotifyAll?.Invoke($"Поступил новый малый корабль в {currentTime} часов"); this.addShip(smallShipList.Dequeue()); } break; case 2: if (middleShipList.Count > 0) { NotifyAll?.Invoke($"Поступил новый средний корабль в {currentTime} часов"); this.addShip(middleShipList.Dequeue()); } break; case 3: if (bigShipList.Count > 0) { NotifyAll?.Invoke($"Поступил новый большой корабль в {currentTime} часов"); this.addShip(bigShipList.Dequeue()); } break; default: break; } randMin += currentTime; randMax += currentTime; } this.lookForNew(); currentTime++; } while (this.counter < 10); NotifyAll -= DisplayMessage; NotifyOrder -= DisplayMessage; Thread.Sleep(50); }
public void Simulate(int A, int B, int C, int D, int E, int F, int G, int H) { //Defing event hadelers NotifyAll += DisplayAllMessage; NotifyOrder += DisplayQueueMessage; NotifyCurrentStat += DisplayCurrentStatMessage; NotifyStat += DisplayStatMessage; currentTime = 0; Random random = new Random(); //Creating queue for all types of ships Queue <SmallShip> smallShipList = new Queue <SmallShip>(); Queue <MiddleShip> middleShipList = new Queue <MiddleShip>(); Queue <BigShip> bigShipList = new Queue <BigShip>(); //Filling queue for all types of ships for (int i = 0; i < 30; i++) { SmallShip newShip = new SmallShip(); smallShipList.Enqueue(newShip); } for (int i = 0; i < 15; i++) { MiddleShip newShip = new MiddleShip(); middleShipList.Enqueue(newShip); } for (int i = 0; i < 5; i++) { BigShip newShip = new BigShip(); bigShipList.Enqueue(newShip); } //Defing time intervals for all types of ships SmallShip.minTimeInPort = C; SmallShip.maxTimeInPort = D; MiddleShip.minTimeInPort = E; MiddleShip.maxTimeInPort = F; BigShip.minTimeInPort = G; BigShip.maxTimeInPort = H; //Defing time intervals for ship arrival int randMin = A; int randMax = B; //Finding time of arrival of first ship int timeOfNextShip = random.Next(randMin, randMax); do { //Checking if current time is time of arrival of new ship if (currentTime == timeOfNextShip) { //Defining which type of ship has arrived switch (random.Next(1, 4)) { case 1: if (smallShipList.Count > 0) { NotifyAll?.Invoke($"Поступил новый малый корабль в {currentTime} часов"); this.addShip(smallShipList.Dequeue()); } break; case 2: if (middleShipList.Count > 0) { NotifyAll?.Invoke($"Поступил новый средний корабль в {currentTime} часов"); this.addShip(middleShipList.Dequeue()); } break; case 3: if (bigShipList.Count > 0) { NotifyAll?.Invoke($"Поступил новый большой корабль в {currentTime} часов"); this.addShip(bigShipList.Dequeue()); } break; default: break; } //Changing arrive intervals randMin = currentTime + 1; randMax = currentTime + 2; //Finding time of arrival of next ship timeOfNextShip = random.Next(randMin, randMax); } this.lookForNew(); //Increasing current time currentTime++; //Displaing current statistics DisplayCurrentStatus(); //Thread.Sleep(10); } while (this.shipCounter < 50); //Displaying all of statistics DisplayStatistics(); NotifyAll -= DisplayAllMessage; NotifyOrder -= DisplayQueueMessage; NotifyCurrentStat -= DisplayCurrentStatMessage; NotifyStat -= DisplayStatMessage; }