Beispiel #1
0
 private void Delete_Station_Click(object sender, RoutedEventArgs e)
 {
     if (on)
     {
         for (int i = 0; i < subway.GetRailways.Count; i++)
         {
             Railway rl = subway.GetRailways.ElementAt(i);
             for (int j = 0; j < subway.GetRailways.ElementAt(i).GetStations.Count; j++)
             {
                 Station st = rl.GetStations.ElementAt(j);
                 if (st.ellipsePath == currElleipse)
                 {
                     if (st.Number == rl.GetStations.Count - 1)
                     {
                         fieldCanvas.Children.Remove(st.stationName);
                         fieldCanvas.Children.Remove(currElleipse);
                         if (st.Number > 0)
                         {
                             fieldCanvas.Children.Remove(rl.GetStations.ElementAt(j - 1).startLinePath);
                         }
                         rl.GetStations.RemoveAt(rl.GetStations.Count - 1);
                     }
                     else
                     {
                         MessageBox.Show("You can delete only the last station!");
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 internal void AddSubwayLine(String name)
 {
     if (on)
     {
         Railway rl = new Railway(name);
         subway.addRailway(rl);
         SubwayLinesLBox.Items.Add(name);
     }
 }
Beispiel #3
0
        private void tick(object sender, EventArgs e)
        {
            Railway rl = new Railway();
            Train   t  = new Train();

            for (int i = 0; i < subway.GetRailways.Count; i++)
            {
                rl = subway.GetRailways.ElementAt(i);
                for (int j = 0; j < subway.GetRailways.ElementAt(i).Trains.Count; j++)
                {
                    t = rl.Trains.ElementAt(j);
                    if (rl.GetStations.Count > 1)
                    {
                        ////////////////////////
                        if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start&& subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime == 0 &&
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation != 0 || !subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start&&
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).DepartureTime == currentTime)
                        {
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).DepartureTime == currentTime)
                            {
                                if (!fieldCanvas.Children.Contains(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).TrainPath))
                                {
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Stop(fieldCanvas, subway);
                                    fieldCanvas.Children.Add(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).TrainPath);
                                }
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start = true;
                            }
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).onStation = true;
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation--;
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation != 0)
                            {
                                Random r = new Random(DateTime.Now.Millisecond);
                                if (r.Next(1, 100) % 55 == 0)
                                {
                                    String str = "Train number: " + subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Number + " went ahead by " + subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation + " seconds at the station: " + subway.GetRailways.ElementAt(i).Trains.ElementAt(j).id;
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 0;
                                    subway.GetRailways.ElementAt(i).GetStations.ElementAt(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).id).AddViolations(str);
                                }
                            }
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).away&& subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation == 0)
                            {
                                if (t.Back)
                                {
                                    rl.GetStations.ElementAt(t.id).Board.TrainLeft(true);
                                }
                                else
                                {
                                    rl.GetStations.ElementAt(t.id).Board.TrainLeft(false);
                                }
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Back = !subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Back;
                                if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).numOfPassage != 1)
                                {
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 3;
                                }
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).currStationInd = 0;
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).away           = false;
                            }
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation == 0)
                            {
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).onStation   = false;
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).leftStation = true;
                            }
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).SetCurrId(subway);
                        }
                        if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).numOfPassage == 1 &&
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime == 0 && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation == 0)
                        {
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start = false;
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Stop(fieldCanvas, subway);
                        }
                        /////////////////////////////////////
                        if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime != 0 && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime > 0)
                        {
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime--;
                        }
                        ///////////////////////////
                        if (t.onStation)
                        {
                            if (t.Back)
                            {
                                rl.GetStations.ElementAt(t.id).Board.TrainOnStation(t.Number, true);
                            }
                            else
                            {
                                rl.GetStations.ElementAt(t.id).Board.TrainOnStation(t.Number, false);
                            }
                        }
                        if (t.leftStation)
                        {
                            if (t.Back)
                            {
                                rl.GetStations.ElementAt(t.id).Board.TrainLeft(true);
                            }
                            else
                            {
                                rl.GetStations.ElementAt(t.id).Board.TrainLeft(false);
                            }
                            t.leftStation = false;
                        }
                        //////////////////////////
                        if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start&& subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime == 0 && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation == 0)
                        {
                            if (!fieldCanvas.Children.Contains(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).TrainPath))
                            {
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Stop(fieldCanvas, subway);
                                fieldCanvas.Children.Add(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).TrainPath);
                            }
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).calcTime(subway, i, j);
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Animate(subway);
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).currStationInd < subway.GetRailways.ElementAt(i).GetStations.Count - 2)
                            {
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).currStationInd++;
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 3;
                            }
                            else
                            {
                                if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).numOfPassage != 1)
                                {
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).numOfPassage--;
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).away = true;
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).currStationInd++;
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 3;
                                }
                                else
                                {
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 3;
                                }
                            }
                        }
                        //////////////////////////////////////////
                    }
                }
            }
            AddTick(ref hour, ref min, ref sec);
        }
