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]); }
private void DrawRails(Rail[,] rails) { for (int ri = 0; ri < rails.GetLength(0); ri++) { for (int r = 0; r < rails.GetLength(1); r++) { if (rails[ri, r].GetTrains().Count > 0) { PictureBox p = (PictureBox)tableLayoutPanel1.GetControlFromPosition(r, ri); Train train = rails[ri, r].GetTrains()[0]; p.BackColor = train.GetColor(); } else if (rails[ri, r].GetWagon() != null) { PictureBox p = (PictureBox)tableLayoutPanel1.GetControlFromPosition(r, ri); Wagon wagon = rails[ri, r].GetWagon(); p.BackColor = wagon.GetColor(); } else if (rails[ri, r].GetStation() != null) { PictureBox p = (PictureBox)tableLayoutPanel1.GetControlFromPosition(r, ri); if (rails[ri, r].GetStation().CentralStation()) { p.BackColor = System.Drawing.ColorTranslator.FromHtml("#4a4a4a"); } else { p.BackColor = System.Drawing.ColorTranslator.FromHtml("#878787"); } } else { PictureBox p = (PictureBox)tableLayoutPanel1.GetControlFromPosition(r, ri); p.BackColor = System.Drawing.SystemColors.Control; } } } }
/// <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); } }
private void RemoveWagon(Wagon wagon) { wagons.Remove(wagon); }