private IList <Point> FindOpenPositions(IList <Point> roads, CityMap city)
        {
            // TODO: This function has an O(n^2) computation power which is likely too slow. Some kind of caching might be useful.
            var list = new List <Point>();

            foreach (var roadPos in roads)
            {
                var rX = roadPos.X;
                var rY = roadPos.Y;

                var xMin = Math.Max(city.IsRoad(rX - 1, rY) ? rX : rX - 3, 0);
                var xMax = Math.Min(city.IsRoad(rX + 1, rY) ? rX : rX + 3, city.SizeX - 1);
                var yMin = Math.Max(city.IsRoad(rX, rY - 1) ? rY : rY - 3, 0);
                var yMax = Math.Min(city.IsRoad(rX, rY + 1) ? rY : rY + 3, city.SizeY - 1);

                for (var x = xMin; x <= xMax; x++)
                {
                    for (var y = yMin; y <= yMax; y++)
                    {
                        if (city.Terrain[x, y].ZoneId == _zone.Id && city.Terrain[x, y].Building == null)
                        {
                            list.Add(new Point(x, y));
                        }
                    }
                }
            }

            return(list.Distinct().ToList());
        }
        static void Main(string[] args)
        {
            CityMap map = new CityMap();

            initializeCityMap(map);
            searchConsole(map);
        }
        private void PlaceBuildings(CityMap city, int count)
        {
            if (count == 0)
            {
                return;
            }

            var roadNetwork   = FindRoadNetwork(city);
            var openPositions = FindOpenPositions(roadNetwork, city);

            for (var i = 0; i < count; i++)
            {
                if (!openPositions.Any())
                {
                    return;
                }

                // TODO: Maybe multiple positions should be evaluated and the best be chosen. Experiment with it.
                var id  = _rnd.Next(openPositions.Count);
                var pos = openPositions[id];

                // TODO: This should be buildings chosen by the actor, not the zone.
                city.PlaceBuilding(pos, _zone.GetRandom(_rnd));

                openPositions.RemoveAt(id);
            }
        }
        public void FindShortWayTest()
        {
            var a = new CityPlace(new Coordinate(0, 0));
            var b = new CityPlace(new Coordinate(1, 4));
            var c = new CityPlace(new Coordinate(2, -1));
            var d = new CityPlace(new Coordinate(5, -1));
            var e = new CityPlace(new Coordinate(6, 4));

            var ac = new SelfWeightedCityRoad(a, c, 2);
            var ab = new SelfWeightedCityRoad(a, b, 5);
            var cb = new SelfWeightedCityRoad(c, b, 2);
            var cd = new SelfWeightedCityRoad(c, d, 6);
            var be = new SelfWeightedCityRoad(b, e, 7);
            var de = new SelfWeightedCityRoad(d, e, 1);

            var cityPlaces = new HashSet <ICityPlace> {
                a, b, c, d, e
            };
            var cityRoads = new HashSet <ICityRoad> {
                ac, ab, cb, cd, be, de
            };
            var cityMap = new CityMap(cityPlaces, cityRoads);

            var resolver = new DijkstraResolver();
            var resolve  = resolver.Resolve(cityMap, a);

            var expected = new Route(a, e, new [] { ac, cd, de });
            var actual   = resolve.FindShortRouteTo(e);

            Assert.Equal(expected.Start, actual.Start);
            Assert.Equal(expected.End, actual.End);
            Assert.Equal(expected.Roads, actual.Roads);
        }
        private async void FindADrink(object sender, EventArgs e)
        {
            HttpClient httpClient = new HttpClient();
            string     baseUrl    = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=";
            string     apiKey     = "{API_KEY}";
            var        result     = await httpClient.GetAsync(baseUrl + location.Latitude + "," + location.Longitude + "&radius=1000&type=bar&key=" + apiKey);

            var responseString = await result.Content.ReadAsStringAsync();

            var    responseObject = JsonConvert.DeserializeObject <RouteModel>(responseString);
            Random random         = new Random();
            var    randomNumber   = random.Next(0, responseObject.results.Count - 1);

            location = new Xamarin.Essentials.Location(responseObject.results[randomNumber].geometry.location.lat, responseObject.results[randomNumber].geometry.location.lng);
            Position position = new Position(location.Latitude, location.Longitude);

            barName = responseObject.results[randomNumber].name;
            MapSpan mapSpan = new MapSpan(position, 0.01, 0.01);
            Pin     pin     = new Pin
            {
                Label    = barName,
                Address  = responseObject.results[randomNumber].vicinity,
                Type     = PinType.Place,
                Position = position
            };

            CityMap.MoveToRegion(mapSpan);
            ResultLabel.Text = "YOUR NEXT DRINK IS AT: " + barName;
            CityMap.Pins.Clear();
            CityMap.Pins.Add(pin);
            RouteButton.IsVisible = true;
        }
 public static void initializeCityMap(CityMap map)
 {
     map.addCity("MUM", "Mumbai");
     map.addCity("ST", "Surat");
     map.addCity("VAPI", "Vapi");
     map.addCity("MON", "Monali");
     map.addCity("MAL", "Malad");
 }
        async void OnStartup()
        {
            //var request = new GeolocationRequest(GeolocationAccuracy.Best);
            //location = await Geolocation.GetLocationAsync(request);
            location = new Xamarin.Essentials.Location(50.1118331, 8.6608024);
            Position position = new Position(location.Latitude, location.Longitude);
            MapSpan  mapSpan  = new MapSpan(position, 0.01, 0.01);

            CityMap.MoveToRegion(mapSpan);
        }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameMode"/> class.
 /// </summary>
 public GameMode(Device Device)
 {
     this.Device      = Device;
     this.Time        = new Time();
     this.Random      = new Random();
     this.Office      = new Office();
     this.CityMap     = new CityMap(this);
     this.Puzzle      = new Puzzle(this);
     this.EnergyTimer = new EnergyTimer(this);
 }
