Exemplo n.º 1
0
        /* Avisa al usuario y procesa una flota leida de teclado. */
        private static Flota IntroducirFlota()
        {
            double restante = (0.2 * API_Hundir_Flota.dimension * API_Hundir_Flota.dimension);
            Flota  f        = new Flota();

            while (restante > 0)
            {
                Console.WriteLine("Introduce un barco (" + restante + " casillas restantes)");
                String s = Console.ReadLine();

                try // formateamos el barco leido
                {
                    Barco n = GUI_Hundir_Flota.LecturaBarco(s);
                    f         = new Flota(f.flota, n); // no se ejecuta si hay excepcion
                    restante -= n.tam;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Excepcion:" + e.GetType());
                }


                if (restante <= 0)
                {
                    break;
                }
                else if (restante < API_Hundir_Flota.dimension) // asi evitamos jugar contra una flota vacia
                {
                    Console.WriteLine("Pulsa s para introducir otro barco");
                    string opt = Console.ReadLine();
                    if (opt != "s")
                    {
                        break;
                    }
                }
            }

            return(f);
        }
Exemplo n.º 2
0
 public API_Hundir_Flota()
 {
     tab   = new Tablero();
     flota = new Flota();
 }