private void button4_Click(object sender, EventArgs e) { Crossing c = new Crossing_2(); c.ID = "A0"; Car c2 = new Car(); c2.Crossing = c; // MessageBox.Show("Direction:" + c2.Street.Position.ToString()); c2.StreetIndex[0] = 1; //c2.Direction = Direction.West; c2.Street = c.StreetW; c2.StreetIndex[1] = 0; c2.HasEnteredGrid = true; c2.Crossing = c; c2.HasExitedGrid = false; drawCar(c2); }
/// <summary> /// Add a new crossing /// </summary> /// <param name="id">Grid position where crossing should be added</param> /// <param name="crossing">The type of crossing to add</param> /// <returns>If successful</returns> public bool addCrossing(string id, Type crossing) { try { Crossing c = this.Slots[(((int)id[0]) - (int)'A'), (int)id[1] - 48]; if (c != null) return false; if (crossing == typeof(Crossing_1)) c = new Crossing_1(id); else c = new Crossing_2(id); this.Slots[(((int)id[0]) - (int)'A'), (int)id[1] - 48] = c; return true; } catch { Console.WriteLine("Problems adding a crossing type " + crossing.ToString() + " at position " + id); return false; } }