private void DeletePokeImage(MyPokemon pokemon)
 {
     if (!string.IsNullOrWhiteSpace(pokemon?.ImgUrl))
     {
         string deletePath = Path.Combine(_env.WebRootPath, "images", "PokeImages", pokemon?.ImgUrl);
         System.IO.File.Delete(deletePath);
     }
 }
        // create logic should be done
        #region create
        // GET: Pokemons/Create
        public ActionResult Create()
        {
            var pokemon         = new MyPokemon();
            var pokemonCreateVm = new PokemonCreateVm();

            pokemon.PokemonTypes = new List <PokemonType>();
            PopulateAssignedTypeData(pokemon);

            return(View(pokemonCreateVm));
        }
    void Start()
    {
        // set health
        eHealth = 100;
        eMana   = 100;

        HealthText = TextUI.GetComponent <Text>();
        ManaText   = ManaUI.GetComponent <Text>();


        // set player reference
        mypokemonRef = playerRef.gameObject.GetComponent <MyPokemon>();

        // flag for attacked
        attacked = false;

        // set sprite randomly
        spriteRenderer = GetComponent <SpriteRenderer>();
        float random = Random.Range(1, 7);

        if (random <= 2)
        {
            spriteRenderer.sprite = Resources.Load <Sprite>("Avatars/gyarados");
        }
        else if (random <= 4)
        {
            spriteRenderer.sprite = Resources.Load <Sprite>("Avatars/omastar");
        }
        else if (random <= 6)
        {
            spriteRenderer.sprite = Resources.Load <Sprite>("Avatars/basculin");
        }



        // Abilities
        AbilityList   = new List <Ability>();
        BubbleAbility = new Ability("Bubble", 60);
        AbilityList.Add(BubbleAbility);
        ThunderAbility = new Ability("Thunder", 20);
        AbilityList.Add(ThunderAbility);
        Explosion = new Ability("Explosion", 20);
        AbilityList.Add(Explosion);
        foreach (var item in AbilityList)
        {
            totalweight += item.Weight;
        }
        Debug.Log(totalweight);
    }
        private void UpdatePokemonTypes(string[] selectedTypes, MyPokemon pokemonToUpdate)
        {
            if (selectedTypes == null)
            {
                pokemonToUpdate.PokemonTypes = new List <PokemonType>();
                return;
            }
            var selectedPokemonHS = new HashSet <string>(selectedTypes);

            IEnumerable <Guid> pokemonTypes = pokemonToUpdate.PokemonTypes.Select(pt => pt.TypeId);

            List <PokemonType> newLink = new List <PokemonType>();

            foreach (var type in _pokemonContext.Types)
            {
                if (selectedPokemonHS.Contains(type.Id.ToString()))
                {
                    if (!pokemonTypes.Contains(type.Id))
                    {
                        var foo = new PokemonType {
                            TypeId = type.Id, PokemonId = pokemonToUpdate.Id, Pokemon = pokemonToUpdate, Type = type
                        };
                        newLink.Add(foo);
                    }
                }

                else
                {
                    if (pokemonTypes.Contains(type.Id))
                    {
                        foreach (var pokemonType in _pokemonContext.PokemonTypes)
                        {
                            if (pokemonType.TypeId == type.Id)
                            {
                                pokemonToUpdate.PokemonTypes.Remove(pokemonType);
                            }
                        }
                    }
                }
            }

            foreach (var pokemonType in newLink)
            {
                _pokemonContext.Add(pokemonType);
            }
            _pokemonContext.SaveChanges();
        }
        private void PopulateAssignedTypeData(MyPokemon pokemon)
        {
            var allTypes     = _pokemonContext.Types;
            var pokemonTypes = new HashSet <Guid>(pokemon.PokemonTypes.Select(pt => pt.TypeId));
            var vm           = new List <AssignedTypeDataVm>();

            foreach (var type in allTypes)
            {
                vm.Add(new AssignedTypeDataVm
                {
                    TypeId   = type.Id,
                    TypeName = type.Name,
                    Assigned = pokemonTypes.Contains(type.Id)
                });
            }
            ViewBag.Types = vm;
        }
        public ActionResult Create(PokemonCreateVm pokemonCreateVm, MyPokemon createdPokemon, string[] selectedTypes)
        {
            createdPokemon = new MyPokemon
            {
                Name           = pokemonCreateVm.Name,
                HasAllolanForm = pokemonCreateVm.HasAllolanForm,
                ImgUrl         = pokemonCreateVm.ImgUrl,
                Description    = pokemonCreateVm.Description,
                Location       = pokemonCreateVm.location,
                NDex           = pokemonCreateVm.NDex,
                Id             = Guid.NewGuid()
            };

            if (selectedTypes != null)
            {
                createdPokemon.PokemonTypes = new List <PokemonType>();
                foreach (var type in selectedTypes)
                {
                    var typeToAdd = _pokemonContext.Types.Find(Guid.Parse(type));
                    var foo       = new PokemonType {
                        TypeId = typeToAdd.Id, PokemonId = createdPokemon.Id, Type = typeToAdd
                    };
                    createdPokemon.PokemonTypes.Add(foo);
                }
            }

            if (ModelState.IsValid)
            {
                createdPokemon.ImgUrl = SavePokeImg(pokemonCreateVm.UploadedImage);
                _pokemonContext.Pokemons.Add(createdPokemon);
                _pokemonContext.SaveChanges();
                return(RedirectToAction("Index"));
            }
            PopulateAssignedTypeData(createdPokemon);
            return(View(pokemonCreateVm));
        }
示例#7
0
        static void Main_13717()
        {
            var input      = int.Parse(ReadLine());
            var myPokemons = new List <MyPokemon>();

            for (int i = 0; i < input; i++)
            {
                var myPokemon = new MyPokemon();
                var(name, candys) = (ReadLine(), ReadLine().Split(' ').Select(double.Parse).ToList());

                myPokemon.Name      = name;
                myPokemon.Evolution = 0;

                var e = candys[1];
                var n = candys[0];

                while (e >= 0)
                {
                    var c = e - n + 2;

                    if (c >= 0)
                    {
                        myPokemon.Evolution++;
                    }

                    e = c;
                }

                myPokemons.Add(myPokemon);
            }

            WriteLine(myPokemons.Sum(c => c.Evolution));
            var max = myPokemons.Max(c => c.Evolution);

            WriteLine(myPokemons.FirstOrDefault(c => c.Evolution == max).Name);
        }