Пример #1
0
        // beginning of program
        private void Generator()
        {
            printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);


            btnMutate.Enabled = true;
            ClearForm();

            // refreshes lists
            Animal.NewAnimals();
            Powers.NewPowers();
            Paths.NewPaths();
            Gifts.NewGifts();
            Background.NewBackgrounds();
            Skills.NewSkills();
            Story.NewStories();

            // creates new blank character
            _character = Character.CreateDefaultCharacter();

            // roll stats, background, skills and story
            _character.IsPhysical = Dice.FlipCoin();
            _character.Stats      = Dice.RollStats(_character.IsPhysical, _character.Stats);
            _character.Sanity     = _character.Stats["Intelligence"] + _character.Stats["Willpower"];
            _character.Background = Background.ChooseBackground(_character.IsPhysical, _character.Background);
            _character.Skills     = Skills.AssignSkills(_character.Background.Skills, _character.Skills, _character.Background.SkillsLimit);
            _character.Story      = Story.ChooseStory(_character.Background.ID);

            DisplayHuman();
        }
        public IActionResult GetBackground()
        {
            string       path = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, @"GeoIPDB/GeoLite2-City.mmdb");
            CityResponse city = new CityResponse()
            {
            };

            using (var reader = new DatabaseReader(path))
            {
                var ip = _accessor.ActionContext.HttpContext.Connection.RemoteIpAddress.ToString();
                city = reader.City(ip);
            }

            //Assign API KEY which received from OPENWEATHERMAP.ORG
            string appId = "51484507182468c91ba33387b57568d8";
            //API path with CITY parameter and other parameters.
            string     url        = "http://api.openweathermap.org/data/2.5/weather?q=" + city.City + "&units=metric&cnt=1&APPID=" + appId;
            Background background = new Background()
            {
            };

            using (WebClient client = new WebClient())
            {
                string json = client.DownloadString(url);

                WeatherAPIViewModel weatherInfo = (new JavaScriptSerializer()).Deserialize <WeatherAPIViewModel>(json);

                background.ChooseBackground(weatherInfo.weather[0].main);
            }
            if (city.City == null)
            {
                return(Json(new { success = false, BackgroundImageUrl = background.GetBackground() }));
            }
            return(Json(new { success = true, backgroundImageUrl = background.GetBackground() }));
        }