コード例 #1
0
 /// <summary>
 /// Remove train from old rail and Add train to new rail
 /// </summary>
 /// <param name="rail">new rail</param>
 public void SetRail(Rail rail)
 {
     this.rail.RemoveTrain(this);
     this.rail.AddWagon(wagons, wagons[0]);
     this.rail = rail;
     this.rail.AddTrain(this);
 }
コード例 #2
0
        /// <summary>
        /// Checks if the waittime for a specific train in this station is over and decreases the current waittime for that train
        /// </summary>
        /// <param name="train">Train object to check for</param>
        /// <returns>true if Waittime is over</returns>
        public bool ReadytoDepart(Train train)
        {
            int length = rails.GetLength(0) * rails.GetLength(1);

            Rail[] allRails = new Rail[length];

            for (int ri = 0; ri < rails.GetLength(0); ri++)
            {
                for (int r = 0; r < rails.GetLength(1); r++)
                {
                    allRails[(ri * rails.GetLength(1)) + r] = rails[ri, r];
                }
            }



            if (train.NeedsToGoForward() && train.GetRail() != rails[1, 0])
            {
                MoveTrain(train, allRails);
                return(false);
            }
            else if (!train.NeedsToGoForward() && train.GetRail() != rails[0, 0])
            {
                MoveTrain(train, allRails);
                return(false);
            }

            trainWaitTime[trains.IndexOf(train)]--;
            return(trainWaitTime[trains.IndexOf(train)] < 0);
        }
