Exemplo n.º 1
0
        public void MakeCity()
        {
            var file = new XmlDocument();

            file.LoadXml("<City>\n\n" +
                         "<Roads>\n<Road Start=\"3,10\" End=\"42,35\" Width=\"20\" MaxSpeed=\"50\"></Road>\n</Roads>\n\n" +
                         "<Buildings>\n<Building Location=\"12,42\" Size=\"5\"></Building>\n</Buildings>\n\n" +
                         "<Intersections>\n<Intersection Location =\"35,13\" Size=\"5\"></Intersection>\n</Intersections>\n\n" +
                         "</City>");

            var city = CityParser.MakeCity(file, "Test City");

            Assert.AreEqual(1, city.Roads.Count);
            Assert.AreEqual(1, city.Buildings.Count);

            Assert.AreEqual(new Vector(3, 10), city.Roads[0].Start);
            Assert.AreEqual(new Vector(42, 35), city.Roads[0].End);
            Assert.AreEqual(20, city.Roads[0].Width);
            Assert.AreEqual(50, city.Roads[0].MaxSpeed);

            Assert.AreEqual(new Vector(12, 42), city.Buildings[0].Location);
            Assert.AreEqual(5, city.Buildings[0].Size);
        }
Exemplo n.º 2
0
        public void LoadButtonClick()
        {
            // Loads the city file and parses the information into a City.
            var file = new XmlDocument();

            try
            {
                file.Load(SelectedFilePath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please select a City", "No city selected!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            try
            {
                var cityname = Screen.TBCity.Text;
                CityParser.MakeCity(file, cityname.First().ToString().ToUpper() + cityname.Substring(1));
            }
            catch (Exception ex)
            {
                MessageBox.Show("There is an error in the city file.", "Invalid City File", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var city = CitySystem.City.Instance;

            Screen.CityRenderHandler.DrawCity(city);

            Screen.PropertyDisplayHandler.UpdateProperties();

            EnableButtonsAndTabs();
            UpdateCountLabels(city);

            SimulationLoad?.Invoke(this, new SimulationEventArgs(CitySystem.City.Instance));
        }