Exemple #9
0
 public CityMapDTO(CityMap cityMap)
 {
     Id          = cityMap.Id;
     CityMapType = new CityMapTypeDTO(cityMap.CityMapType);
     CityMapZone = new CityMapZoneDTO(cityMap.CityMapZone);
     XCoordinate = cityMap.XCoordinate;
     YCoordinate = cityMap.YCoordinate;
     Name        = cityMap.Name;
     Level       = cityMap.Level;
 }
        public void Update(CityMap city)
        {
            // TODO: Growth factor should depend on extra variables.
            var growthFactor = 0.15f;

            var count = Math.Floor(_rnd.NextDouble() + growthFactor);

            PlaceBuildings(city, (int)count);

            // TODO: Building decay
        }
Exemple #11
0
        public MapWrapper generateWrapperFromMap(CityMap map)
        {
            MapWrapper wrapper = new MapWrapper();

            wrapper.cities = new List <CityWrapper>();
            foreach (City city in map.Cities)
            {
                wrapper.cities.Add(generateWrapperFromCity(city));
            }
            return(wrapper);
        }
Exemple #12
0
        private IEnumerable <CityMap> GetCityMapFromDatatable(DataTable dt)
        {
            List <CityMap> maps = new List <CityMap>();

            foreach (DataRow row in dt.Rows)
            {
                CityMap map = GetCityMapFromDataRow(row);
                maps.Add(map);
            }

            return(maps);
        }
Exemple #13
0
        public CityMap generateMapFromWrapper(MapWrapper wrapper)
        {
            CityMap map = new CityMap();

            foreach (CityWrapper city in wrapper.cities)
            {
                Army tempArmy = generateArmyFromWrapper(city.army);
                City temp     = new City(map, new Microsoft.Xna.Framework.Point(city.xPosition, city.yPosition), city.name, tempArmy.Owner);
                temp.SetStationedArmy(tempArmy);
                //map.Cities.Add(temp);
            }
            return(map);
        }
Exemple #14
0
        public static List <Tool> GetTools(CityMap city, ZoneManager zones)
        {
            var list = new List <Tool>();

            list.Add(new TileTool(new RectangeAreaSelector(), new PlaceZoneEffect(city, zones[0])));
            list.Add(new TileTool(new RectangeAreaSelector(), new PlaceZoneEffect(city, zones[1])));
            list.Add(new TileTool(new RectangeAreaSelector(), new PlaceZoneEffect(city, zones[2])));
            list.Add(new TileTool(new RectangeAreaSelector(), new PlaceZoneEffect(city, zones[3])));

            list.Add(new TileTool(new LineAreaSelector(), new PlaceRoadEffect(city, zones[4])));
            list.Add(new TileTool(new RectangeAreaSelector(), new DestroyEffect(city)));

            return(list);
        }
        public Mesh GenerateMesh(Building building, CityMap map)
        {
            var factory = new Mesh.Factory();

            var plan = _planGenerator.Generate(building.Pos + new Vector2(0.5f, 0.5f), building.Type.Size);

            plan.NumFloors = _rnd.Next(1, 3);

            UpdateHeights(plan, map.HeightMap);

            _wallGenerator.CreateWalls(factory, plan);
            _roofGenerator.CreateRoof(factory, plan);

            return(factory.ToMesh());
        }
