public bool Attack(Pokemon attackingPokemon, Pokemon defendingPokemon, OwnedPokemonAttack attack)
        {
            Random accuracy = new Random();

            //check accuracy
            if (accuracy.Next(0, 101) <= attack.Attack.Accuracy)
            {
                Random randomAttackDamage = new Random();

                //random attack modifier
                double modifier = Convert.ToDouble(randomAttackDamage.Next(85, 101)) / 100;

                //type modifier
                if (attack.Attack.Type.TypeEffectiveId == defendingPokemon.Pokedex.TypeId)
                {
                    modifier            *= 2;
                    txtInformation.Text += ", it was very effective";
                }
                else if (attack.Attack.Type.TypeNotEffectiveId == defendingPokemon.Pokedex.TypeId)
                {
                    modifier            *= 0.5;
                    txtInformation.Text += ", it was not very effective";
                }

                //attack type is hetzelfde als pokemon type
                if (attack.Attack.TypeId == attackingPokemon.Pokedex.TypeId)
                {
                    modifier *= 1.5;
                }


                double damage;

                if (attack.Attack.Type.Name.ToLower() == "normal")
                {
                    //normal attack
                    damage = (((((2 * attackingPokemon.Level) / 5) + 2) * attack.Attack.BaseDamage * (attackingPokemon.CalculatedAttack / defendingPokemon.CalculatedDefense) / 50) + 2) * modifier;
                }
                else
                {
                    //special attack
                    damage = (((((2 * attackingPokemon.Level) / 5) + 2) * attack.Attack.BaseDamage * (attackingPokemon.CalculatedSpecialAttack / defendingPokemon.CalculatedSpecialDefense) / 50) + 2) * modifier;
                }

                txtInformation.Text += Environment.NewLine + "it did " + Convert.ToInt32(Math.Round(damage)) + " damage" + Environment.NewLine;

                defendingPokemon.CurrentHp -= Convert.ToInt32(Math.Round(damage));
            }
            else if (attack.Attack.Name.ToLower() == "splash")
            {
                txtInformation.Text += Environment.NewLine + "But nothing happened...";
            }
            else
            {
                txtInformation.Text += Environment.NewLine + "It missed...";
            }


            return(defendingPokemon.CheckHp());
        }
        private void LevelUp()
        {
            if (playerPokemon.Xp >= Convert.ToInt32(Math.Pow(playerPokemon.Pokemon.Level, 3)))
            {
                LevelGained = true;
                playerPokemon.Pokemon.Level++;
                txtInformation.Text += $"{Environment.NewLine}Your {playerPokemon.Name} leveled up to level {playerPokemon.Pokemon.Level}! {Environment.NewLine}";


                List <PokemonAttack>      attackList        = DatabaseOperations.GetAvailableAttacks(playerPokemon.Pokemon.PokedexId, playerPokemon.Pokemon.Level);
                List <OwnedPokemonAttack> knownAttacks      = DatabaseOperations.GetKnownAttacks(PlayerPokemonStatics.PlayerPokemon.PokemonId);
                List <OwnedPokemonAttack> knownAttacksFalse = DatabaseOperations.GetKnownAttacksEqualsFalse(PlayerPokemonStatics.PlayerPokemon.PokemonId);

                foreach (var item in attackList)
                {
                    if (playerPokemon.Pokemon.Level >= item.RequiredLevel)
                    {
                        OwnedPokemonAttack newAttack = new OwnedPokemonAttack()
                        {
                            AttackId    = item.AttackId,
                            CurrentPp   = item.Attack.Pp,
                            PokemonId   = playerPokemon.PokemonId,
                            KnownAttack = false
                        };


                        if (!knownAttacks.Contains(newAttack) && !knownAttacksFalse.Contains(newAttack))
                        {
                            DatabaseOperations.AddCaughtPokemonAttacks(newAttack);
                            txtInformation.Text += $"Your {playerPokemon.Name} can learn a new move" + Environment.NewLine;
                        }
                    }
                }

                PlayerPokemonUi();
            }
        }
        private void BtnConfirm_Click(object sender, RoutedEventArgs e)
        {
            Player        player        = new Player();
            PlayerPokemon playerPokemon = new PlayerPokemon();

            player.Name        = txtPlayerName.Text;
            playerPokemon.Name = txtRenamePokemon.Text;



            if (player.IsGeldig() && playerPokemon.IsGeldig() && PokemonSelected() != false)
            {
                TimeSpan startTime = new TimeSpan(0, 0, 0);


                player.Pokedollar = 10000;
                player.PlayedTime = startTime;

                int ok = DatabaseOperations.AddPlayer(player);

                Random r = new Random();

                PlayerPokedex playerPokedex = new PlayerPokedex();

                int id = 0;

                playerPokedex.PlayerId = player.Id;

                if (tbBulbasaur.IsChecked == true)
                {
                    playerPokemon.Height = 0.7m;
                    playerPokemon.Weight = 6.9m;
                    id = 1;
                    playerPokedex.Caught      = true;
                    playerPokedex.Encountered = true;
                    playerPokedex.PokedexId   = id;
                }
                else if (tbCharmander.IsChecked == true)
                {
                    playerPokemon.Height = 0.6m;
                    playerPokemon.Weight = 8.5m;
                    id = 4;
                    playerPokedex.Caught      = true;
                    playerPokedex.Encountered = true;
                    playerPokedex.PokedexId   = id;
                }
                else if (tbSquirtle.IsChecked == true)
                {
                    playerPokemon.Height = 0.5m;
                    playerPokemon.Weight = 9;
                    id = 7;
                    playerPokedex.Caught      = true;
                    playerPokedex.Encountered = true;
                    playerPokedex.PokedexId   = id;
                }



                DatabaseOperations.AddNewPokemonPlayerPokedex(playerPokedex);


                pokemon = new Pokemon
                {
                    Level          = 7,
                    Hp             = r.Next(0, 32),
                    CurrentHp      = 0,
                    Defense        = r.Next(0, 32),
                    Attack         = r.Next(0, 32),
                    SpecialAttack  = r.Next(0, 32),
                    SpecialDefense = r.Next(0, 32),
                    Speed          = r.Next(0, 32),
                    PokedexId      = id,
                };

                playerPokemon.PokemonId = DatabaseOperations.AddPokemon(pokemon);

                pokemon.Pokedex = DatabaseOperations.GetPokedexEntry(id);
                pokemon.SetMaxHp();
                pokemon.CurrentHp = pokemon.CalculatedMaxHP;

                DatabaseOperations.UpdatePokemonCurrentHp(pokemon);



                playerPokemon.InParty  = true;
                playerPokemon.PlayerId = player.Id;
                playerPokemon.Xp       = Convert.ToInt32(Math.Pow(pokemon.Level - 1, 3));

                DatabaseOperations.AddPlayerPokemon(playerPokemon);

                List <PokemonAttack> pokemonAttacks = DatabaseOperations.GetAvailableAttacks(pokemon.PokedexId, pokemon.Level);

                foreach (var item in pokemonAttacks)
                {
                    if (pokemon.Level >= item.RequiredLevel)
                    {
                        OwnedPokemonAttack ownedPokemonAttack = new OwnedPokemonAttack
                        {
                            AttackId    = item.AttackId,
                            CurrentPp   = item.Attack.Pp,
                            PokemonId   = playerPokemon.PokemonId,
                            KnownAttack = true
                        };
                        DatabaseOperations.AddCaughtPokemonAttacks(ownedPokemonAttack);
                    }
                }

                PlayerInformation.PlayerId = ok;

                MainMenuWindow mainMenuWindow = new MainMenuWindow();
                mainMenuWindow.Show();
                this.Close();
            }
            else if (!player.IsGeldig())
            {
                MessageBox.Show(player.Error);
            }
            else if (!playerPokemon.IsGeldig())
            {
                MessageBox.Show(playerPokemon.Error);
            }
            else
            {
                MessageBox.Show("You need to select a pokemon first.");
            }
        }
        private bool Catch(double catchMultiplier, Pokemon pokemon, List <OwnedPokemonAttack> attacks)
        {
            if (lblEnemyName.Content.ToString() == "Wild Pokemon")
            {
                int    catchRate      = pokemon.Pokedex.CatchRate;
                double catchMissingHp = ((100 - pbHpEnemyPokemon.Value) / 100) + 1;
                double catchNumber    = ((catchRate * catchMissingHp) * catchMultiplier);

                Random r = new Random();

                if (r.Next(0, 101) <= catchNumber)
                {
                    // pokemon object aanmaken om te inserten
                    Pokemon p = new Pokemon
                    {
                        Level          = pokemon.Level,
                        Attack         = pokemon.Attack,
                        Defense        = pokemon.Defense,
                        Hp             = pokemon.Hp,
                        CurrentHp      = pokemon.CalculatedMaxHP,
                        SpecialAttack  = pokemon.SpecialAttack,
                        SpecialDefense = pokemon.SpecialDefense,
                        Speed          = pokemon.Speed,
                        PokedexId      = pokemon.PokedexId
                    };

                    int id = DatabaseOperations.AddPokemon(p);

                    // speler pokemon aanmaken om te inserten
                    PlayerPokemon newPlayerPokemon = new PlayerPokemon
                    {
                        Name      = pokemon.Pokedex.Name,
                        Height    = pokemon.Pokedex.AvgHeight,
                        Weight    = pokemon.Pokedex.AvgWeight,
                        Xp        = (pokemon.Level - 1) * (pokemon.Level - 1) * (pokemon.Level - 1),
                        InParty   = false,
                        PlayerId  = PlayerInformation.PlayerId,
                        PokemonId = id,
                    };

                    DatabaseOperations.AddPlayerPokemon(newPlayerPokemon);

                    // pokemon aanvallen aanmaken om te inserten
                    foreach (var item in attacks)
                    {
                        OwnedPokemonAttack attack = new OwnedPokemonAttack
                        {
                            CurrentPp = item.CurrentPp,
                            PokemonId = id,
                            AttackId  = item.AttackId,
                        };
                        if (item.KnownAttack == true)
                        {
                            attack.KnownAttack = true;
                        }
                        else
                        {
                            attack.KnownAttack = false;
                        }



                        DatabaseOperations.AddCaughtPokemonAttacks(attack);
                    }

                    txtInformation.Text               = $"Congratulations , You caught a {pokemon.Pokedex.Name}!";
                    imgEnemyPokemon.Source            = new BitmapImage(new Uri(@"images\sprites\pokeball.png", UriKind.Relative));
                    imgEnemyPokemon.Width             = 50;
                    imgEnemyPokemon.Height            = 50;
                    imgEnemyPokemon.VerticalAlignment = VerticalAlignment.Center;

                    return(true);
                }
                else
                {
                    txtInformation.Text = $"{pokemon.Pokedex.Name} broke free, Try again!";

                    return(false);
                }
            }
            else
            {
                txtInformation.Text = $"You can't catch another trainer's pokemon";

                return(false);
            }
        }
        // WILD BATTLE
        public TrainerBattleWindow(Found wildPokemon)
        {
            InitializeComponent();

            Random r = new Random();

            Pokedex pokedex = wildPokemon.Pokedex;

            pokemon = new Pokemon
            {
                Level          = r.Next(wildPokemon.MinLevel, wildPokemon.MaxLevel + 1),
                Hp             = r.Next(0, 32),
                CurrentHp      = 0,
                Defense        = r.Next(0, 32),
                Attack         = r.Next(0, 32),
                SpecialAttack  = r.Next(0, 32),
                SpecialDefense = r.Next(0, 32),
                Speed          = r.Next(0, 32),
                PokedexId      = pokedex.Id,
                Pokedex        = pokedex,
            };

            pokemon.SetMaxHp();
            pokemon.CurrentHp = pokemon.CalculatedMaxHP;

            List <PokemonAttack> possibleAttacksList = DatabaseOperations.GetAvailableAttacks(pokemon.PokedexId, pokemon.Level);
            List <Attack>        attackList          = new List <Attack>();

            foreach (var item in possibleAttacksList)
            {
                attackList.Add(DatabaseOperations.GetAttack(item.AttackId));
            }

            List <int> knownAttackListIds = new List <int>();

            while (knownAttackList.Count != attackList.Count)
            {
                Random rx            = new Random();
                int    attackId      = rx.Next(0, attackList.Count);
                Attack attackToLearn = attackList[attackId];

                OwnedPokemonAttack newAttack = new OwnedPokemonAttack
                {
                    CurrentPp = attackToLearn.Pp,
                    AttackId  = attackToLearn.Id,
                    Attack    = attackToLearn
                };

                if (knownAttackList.Count < 4)
                {
                    newAttack.KnownAttack = true;

                    if (!knownAttackListIds.Contains(newAttack.AttackId))
                    {
                        knownAttackListIds.Add(newAttack.AttackId);
                        knownAttackList.Add(newAttack);
                    }
                }
                else
                {
                    newAttack.KnownAttack = false;

                    if (!knownAttackListIds.Contains(newAttack.AttackId))
                    {
                        knownAttackListIds.Add(newAttack.AttackId);
                        knownAttackList.Add(newAttack);
                    }
                }
            }


            //wild pokemon UI
            lblEnemyName.Content = "Wild Pokemon";
            txtInformation.Text  = $"You encountered a wild {pokemon.Pokedex.Name}{Environment.NewLine}";
            btnRun.IsEnabled     = true;

            enemyPokemon = pokemon;

            EnemyUi();
        }