Beispiel #4
0
 public void addRailway(Railway rl)
 {
     _railways.Add(rl);
 }
Beispiel #5
0
 public void addRailway(Railway rl)
 {
     _railways.Add(rl);
 }
Beispiel #6
0
        private void tick(object sender, EventArgs e)
        {
            Railway rl = new Railway();
            Train t = new Train();
            for (int i = 0; i < subway.GetRailways.Count; i++)
            {
                rl = subway.GetRailways.ElementAt(i);
                for (int j = 0; j < subway.GetRailways.ElementAt(i).Trains.Count; j++)
                {
                    t = rl.Trains.ElementAt(j);
                    if (rl.GetStations.Count > 1)
                    {
                        ////////////////////////
                        if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime == 0 &&
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation != 0 || !subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start &&
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).DepartureTime == currentTime)
                        {
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).DepartureTime == currentTime)
                            {
                                if (!fieldCanvas.Children.Contains(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).TrainPath))
                                {
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Stop(fieldCanvas, subway);
                                    fieldCanvas.Children.Add(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).TrainPath);
                                }
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start = true;
                            }
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).onStation = true;
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation--;
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation != 0)
                            {
                                Random r = new Random(DateTime.Now.Millisecond);
                                if (r.Next(1, 100) % 55 == 0)
                                {
                                    String str = "Train number: " + subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Number + " went ahead by " + subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation + " seconds at the station: " + subway.GetRailways.ElementAt(i).Trains.ElementAt(j).id;
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 0;
                                    subway.GetRailways.ElementAt(i).GetStations.ElementAt(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).id).AddViolations(str);

                                }
                            }
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).away && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation == 0)
                            {
                                if (t.Back)
                                {
                                    rl.GetStations.ElementAt(t.id).Board.TrainLeft(true);
                                }
                                else
                                {
                                    rl.GetStations.ElementAt(t.id).Board.TrainLeft(false);
                                }
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Back = !subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Back;
                                if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).numOfPassage != 1)
                                {
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 3;
                                }
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).currStationInd = 0;
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).away = false;
                            }
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation == 0)
                            {
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).onStation = false;
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).leftStation = true;
                            }
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).SetCurrId(subway);
                        }
                        if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).numOfPassage == 1 &&
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime == 0 && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation == 0)
                        {
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start = false;
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Stop(fieldCanvas, subway);
                        }
                        /////////////////////////////////////
                        if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime != 0 && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime > 0)
                        {
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime--;
                        }
                        ///////////////////////////
                        if (t.onStation)
                        {
                            if (t.Back)
                            {
                                rl.GetStations.ElementAt(t.id).Board.TrainOnStation(t.Number, true);
                            }
                            else
                            {
                                rl.GetStations.ElementAt(t.id).Board.TrainOnStation(t.Number, false);
                            }
                        }
                        if (t.leftStation)
                        {
                            if (t.Back)
                            {
                                rl.GetStations.ElementAt(t.id).Board.TrainLeft(true);
                            }
                            else
                            {
                                rl.GetStations.ElementAt(t.id).Board.TrainLeft(false);
                            }
                            t.leftStation = false;
                        }
                        //////////////////////////
                        if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Start && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).travelTime == 0 && subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation == 0)
                        {
                            if (!fieldCanvas.Children.Contains(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).TrainPath))
                            {
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Stop(fieldCanvas, subway);
                                fieldCanvas.Children.Add(subway.GetRailways.ElementAt(i).Trains.ElementAt(j).TrainPath);
                            }
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).calcTime(subway, i, j);
                            subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Animate(subway);
                            if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).currStationInd < subway.GetRailways.ElementAt(i).GetStations.Count - 2)
                            {
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).currStationInd++;
                                subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 3;
                            }
                            else
                            {
                                if (subway.GetRailways.ElementAt(i).Trains.ElementAt(j).numOfPassage != 1)
                                {
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).numOfPassage--;
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).away = true;
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).currStationInd++;
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 3;
                                }
                                else
                                {
                                    subway.GetRailways.ElementAt(i).Trains.ElementAt(j).timeOnStation = 3;
                                }
                            }
                        }
                        //////////////////////////////////////////
                    }
                }
            }
            AddTick(ref hour, ref min, ref sec);
        }
Beispiel #7
0
 internal void AddSubwayLine(String name)
 {
     if (on)
     {
         Railway rl = new Railway(name);
         subway.addRailway(rl);
         SubwayLinesLBox.Items.Add(name);
     }
 }