Exemple #16
0
        public void resetGame()
        {
            PlayerArmy  = new Army("Player");
            SelectedMap = new CityMap();
            EnemyArmy   = null;

            Unit firstUnit = new Unit();

            PlayerArmy.addUnit(firstUnit);
            PlayerArmy.addUnit(new Unit(UnitType.Miku));
            for (int i = 0; i < 10; i++)
            {
                PlayerArmy.addUnit(new Unit());
            }
            PlayerArmy.squads[0, 0].addUnit(0, firstUnit);
        }
        public static void searchConsole(CityMap map)
        {
            bool isExit = false;

            Console.WriteLine("Search Console Started for Map....");

            while (!isExit)
            {
                Console.WriteLine("Select Any Option Below: "
                                  + "\n    1. to Search"
                                  + "\n    2. Quit"
                                  + "\n    Enter Your Choice: ");

                int       choice = 0;
                const int ADD = 1, QUIT = 2;

                choice = Convert.ToInt32(Console.ReadLine());

                switch (choice)
                {
                case ADD:
                    Console.WriteLine("Enter City Code: ");
                    string cityCode = Console.ReadLine();

                    Dictionary <City, City> cityMap = map.search(cityCode);

                    Console.WriteLine("Cities BELOW: ");

                    foreach (KeyValuePair <City, City> city in cityMap)
                    {
                        Console.WriteLine(city.Value);
                    }

                    break;

                case QUIT:
                    Console.WriteLine("The Program is now closed....!!");
                    isExit = true;
                    break;

                default:
                    Console.WriteLine("You Have toSelect an Option");
                    break;
                }
            }
        }
        private IList <Point> FindRoadNetwork(CityMap city)
        {
            // TODO: This function has an O(n^2) computation power which is likely too slow. Some kind of caching might be useful.
            var list = new List <Point>();

            for (var x = 0; x < city.SizeX; x++)
            {
                for (var y = 0; y < city.SizeX; y++)
                {
                    if (city.IsRoad(x, y))
                    {
                        list.Add(new Point(x, y));
                    }
                }
            }
            return(list);
        }
Exemple #19
0
    void ReadMap(string _Line, int _Count)
    {
        //int m_J = 0;

        for (int m_I = 0; m_I < _Line.Length; m_I++)
        {
            m_TempMap             = new CityMap();
            m_TempMap.m_Coor.x    = m_I;
            m_TempMap.m_Coor.y    = _Count;
            m_TempMap.m_Character = _Line[m_I];

            m_TempMap.m_Colour   = Color.grey;
            m_TempMap.m_Rotation = Random.Range(0, 4);

            m_Map.Add(m_TempMap);
        }
    }
Exemple #20
0
        /// <summary>
        ///  Searches for cities that match the given cityName, countryCode and countyName,
        ///  returning a list of matching cities.
        /// </summary>
        /// <param name="cityName">Mandatory. Name of the city to search for.</param>
        /// <param name="countryCode">Optional. Two letter country code for the city to search for.</param>
        /// <param name="countryName">Optional. Name of the country to search for. </param>
        public async Task <IList <City> > SearchForCities(string cityName, string countryCode = null,
                                                          string countryName = null)
        {
            string requestUri = string.Empty;

            if (countryCode == null && countryName != null)
            {
                GlobalizationHelper globalizationHelper = new GlobalizationHelper();
                countryCode = globalizationHelper.GetCountryCode(countryName);
            }

            if (countryCode != null)
            {
                requestUri = $"{_serachBaseUrl}{cityName},{countryCode}&type=like&appid={_searchApiKey}";
            }
            else
            {
                requestUri = $"{_serachBaseUrl}{cityName}&type=like&appid={_searchApiKey}";
            }

            HttpClient client = new HttpClient {
                BaseAddress = new Uri(requestUri)
            };

            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await client.GetAsync(requestUri);

            if (response.IsSuccessStatusCode)
            {
                string responseJsonString = await response.Content.ReadAsStringAsync();

                WeatherSearchResultDto deserializedProduct = JsonConvert.DeserializeObject <WeatherSearchResultDto>(responseJsonString);

                IDomainMapper <WeatherSearchResultDto, IList <City> > cityMapper = new CityMap();
                IList <City> cityList = cityMapper.MapTo(deserializedProduct);

                return(cityList);
            }

            return(null);
        }