コード例 #3
0
        /// <summary>
        /// Checks if this Rail is safe to enter for specific train.
        /// </summary>
        /// <returns>true if Rail is safe</returns>
        public bool IsClear()
        {
            bool clear = true;

            if (trains.Count > 0)
            {
                clear = false;
                if (station != null)
                {
                    if (station.CentralStation())
                    {
                        clear = true;
                    }
                }
            }
            if (wagons.Count > 0)
            {
                clear = false;
                Rail rail = wagons[0].Gettrain().GetRail();
                if (rail.GetStation() != null)
                {
                    if (rail.GetStation().CentralStation())
                    {
                        clear = true;
                    }
                }
            }
            return(clear);
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: LuukdeKinderen/S1Proftaak2
        private string GenerateHexString(Rail[,] rails)
        {
            Rail[] allRails = new Rail[240];
            for (int ri = 0; ri < rails.GetLength(0); ri++)
            {
                for (int r = 0; r < rails.GetLength(1); r++)
                {
                    allRails[(ri * rails.GetLength(1)) + r] = rails[ri, r];
                }
            }

            string longString = "FxFF 9 ";



            for (int i = 0; i < allRails.Length; i++)
            {
                if (allRails[i].GetTrains().Count > 0)
                {
                    Color c = allRails[i].GetTrains()[0].GetColor();
                    longString += i.ToString("000") + c.R.ToString("000") + c.G.ToString("000") + c.B.ToString("000");
                }
                else if (allRails[i].GetWagon() != null)
                {
                    Color c = allRails[i].GetWagon().GetColor();
                    longString += i.ToString("000") + c.R.ToString("000") + c.G.ToString("000") + c.B.ToString("000");
                }
            }


            longString += "~";
            return(longString);
        }
コード例 #5
0
        public TrainBehaviour()
        {
            for (int ri = 0; ri < rails.GetLength(0); ri++)
            {
                for (int r = 0; r < rails.GetLength(1); r++)
                {
                    rails[ri, r] = new Rail(ri, r);
                }
            }



            stations.Add(new Station("Christopher laan", true, 0, rails));
            stations.Add(new Station("Knap Ford", false, 20, rails));
            stations.Add(new Station("Frow Tastic", true, 46, rails));
            stations.Add(new Station("Burgemeester v. Hoofdstraat", false, 70, rails));
            stations.Add(new Station("Blauwe Reiger", false, 90, rails));
            stations.Add(new Station("Jethoe Plein", true, 116, rails));



            trains.Add(new Train("I1", Color.FromArgb(255, 0, 0), true, new Station[] { stations[0], stations[2], stations[5], stations[2], stations[0] }));
            trains.Add(new Train("I2", Color.FromArgb(255, 255, 0), true, new Station[] { stations[5], stations[2], stations[0], stations[2], stations[5] }));
            trains.Add(new Train("S1", Color.FromArgb(0, 255, 0), false, new Station[] { stations[0], stations[1], stations[2], stations[1], stations[0] }));
            trains.Add(new Train("S2", Color.FromArgb(0, 0, 255), false, new Station[] { stations[2], stations[3], stations[4], stations[5], stations[4], stations[3], stations[2] }));
        }
コード例 #6
0
        public Wagon(Rail rail, Train trian)
        {
            Random r = new Random();

            SetRandomCroudLevel(r.Next(0, 3));
            this.rail  = rail;
            this.train = trian;
        }
コード例 #7
0
ファイル: Train.cs プロジェクト: RobinvHoof/Proftaak2
 /// <summary>
 /// Constructs a new Train object
 /// </summary>
 /// <param name="name">name of the new Train</param>
 /// <param name="intercity">When true => new Train is intercity</param>
 /// <param name="route">Array of stations to cover on full train cycle, please include return</param>
 /// <param name="rail">Rail to start on</param>
 public Train(string name, string HEX, bool intercity, Station[] route, Rail rail)
 {
     this.name      = name;
     this.HEX       = HEX;
     this.intercity = intercity;
     this.route     = route;
     this.rail      = rail;
 }
コード例 #8
0
        public void AddWagon(Wagon[] wagons, Wagon wagon)
        {
            int  index   = Array.IndexOf(wagons, wagon);
            Rail oldRail = wagon.GetRail();

            wagon.SetRail(this);
            this.wagons.Add(wagon);

            index++;
            if (index != wagons.Length)
            {
                oldRail.AddWagon(wagons, wagons[index]);
            }

            oldRail.RemoveWagon(wagons[index - 1]);
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: RobinvHoof/Proftaak2
        private string GenerateHexString(Rail[,] rails)
        {
            Rail[] allRails = new Rail[240];
            for (int ri = 0; ri < rails.GetLength(0); ri++)
            {
                for (int r = 0; r < rails.GetLength(1); r++)
                {
                    allRails[(ri * rails.GetLength(1)) + r] = rails[ri, r];
                }
            }

            string longString = "FxFF 9 ";

            string[] hex = new string[240];
            for (int i = 0; i < hex.Length; i++)
            {
                hex[i] = "000000";
            }


            for (int i = 0; i < allRails.Length; i++)
            {
                if (allRails[i].GetTrains().Count > 0)
                {
                    hex[i] = allRails[i].GetTrains()[0].GetHEX();
                }
            }

            for (int i = 0; i < hex.Length; i++)
            {
                if (prevHex[i] != hex[i])
                {
                    longString += i.ToString("000") + hex[i];
                }
                else
                {
                    //longString += "zzzzzz";
                }
            }

            longString += "~";
            prevHex     = hex;
            return(longString);
        }
コード例 #10
0
/// <summary>
/// Creates a train object
/// </summary>
/// <param name="name"></param>
/// <param name="color"></param>
/// <param name="intercity"></param>
/// <param name="route"></param>
        public Train(string name, Color color, bool intercity, Station[] route)
        {
            this.name      = name;
            this.color     = color;
            this.intercity = intercity;
            this.route     = route;
            rail           = route[0].GetRail();

            if (intercity)
            {
                wagons = new Wagon[3];
            }
            else
            {
                wagons = new Wagon[2];
            }


            for (int w = 0; w < wagons.Length; w++)
            {
                wagons[w] = new Wagon(rail, this);
            }
        }
コード例 #11
0
        public TrainBehaviour()
        {
            for (int ri = 0; ri < rails.GetLength(0); ri++)
            {
                for (int r = 0; r < rails.GetLength(1); r++)
                {
                    rails[ri, r] = new Rail(ri, r);
                }
            }


            stations.Add(new Station("CL", true, new Rail[, ] {
                { rails[0, 0], rails[0, 1], rails[0, 2], rails[0, 3] }, { rails[1, 3], rails[1, 2], rails[1, 1], rails[1, 0] }
            }));
            stations.Add(new Station("KF", false, new Rail[, ] {
                { rails[0, 20], rails[0, 21], rails[0, 22], rails[0, 23] }, { rails[1, 23], rails[1, 22], rails[1, 21], rails[1, 20] }
            }));
            stations.Add(new Station("FR", true, new Rail[, ] {
                { rails[0, 50], rails[0, 51], rails[0, 52], rails[0, 53] }, { rails[1, 53], rails[1, 52], rails[1, 51], rails[1, 50] }
            }));
            stations.Add(new Station("BH", false, new Rail[, ] {
                { rails[0, 70], rails[0, 71], rails[0, 72], rails[0, 73] }, { rails[1, 73], rails[1, 72], rails[1, 71], rails[1, 70] }
            }));
            stations.Add(new Station("BR", false, new Rail[, ] {
                { rails[0, 90], rails[0, 91], rails[0, 92], rails[0, 93] }, { rails[1, 93], rails[1, 92], rails[1, 91], rails[1, 90] }
            }));
            stations.Add(new Station("JP", true, new Rail[, ] {
                { rails[0, 116], rails[0, 117], rails[0, 118], rails[0, 119] }, { rails[1, 119], rails[1, 118], rails[1, 117], rails[1, 116] }
            }));



            trains.Add(new Train("I1", "ff9500", true, new Station[] { stations[0], stations[2], stations[5], stations[2], stations[0] }, rails[0, 0]));
            trains.Add(new Train("I2", "fff200", true, new Station[] { stations[5], stations[2], stations[0], stations[2], stations[5] }, rails[1, 116]));
            trains.Add(new Train("S1", "0004ff", false, new Station[] { stations[0], stations[1], stations[2], stations[1], stations[0] }, rails[0, 0]));
            trains.Add(new Train("S2", "00d5ff", false, new Station[] { stations[2], stations[3], stations[4], stations[5], stations[4], stations[3], stations[2] }, rails[0, 50]));
        }
コード例 #12
0
 public void SetRail(Rail rail)
 {
     this.rail = rail;
 }
コード例 #13
0
ファイル: Train.cs プロジェクト: RobinvHoof/Proftaak2
 /// <summary>
 /// Remove train from old rail and Add train to new rail
 /// </summary>
 /// <param name="rail">new rail</param>
 public void SetRail(Rail rail)
 {
     this.rail.RemoveTrain(this);
     this.rail = rail;
     this.rail.AddTrain(this);
 }