Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Tablero GoL = new Tablero(10, 5);


            GoL.inserta(new Celula(Estado.viva, GoL, 3, 3));
            GoL.inserta(new Celula(Estado.viva, GoL, 3, 2));
            GoL.inserta(new Celula(Estado.viva, GoL, 3, 1));
            GoL.inserta(new Celula(Estado.viva, GoL, 0, 0));


            int CaseSwitch;

            do
            {
                Console.WriteLine("1.Pocision inicial \n2.Inicializar etapas\n3.Finalizar");
                CaseSwitch = Convert.ToInt16(Console.ReadLine());
                switch (CaseSwitch)
                {
                case 1:
                    GoL.print();
                    GoL.actualiza_estado_todas();
                    Console.WriteLine(GoL.grid[1][1].num_vecinas());
                    break;

                case 2:
                    for (int i = 0; i < 5; i++)
                    {
                        GoL.print();
                        GoL.actualiza_estado_todas();
                        GoL.Avance_turno();
                        System.Threading.Thread.Sleep(350);
                    }
                    break;

                case 3:
                    Console.WriteLine("Finalizado");
                    break;
                }
            }while(CaseSwitch != 3);



            //Actualizar el estado de todas las celdas
            //Cambiar el estado actual
            //Volver a imprimir
            //Repetir haciendo una pausa
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Tablero GoL = new Tablero(10, 5);

            GoL.inserta(new Celula(Estado.viva, GoL, 3, 3));
            GoL.inserta(new Celula(Estado.viva, GoL, 3, 2));
            GoL.inserta(new Celula(Estado.viva, GoL, 3, 1));
            GoL.inserta(new Celula(Estado.viva, GoL, 0, 0));

            GoL.print();

            // Actualizar el estado_siguiente de todas las celulas
            // Actualizar el estado actual con el siguiente
            // Volver a imprimir
            // Repetir haciendo una pausa
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
/*
 *                      // Glider Gun, hacer tablero de 15, 40
 *                      short[,] glider_gun = new short[,] {
 *                              {0, 24},
 *                              {1, 22}, {1, 24},
 *                              {2, 12}, {2, 13}, {2, 20}, {2, 21}, {2, 34}, {2, 35},
 *                              {3,11}, {3,15}, {3,20}, {3,21}, {3,34}, {3,35},
 *                              {4,0}, {4,1}, {4,10}, {4,16}, {4,20}, {4,21},
 *                              {5,0}, {5,1}, {5,10}, {5,14}, {5,16}, {5,17}, {5,22}, {5, 24},
 *                              {6,10}, {6,16}, {6,24},
 *                              {7,11}, {7,15},
 *                              {8,12}, {8,13}
 *                      };
 */
            Tablero GoL = new Tablero(10, 5);

            GoL.inserta_mapa(new short[, ] {
                { 3, 3 },
                { 3, 2 },
                { 3, 1 },
                { 0, 0 }
            });
            int input = 1;

            while (input == 1)
            {
                Console.Clear();
                Console.WriteLine("Tablero de juego:\n");
                GoL.print();
                Console.WriteLine("Menu de opciones\n 1.- Siguiente Turno\n 2.- Modificar tablero\n 3.- Adeltantar 50 turnos");
                input = int.Parse(Console.ReadLine());
                if (input == 1)
                {
                    GoL.actualizar_tablero();
                    GoL.siguiente_turno();
                }
                else if (input == 2)
                {
                    Console.Clear();
                    GoL.print(true);
                    Console.WriteLine("(Recuerda que los renglones y columnas empiezan de 0)");
InvalidPos:
                    Console.Write("Ingrese las posiciones de la celula en formato '(R)englon,(C)olumna,viva': ");
                    var pos = Console.ReadLine().Split(",");
                    if (pos.Length != 3)
                    {
                        Console.WriteLine("Deben ser 3 parametros en formato '(R)englon,(C)olumna,viva', ejemplo: 0,1,1");
                        goto InvalidPos;
                    }
                    else
                    {
                        short  x      = short.Parse(pos[0]);
                        short  y      = short.Parse(pos[1]);
                        string estado = pos[2];
                        if (!(x >= 0 && x < GoL.num_renglones))
                        {
                            Console.WriteLine("El renglon especificado esta fuera de los alcances del tablero.\n");
                            goto InvalidPos;
                        }
                        else if (!(y >= 0 && y < GoL.num_columnas))
                        {
                            Console.WriteLine("El renglon especificado esta fuera de los alcances del tablero.\n");
                            goto InvalidPos;
                        }
                        else if (estado != "1" && estado != "0" && estado != "false" && estado != "true")
                        {
                            Console.WriteLine("El parametro 'viva' tiene que ser true/false, o 0/1.\n");
                            goto InvalidPos;
                        }
                        else
                        {
                            input = 1;
                            bool viva = false;
                            if (estado == "1" || estado == "true")
                            {
                                viva = true;
                            }
                            GoL.inserta(new Celula((viva ? Estado.viva : Estado.vacia), GoL, x, y));
                        }
                    }
                }
                else if (input == 3)
                {
                    // 50 Turnos cada 150 ticks (0.150 segundos o 150 milisegundos)
                    GoL.avanzar_turnos(50, 150);
                    input = 1;
                }
            }
            Console.WriteLine("Gracias por jugar el 'Juego de la Vida'");
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
/*			Tablero GoL = new Tablero(10, 5);
 *                      GoL.agrega(new Celula(Estado.viva, GoL, 0, 0));
 *                      GoL.agrega(new Celula(Estado.viva, GoL, 1, 1));
 *                      GoL.agrega(new Celula(Estado.viva, GoL, 1, 2));
 *                      GoL.agrega(new Celula(Estado.viva, GoL, 2, 1));
 *                      GoL.agrega(new Celula(Estado.viva, GoL, 1, 2));*/
            Tablero GoL = new Tablero(15, 40);

            short[,] glider_gun = new short[, ] {
                { 0, 24 },
                { 1, 22 }, { 1, 24 },
                { 2, 12 }, { 2, 13 }, { 2, 20 }, { 2, 21 }, { 2, 34 }, { 2, 35 },
                { 3, 11 }, { 3, 15 }, { 3, 20 }, { 3, 21 }, { 3, 34 }, { 3, 35 },
                { 4, 0 }, { 4, 1 }, { 4, 10 }, { 4, 16 }, { 4, 20 }, { 4, 21 },
                { 5, 0 }, { 5, 1 }, { 5, 10 }, { 5, 14 }, { 5, 16 }, { 5, 17 }, { 5, 22 }, { 5, 24 },
                { 6, 10 }, { 6, 16 }, { 6, 24 },
                { 7, 11 }, { 7, 15 },
                { 8, 12 }, { 8, 13 }
            };
            GoL.agrega_map(glider_gun);
            int input = 1;

            while (input == 1)
            {
                Console.Clear();
                Console.WriteLine("Tablero de juego");
                GoL.print(true);
                Console.Write("Presiona 1 para el siguiente turno, 2 para modificar el tablero o 3 para adelantar 10 turnos: ");
                input = int.Parse(Console.ReadLine());
                if (input == 1)
                {
                    GoL.actualizar();
                    GoL.siguiente_turno();
                }
                else if (input == 2)
                {
InvalidPos:
                    Console.Write("Ingrese las posiciones de la celula en formato 'x,y,viva': ");
                    var pos = Console.ReadLine().Split(",");
                    if (pos.Length != 3)
                    {
                        Console.WriteLine("Deben ser 3 parametros en formato 'x,y,viva', ejemplo: 5,2,1");
                        goto InvalidPos;
                    }
                    else
                    {
                        short  x      = short.Parse(pos[0]);
                        short  y      = short.Parse(pos[1]);
                        string estado = pos[2];
                        if (!(x >= 0 && x < GoL.num_renglones))
                        {
                            Console.WriteLine("El renglon especificado esta fuera de los alcances del tablero.");
                            goto InvalidPos;
                        }
                        else if (!(y >= 0 && y < GoL.num_columnas))
                        {
                            Console.WriteLine("El renglon especificado esta fuera de los alcances del tablero.");
                            goto InvalidPos;
                        }
                        else if (estado != "1" && estado != "0" && estado != "false" && estado != "true")
                        {
                            Console.WriteLine("El renglon especificado esta fuera de los alcances del tablero.");
                            goto InvalidPos;
                        }
                        else
                        {
                            input = 1;
                            bool viva = false;
                            if (estado == "1" || estado == "true")
                            {
                                viva = true;
                            }
                            GoL.agrega(new Celula((viva ? Estado.viva : Estado.muerta), GoL, x, y));
                        }
                    }
                }
                else if (input == 3)
                {
                    int tick  = 150;
                    int ticks = 50;
                    for (int i = 0; i < ticks; i++)
                    {
                        Console.Clear();
                        GoL.print(true);
                        GoL.actualizar();
                        GoL.siguiente_turno();
                        Thread.Sleep(tick);
                    }
                    input = 1;
                }
            }
            Console.WriteLine("Gracias por jugar el 'Juego de la Vida'");
        }