Exemple #21
0
        private void TryFillCity(ExchangeAddressDetail detail, AddressDetail addressDetail)
        {
            if (string.IsNullOrEmpty(detail.CityName))
            {
                return;
            }
            var citiesValue = CityMap.Where(e => e.Key.CityName == detail.CityName).ToList();

            if (!citiesValue.Any())
            {
                return;
            }
            if (citiesValue.Count() == 1)
            {
                FillAddressDetail(addressDetail, citiesValue.First().Value);
                return;
            }
            if (string.IsNullOrEmpty(detail.RegionName))
            {
                return;
            }
            citiesValue = citiesValue.Where(e => e.Key.RegionNameConfig.RegionName == detail.RegionName).ToList();
            if (!citiesValue.Any())
            {
                return;
            }
            if (citiesValue.Count() == 1)
            {
                FillAddressDetail(addressDetail, citiesValue.First().Value);
                return;
            }
            if (string.IsNullOrEmpty(detail.CountryName))
            {
                return;
            }
            citiesValue = citiesValue.Where(e => e.Key.RegionNameConfig.CountryName == detail.CountryName).ToList();
            if (citiesValue.Count() == 1)
            {
                FillAddressDetail(addressDetail, citiesValue.First().Value);
            }
        }
        /// <summary>
        /// Находит ближайший путь до указанного местоположения.
        /// </summary>
        /// <param name="cityPlace">Местоположение до которого необходимо получить ближайший путь.</param>
        /// <returns>Путь <see cref="IRoute"/>.</returns>
        public IRoute FindShortRouteTo(ICityPlace cityPlace)
        {
            if (!CityMap.Places.Contains(cityPlace))
            {
                throw new ArgumentException("Местоположение не относится к текущему городу.");
            }

            var roads = new List <ICityRoad>();

            var vertex = _dijkstraVertices.GetDijkstraVertex(cityPlace);

            while (vertex.CityPlace != StartPlace)
            {
                var road = CityMap.GetRoadBetween(vertex.CityPlace, vertex.PreviousCityPlace);
                roads.Add(road);
                vertex = _dijkstraVertices.GetDijkstraVertex(vertex.PreviousCityPlace);
            }

            roads.Reverse();
            return(new Route(StartPlace, cityPlace, roads));
        }
Exemple #23
0
        public static Scene MainScene()
        {
            Scene newScene = new Scene("MainScene");

            var map = new CityMap(128, 72);

            var zoomIndicator = new UIFadingLabel()
            {
                Text     = "10x",
                Color    = Color.White,
                FontSize = 48,
                FadeTime = 1f
            };

            zoomIndicator.RectTransform.Rect = new Rectangle(1150, 0, 100, 100);
            map.ZoomIndicator = zoomIndicator;

            newScene.AddComponent(map);
            newScene.AddComponent(zoomIndicator);

            return(newScene);
        }
Exemple #24
0
        public TkCityRenderer(CityMap cityMap)
        {
            _cityMap = cityMap;

            _heightMapMesh         = _cityMap.HeightMap.ToMesh();
            _heightMapMesh.Texture = Program.TextureCache["grass.png"];

            var waterMeshFactory = new Mesh.Factory();

            waterMeshFactory.AddSurface(
                new Mesh.Vertex {
                Pos = Vector3.Zero, Normal = Vector3.UnitY, TexCoords = Vector2.Zero
            },
                new Mesh.Vertex {
                Pos = new Vector3(0, 0, 128), TexCoords = new Vector2(0, 32)
            },
                new Mesh.Vertex {
                Pos = new Vector3(128, 0, 0), TexCoords = new Vector2(32, 0)
            });

            _waterMesh         = waterMeshFactory.ToMesh();
            _waterMesh.Texture = Program.TextureCache["water.png"];
        }
