Esempio n. 1
0
        /* Reads pokemons from a text file.
         *
         * Parameter: pokemonFile - name of a text file
         */
        private void ReadPokemons(string pokemonFile)
        {
            StreamReader st = null;
            StreamWriter sw = null;
            /* Try to open a text file */
            try
            {
                st = new System.IO.StreamReader(pokemonFile);
                sw = new StreamWriter(pokemonFile + ".out");
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            var pokemons = Enum.GetValues(typeof(Pokemons)).Cast<Pokemons>().ToList();
            var rndType = new Random();

            for (int i = 0; i < 150; i++)
            {
                /* Read tuple <x, y, pokemon> */

                var line = st.ReadLine().Split(' ');
                int pokeN = int.Parse( line[2] );
                int x = int.Parse(line[0]);
                int y = int.Parse(line[1]);

                Pokemons t ;
                if (pokeN == -1) // aleatory Pokemon
                {
                    int nPoke = rndType.Next(pokemons.Count);
                    t = pokemons[nPoke];
                    pokemons.RemoveAt(nPoke);
                }
                else
                    t = (Pokemons) (pokeN -1 );

                /* If random position */
                if (x == -1 && y == -1)
                {
                    /* Random object */
                    Random random = new Random(DateTime.Now.Millisecond.GetHashCode());
                    var temLugar = this._map.Any(a => a.Where(b => !b.HasPokemon && !b.HasAsh && !b.hasMart && !b.hasPokeCenter && !b.hasTrainer ).Count() > 0);
                    if(temLugar)
                    do
                    {
                        x = random.Next(0, 42);
                        y = random.Next(0, 42);

                    } while (
                       GetTile(x, y).HasPokemon ||
                       GetTile(x, y).hasTrainer||
                    GetTile(x, y).hasPokeCenter ||
                    GetTile(x, y).hasMart ||
                       GetTile(x, y).HasAsh );

                }

                /* Create pokemon */

                Pokemon _pokemon = new Pokemon(t);

                /* Assign pokemon */
                GetTile(x, y).Pokemon = _pokemon;
                sw.WriteLine(x + " " + y + " " + _pokemon.ToString() );
            }
            sw.Close();
        }
Esempio n. 2
0
 public void ShowPokemon(Pokemon poke)
 {
     lsvMyPokemnos.Items.Add(poke.ToString());
     lsvMyPokemnos.Update();
 }