public FormGame(Character character)
        {
            InitializeComponent();

            player = character;

            Map.mainForm = this;

            tbDialog.Hide();
            panelDialog.Hide();

            map = new Map(1, 375, 270);

            new Paint_BlackScreen(this, pbCanvas.CreateGraphics(), pbCanvas.Width, pbCanvas.Height);

            timerRefresh.Interval = refreshRate;
            timerRefresh.Start();

            panelMenu.Location = new Point(panelMenu.Location.X, -31);

            panelMenuCloseTimer.Interval = 50;
            panelMenuCloseTimer.Tick += panelMenuCloseTimer_Tick;
        }
        public FormBattle(Character trainer)
        {
            InitializeComponent();

            enemyTrainer = trainer;
            enemyPokemon = trainer.pokemons[0];
            tbHistory.Text = "You started a pokemon battle with " + trainer.name + "!";

            // set temporary stats
            for (int i = 0; i < trainer.pokemons.Count; ++i)
            {
                trainer.pokemons[i].SetTemporaryStats();
                trainer.pokemons[i].EraseAffections();
            }

            // see pokemon
            for (int i = 0; i < trainer.pokemons.Count; ++i)
            {
                FormPokedex.SeePokemon(trainer.pokemons[i].index);
            }

            Initialize();
        }
        private void buttonStartGame_Click(object sender, EventArgs e)
        {
            if (selectedNr < 0)
            {
                labelError.Text = "Select a starter pokemon";
                labelError.Show();
                return;
            }

            if (tbName.Text == "")
            {
                labelError.Text = "Select a name for your trainer";
                labelError.Show();
                return;
            }

            string[] words = tbName.Text.Split();
            if(words[0] != tbName.Text)
            {
                labelError.Text = "Your name can not contain spaces";
                labelError.Show();
                return;
            }

            applicationIsRunning = true;

            Character player = new Character(tbName.Text);

            int pokeNr;

            switch (selectedNr)
            {
                case 0: pokeNr = 1; break;
                case 1: pokeNr = 4; break;
                case 2: pokeNr = 7; break;
                case 3: pokeNr = 152; break;
                case 4: pokeNr = 155; break;
                case 5: pokeNr = 158; break;
                case 6: pokeNr = 252; break;
                case 7: pokeNr = 255; break;
                case 8: pokeNr = 258; break;
                case 9: pokeNr = 387; break;
                case 10: pokeNr = 390; break;
                default: pokeNr = 393; break;
            }

            Pokemons pokemon = new Pokemons(pokeNr, 5);

            FormPokedex.SeePokemon(pokeNr);
            FormPokedex.OwnPokemon(pokeNr);

            // starting pokemon
            pokemon.lovebase = 50;
            pokemon.EarnLove(100, 20, 30);
            player.AddPokemon(pokemon);

            // starting items
            Pokeball pball = new Pokeball(1);
            pball.number = 5;
            player.pokeballs.Add(pball);

            // starting money
            player.money = 1000;

            // starting food
            player.food = 10;

            new FormGame(player).Show();

            this.Close();
        }
 private void ShuffleTeam(Character trainer)
 {
     List<Pokemons> list = trainer.pokemons;
     for(int i=1;i<=1000;++i)
     {
         int x = rand.Next() % 6;
         int y = rand.Next() % 6;
         Pokemons aux;
         aux = list[x];
         list[x] = list[y];
         list[y] = aux;
     }
 }
        public void StopActionFromTrainer(Character trainer)
        {
            if (trainer.index == 117)
            {
                FormGame.map = new Map(mapNumber, FormGame.OX - 7, FormGame.OY - 6);
                return;
            }

            trainerDefeated[trainer.index] = true;

            if(trainer.index >= 118 && trainer.index <= 120)
            {
                player.HealTeam();
                characters.Clear();
                actionpoint.Clear();
                LoadTournament(trainer.index - 116);
                return;
            }

            if(trainer.index == 121)
            {
                new FormEndGame(1).Show();
                mainForm.Close();
            }

            if (trainer.index == 9) // first gym
            {
                mainForm.ShowMessage("John the Lumberjack: Aaaaah, not again! I'm surprised. Congratulations! Here, take this badge, you deserve it! Oh, and take this, too. It is a HM: Cut. You can teach your pokemons this move how many times you want. Check your bag.");
                player.TMs.Add(new Attack(15)); // give Cut
                player.badges = 1;
            }

            if (trainer.index == 19) // second gym
            {
                mainForm.ShowMessage("Desmond: Excellent skills! Here is your badge and a pleasant surprise - TM: Calm Mind. But be careful! You can teach your pokemons a HM how many times you want, but after you teach one a TM, you will lose the TM forever. The Calm Mind should help you approach the Haunted House without fear.");
                player.TMs.Add(new Attack(347)); // give Calm Mind
                player.badges = 2;
            }

            if (trainer.index == 25) // third gym
            {
                mainForm.ShowMessage("Magic Stan: I guess you can't be a great magician in a small village like this. But you have talent. Here, take HM: Surf. With it you can surf on water and go towards new horizons!");
                player.TMs.Add(new Attack(57)); // give Surf
                player.badges = 3;
            }

            if (trainer.index == 64) // fourth gym
            {
                mainForm.ShowMessage("Aviana: Oh my God! I was so blinded by power that i didn't notice how polluted our waters were. I should be taking care of these problems right away!");
                player.badges = 4;
            }

            if (trainer.index == 79) // fifth gym
            {
                mainForm.ShowMessage("Farmer: YOOHOO! What a battle! Take a pair of goggles to go in the desert. Oh, and you should take this TM: Dig. Dig in the desert to find hidden secrets.");
                player.TMs.Add(new Attack(91)); // give Dig
                player.badges = 5;
            }

            if (trainer.index == 93) // sixth gym
            {
                mainForm.ShowMessage("Isolde: I feel something strange coming from the north.");
                player.badges = 6;
            }

            if (trainer.index == 99) // seventh gym
            {
                mainForm.ShowMessage("Charles&Clotilde Dubois: Mon dieu! We did not expect that! C'est dommage, you win...");
                player.badges = 7;
            }

            if (trainer.index == 116) // eighth gym
            {
                mainForm.ShowMessage("Edmund the Wise: Oh, you are gifted. I guess this is your last badge. Take it and become the tournament champion!");
                player.badges = 8;
            }

            if (trainer.index == 103) // fake gym
            {
                mainForm.ShowMessage(player.name + ": Oh, you are the leader of Team Rocket!\nGiovanni: How could a prick interfere with my plans?\n\nYou recovered a Master Ball from Team Rocket!");
                Pokeball pball = new Pokeball(4);
                pball.number = 1;
                player.pokeballs.Add(pball);
            }

            if (trainer.index >= 39 && trainer.index <= 43 && trainerDefeated[39] && trainerDefeated[40]
                && trainerDefeated[41] && trainerDefeated[42] && trainerDefeated[43]) // open gates for Lucas the Fighter
            {
                mainForm.ShowMessage("Lucas the Fighter: Hmm, I know you. You beat my older brother, John the Lumberjack. But can you handle my superior strength?");
                structures.Clear();
            }

            if (trainer.index == 38) // Lucas the Fighter
            {
                mainForm.ShowMessage("Lucas the Fighter: What the hell... whatever, you deserve the prize. I will teach your pokemon the best fighting move: Focus Punch. But be careful at its downsides.");
                actionAfterDialog = 3;
            }

            if (trainer.index >= 45 && trainer.index <= 49 && trainerDefeated[45] && trainerDefeated[46]
                && trainerDefeated[47] && trainerDefeated[48] && trainerDefeated[49]) // open gates for Dino Senior
            {
                mainForm.ShowMessage("Dino Senior: Haha, you're a shifty one!");
                structures.Clear();
            }

            if (trainer.index == 44) // Dino Senior
            {
                mainForm.ShowMessage("Dino Senior: Bravos! Take this TM: Draco Meteor. It is a very strong move, but not so many pokemons can learn it.");
                player.TMs.Add(new Attack(434)); // give Draco Meteor
            }

            if (trainer.index >= 54 && trainer.index <= 62) // Get evolution stones from Team Rocket
            {
                EvolutionItem evolitem = new EvolutionItem(trainer.index - 53);
                player.evolutionItems.Add(evolitem);
                mainForm.ShowMessage("You recovered " + evolitem.name + " from Team Rocket!");
            }

            if (trainer.index >= 54 && trainer.index <= 62 && trainerDefeated[54] && trainerDefeated[55]
                && trainerDefeated[56] && trainerDefeated[57] && trainerDefeated[58] && trainerDefeated[59]
                && trainerDefeated[60] && trainerDefeated[61] && trainerDefeated[62]) // Team Rocket Squad 1 defeated
            {
                FormGame.map = new Map(mapNumber, FormGame.OX - 7, FormGame.OY - 6);
            }

            if (trainer.index >= 88 && trainer.index <= 92) // Get other evolution items from Team Rocket
            {
                int aux = (trainer.index - 88) * 3;
                EvolutionItem evolitem1 = new EvolutionItem(aux + 10);
                EvolutionItem evolitem2 = new EvolutionItem(aux + 11);
                EvolutionItem evolitem3 = new EvolutionItem(aux + 12);
                player.evolutionItems.Add(evolitem1);
                player.evolutionItems.Add(evolitem2);
                player.evolutionItems.Add(evolitem3);
                mainForm.ShowMessage("You recovered " + evolitem1.name + ", " + evolitem2.name + " and " + evolitem3.name + " from Team Rocket!");
            }

            if (trainer.index >= 88 && trainer.index <= 92 && trainerDefeated[88] && trainerDefeated[89]
               && trainerDefeated[90] && trainerDefeated[91] && trainerDefeated[92]) // Team Rocket Squad 2 defeated
            {
                FormGame.map = new Map(mapNumber, FormGame.OX - 7, FormGame.OY - 6);
            }
        }
        private void timerLoading_Tick(object sender, EventArgs e)
        {
            points = (points + 1) % 4;
            labelLoading.Text = "Loading";
            for (int i = 1; i <= points; ++i) labelLoading.Text += ".";

            if (Resources.resourcesDone)
            {
                timerLoading.Stop();

                applicationIsRunning = true;

                if(newGame) new FormCharacterCreation().Show();
                else
                {
                    StreamReader sr = new StreamReader(Application.StartupPath + "\\game.sav");

                    string line;
                    string[] words;

                    line = sr.ReadLine();
                    words = line.Split();

                    Character player = new Character(words[0]);
                    player.money = Convert.ToInt32(words[1]);
                    player.badges = Convert.ToInt32(words[2]);
                    player.healingcenter = Convert.ToInt32(words[3]);
                    player.food = Convert.ToInt32(words[4]);

                    line = sr.ReadLine();
                    words = line.Split();
                    int pokeCount = Convert.ToInt32(words[0]);
                    for(int i=0;i<pokeCount;++i)
                    {
                        line = sr.ReadLine();
                        words = line.Split();
                        Pokemons pokemon = new Pokemons(Convert.ToInt32(words[0]), 1);
                        pokemon.level = Convert.ToInt32(words[1]);

                        pokemon.gender = Convert.ToInt32(words[2]);
                        pokemon.name = words[3] + "";
                        pokemon.lovebase = (float)Convert.ToDouble(words[4]);
                        pokemon.EarnLove((float)Convert.ToDouble(words[5]), (float)Convert.ToDouble(words[6]), (float)Convert.ToDouble(words[7]));

                        pokemon.hp = (float)Convert.ToDouble(words[8]);
                        pokemon.hpmax = (float)Convert.ToDouble(words[9]);
                        pokemon.atk = (float)Convert.ToDouble(words[10]);
                        pokemon.def = (float)Convert.ToDouble(words[11]);
                        pokemon.spatk = (float)Convert.ToDouble(words[12]);
                        pokemon.spdef = (float)Convert.ToDouble(words[13]);
                        pokemon.speed = (float)Convert.ToDouble(words[14]);

                        pokemon.xp = Convert.ToInt32(words[15]);

                        line = sr.ReadLine();
                        words = line.Split();
                        pokemon.moves = new List<Attack>();
                        int moveCount = Convert.ToInt32(words[0]);
                        for (int j = 0; j < moveCount; ++j)
                        {
                            Attack move = new Attack(Convert.ToInt32(words[1 + j * 2]));
                            move.PP = Convert.ToInt32(words[2 + j * 2]);
                            pokemon.LearnMove(move);
                        }

                        player.AddPokemon(pokemon);
                    }

                    line = sr.ReadLine();
                    words = line.Split();
                    int pokeLabCount = Convert.ToInt32(words[0]);
                    for (int i = 0; i < pokeLabCount; ++i)
                    {
                        line = sr.ReadLine();
                        words = line.Split();
                        Pokemons pokemon = new Pokemons(Convert.ToInt32(words[0]), 1);
                        pokemon.level = Convert.ToInt32(words[1]);

                        pokemon.gender = Convert.ToInt32(words[2]);
                        pokemon.name = words[3] + "";
                        pokemon.lovebase = (float)Convert.ToDouble(words[4]);
                        pokemon.EarnLove((float)Convert.ToDouble(words[5]), (float)Convert.ToDouble(words[6]), (float)Convert.ToDouble(words[7]));

                        pokemon.hp = (float)Convert.ToDouble(words[8]);
                        pokemon.hpmax = (float)Convert.ToDouble(words[9]);
                        pokemon.atk = (float)Convert.ToDouble(words[10]);
                        pokemon.def = (float)Convert.ToDouble(words[11]);
                        pokemon.spatk = (float)Convert.ToDouble(words[12]);
                        pokemon.spdef = (float)Convert.ToDouble(words[13]);
                        pokemon.speed = (float)Convert.ToDouble(words[14]);

                        pokemon.xp = Convert.ToInt32(words[15]);

                        line = sr.ReadLine();
                        words = line.Split();
                        pokemon.moves = new List<Attack>();
                        int moveCount = Convert.ToInt32(words[0]);
                        for (int j = 0; j < moveCount; ++j)
                        {
                            Attack move = new Attack(Convert.ToInt32(words[1 + j * 2]));
                            move.PP = Convert.ToInt32(words[2 + j * 2]);
                            pokemon.LearnMove(move);
                        }

                        player.pokemonsLab.Add(pokemon);
                    }

                    line = sr.ReadLine();
                    words = line.Split();
                    int pokeballCount = Convert.ToInt32(words[0]);
                    for (int i = 0; i < pokeballCount;++i )
                    {
                        Pokeball ball = new Pokeball(Convert.ToInt32(words[1 + i * 2]));
                        ball.number = Convert.ToInt32(words[2 + i * 2]);
                        player.pokeballs.Add(ball);
                    }

                    line = sr.ReadLine();
                    words = line.Split();
                    int potionCount = Convert.ToInt32(words[0]);
                    for (int i = 0; i < potionCount; ++i)
                    {
                        Potion pot = new Potion(Convert.ToInt32(words[1 + i * 2]));
                        pot.number = Convert.ToInt32(words[2 + i * 2]);
                        player.potions.Add(pot);
                    }

                    line = sr.ReadLine();
                    words = line.Split();
                    int TMCount = Convert.ToInt32(words[0]);
                    for (int i = 0; i < TMCount; ++i)
                    {
                        player.TMs.Add(new Attack(Convert.ToInt32(words[1 + i])));
                    }

                    line = sr.ReadLine();
                    words = line.Split();
                    int EvolutionItemsCount = Convert.ToInt32(words[0]);
                    for (int i = 0; i < EvolutionItemsCount; ++i)
                    {
                        player.evolutionItems.Add(new EvolutionItem(Convert.ToInt32(words[1 + i])));
                    }

                    FormGame formGame = new FormGame(player);

                    line = sr.ReadLine();
                    words = line.Split();
                    FormGame.map = new Map(Convert.ToInt32(words[0]), Convert.ToInt32(words[1]), Convert.ToInt32(words[2]));
                    FormGame.gameTime = Convert.ToInt32(words[3]);
                    Map.lastTimeGym = Convert.ToInt32(words[4]);

                    line = sr.ReadLine();
                    words = line.Split();
                    for (int i = 0; i < 200;++i )
                    {
                        if (Convert.ToInt32(words[i]) == 1) Map.trainerDefeated[i] = true;
                    }

                    line = sr.ReadLine();
                    words = line.Split();
                    for (int i = 1; i < 494; ++i)
                    {
                        if (Convert.ToInt32(words[i - 1]) == 1) Map.pokemonDefeated[i] = true;
                    }

                    line = sr.ReadLine();
                    words = line.Split();
                    FormPokedex.seen = Convert.ToInt32(words[0]);
                    FormPokedex.owned = Convert.ToInt32(words[1]);

                    line = sr.ReadLine();
                    words = line.Split();
                    for (int i = 1; i < 494; ++i)
                        if (Convert.ToInt32(words[i - 1]) == 1)
                            FormPokedex.inPokedex[i] = true;

                    line = sr.ReadLine();
                    words = line.Split();
                    for (int i = 1; i < 494; ++i)
                        if (Convert.ToInt32(words[i - 1]) == 1)
                            FormPokedex.ownedPokemon[i] = true;

                    line = sr.ReadLine();
                    words = line.Split();
                    for (int i = 1; i < 494; ++i)
                    {
                        string nameString = words[i - 1] + "";
                        if (nameString != "-")
                            FormPokedex.names[i] = nameString;
                    }

                    formGame.Show();

                    sr.Close();
                }

                this.Close();
            }
        }