Exemple #25
0
        private CityMap GetCityMapFromDataRow(DataRow row)
        {
            // TODO: refactor
            CityMapType cityMapType = new CityMapType(
                Convert.ToInt32(row["CityMapTypeId"].ToString()),
                row["CityMapTypeName"].ToString(),
                row["CityMapTypeOfficialName"].ToString(),
                row["CityMapTypeFictionalName"].ToString()
                );

            CityMapType zoneCityMapType = new CityMapType(
                Convert.ToInt32(row["ZoneMapTypeId"].ToString()),
                row["ZoneMapTypeName"].ToString(),
                row["ZoneMapTypeOfficialName"].ToString(),
                row["ZoneMapTypeFictionaleName"].ToString()
                );

            CityMapZone cityMapZone = new CityMapZone(
                Convert.ToInt32(row["CityMapZoneId"].ToString()),
                row["CityMapZoneName"].ToString(),
                row["CityMapZoneOfficialName"].ToString(),
                row["CityMapZoneFictionalName"].ToString(),
                zoneCityMapType
                );

            CityMap city = new CityMap(
                Convert.ToInt32(row["Id"].ToString()),
                cityMapType,
                cityMapZone,
                Convert.ToInt32(row["XCoordinate"].ToString()),
                Convert.ToInt32(row["YCoordinate"].ToString()),
                row["Name"].ToString(),
                Convert.ToInt32(row["Level"].ToString())
                );

            return(city);
        }
Exemple #26
0
 public PlaceRoadEffect(CityMap city, ZoneType zone)
 {
     _city = city;
     _zone = zone;
 }
Exemple #27
0
 public Route(CityMap cities)
 {
     this.cities = cities;
     Initialize();
 }
Exemple #28
0
 public DestroyEffect(CityMap city)
 {
     _city = city;
 }
Exemple #29
0
        public int GetPrice(CityMap map, ushort x, ushort y)
        {
            //TODO: Work on this scheme
            var terrain   = map.GetTerrain(x, y);
            var basePrice = 3000;

            switch (terrain)
            {
            case TerrainType.GRASS:
                basePrice += 1000;
                break;

            case TerrainType.SAND:
            case TerrainType.SNOW:
                basePrice += 2000;
                break;
            }

            var price = basePrice;

            //Altitude increase price
            var elevation = map.GetElevation(x, y);

            //$19 for each elevation increment
            price += (19 * elevation);

            //+2500 for every water edge
            var leftLocation = MapCoordinates.Offset(new MapCoordinate(x, y), -1, 0);
            var leftTerrain  = map.GetTerrain(leftLocation.X, leftLocation.Y);

            var rightLocation = MapCoordinates.Offset(new MapCoordinate(x, y), 1, 0);
            var rightTerrain  = map.GetTerrain(rightLocation.X, rightLocation.Y);

            var topLocation = MapCoordinates.Offset(new MapCoordinate(x, y), 0, -1);
            var topTerrain  = map.GetTerrain(topLocation.X, topLocation.Y);

            var bottomLocation = MapCoordinates.Offset(new MapCoordinate(x, y), 0, 1);
            var bottomTerrain  = map.GetTerrain(bottomLocation.X, bottomLocation.Y);

            if (leftTerrain == TerrainType.WATER)
            {
                price += 5000;
            }
            if (rightTerrain == TerrainType.WATER)
            {
                price += 5000;
            }
            if (topTerrain == TerrainType.WATER)
            {
                price += 5000;
            }
            if (bottomTerrain == TerrainType.WATER)
            {
                price += 5000;
            }

            //Extra for an island
            if (bottomTerrain == TerrainType.WATER && topTerrain == TerrainType.WATER &&
                leftTerrain == TerrainType.WATER && rightTerrain == TerrainType.WATER)
            {
                price += 10000;
            }

            return(price);
        }
Exemple #30
0
 public ShardRealestateDomain(ShardStatusItem shard, CityMap map)
 {
     _Map = map;
     //TODO: Hardcore
     _Pricing = new BasicLotPricingStrategy();
 }
Exemple #31
0
 public PlayerInfo(Army playerArmy, CityMap cityMap)
 {
     PlayerArmy  = playerArmy;
     SelectedMap = cityMap;
     EnemyArmy   = null;
 }