コード例 #1
0
ファイル: Program.cs プロジェクト: simontoyabe/Gato
        static void instrucciones()
        {
            tablero mitab = new tablero();

            Console.Clear();
            Console.WriteLine("Bienvenido al juego del gato. A continuación dos jugadores deben de colocar un símbolo en el tablero uno a la vez, el jugador que logre completar una linea de tres simbolos completos ganará el juego, en caso que ninguno lo logre se considerará empate. El juego asigna aleatoriamente el simbolo para cada jugador.");
            formateador(mitab.position);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: simontoyabe/Gato
        static void ipartida(string n1, string c1, string n2, string c2)
        {
            bdconection mycon = new bdconection();

            Console.Clear();
            jugador j1        = new jugador();
            jugador j2        = new jugador();
            tablero mytablero = new tablero();

            j1.nombre   = n1;
            j1.caracter = c1;
            j2.nombre   = n2;
            j2.caracter = c2;

            bool   esnumero;
            string spotition;
            string var  = "";
            int    var2 = 0;
            int    ipotition;
            int    njugador = 1;
            bool   ganador  = true;


            while (ganador)
            {
                Console.Clear();
                formateador(mytablero.position);

                if (njugador == 1)
                {
                    Console.Write(j1.nombre + " selecciona una posición");
                    spotition = Console.ReadLine();
                    try
                    {
                        esnumero  = Int32.TryParse(spotition, out ipotition);
                        ipotition = ipotition - 1;
                        if (esnumero && ipotition < 0 || ipotition > 8)
                        {
                            Console.WriteLine("La posicion no existe, perdiste el turno :(");
                            System.Threading.Thread.Sleep(1000);
                        }
                        else if (esnumero && String.IsNullOrEmpty(mytablero.position[ipotition]))
                        {
                            mytablero.position[ipotition] = j1.caracter;
                            var2 = var2 + 1;
                        }
                        else if (esnumero == false)
                        {
                            Console.WriteLine("¡TURNO PERDIDO! No ingresaste una posicion :(");
                            System.Threading.Thread.Sleep(1000);
                        }
                        else
                        {
                            Console.WriteLine("Posicion ocupada, perdiste el turno :(");
                            System.Threading.Thread.Sleep(1000);
                        }
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Posicion invalidad, turno perdido :(");
                    }
                }
                if (njugador == 2)
                {
                    Console.Write(j2.nombre + " selecciona una posición");
                    spotition = Console.ReadLine();
                    try
                    {
                        esnumero  = Int32.TryParse(spotition, out ipotition);
                        ipotition = ipotition - 1;
                        if (esnumero && ipotition < 0 || ipotition > 8)
                        {
                            Console.WriteLine("La posicion no existe, perdiste el turno :(");
                            System.Threading.Thread.Sleep(1000);
                        }
                        else if (esnumero && String.IsNullOrEmpty(mytablero.position[ipotition]))
                        {
                            mytablero.position[ipotition] = j2.caracter;
                            var2 = var2 + 1;
                        }
                        else if (esnumero == false)
                        {
                            Console.WriteLine("¡TURNO PERDIDO! No ingresaste una posicion :(");
                            System.Threading.Thread.Sleep(1000);
                        }
                        else
                        {
                            Console.WriteLine("Posicion ocupada, perdiste el turno :(");
                            System.Threading.Thread.Sleep(1000);
                        }
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Posicion invalidad, turno perdido :(");
                    }
                }

                var = validarganador(mytablero.position);
                if (var == "X")
                {
                    if (j1.caracter == "X")
                    {
                        Console.WriteLine("¡¡¡Felicidades " + j1.nombre + " ganaste la partida!!!");
                        System.Threading.Thread.Sleep(6000);
                        mycon.insertar(j1.nombre);
                    }
                    else
                    {
                        Console.WriteLine("¡¡¡Felicidades " + j2.nombre + " ganaste la partida!!!");
                        System.Threading.Thread.Sleep(6000);
                        mycon.insertar(j2.nombre);
                    }
                    ganador = false;
                }
                else if (var == "O")
                {
                    if (j1.caracter == "O")
                    {
                        Console.WriteLine("¡¡¡Felicidades " + j1.nombre + " ganaste la partida!!!");
                        System.Threading.Thread.Sleep(6000);
                        mycon.insertar(j1.nombre);
                    }
                    else
                    {
                        Console.WriteLine("¡¡¡Felicidades " + j2.nombre + " ganaste la partida!!!");
                        System.Threading.Thread.Sleep(6000);
                        mycon.insertar(j2.nombre);
                    }
                    ganador = false;
                }

                if (var2 == 9)
                {
                    Console.WriteLine("Esta machaca fue empate!!!");
                    System.Threading.Thread.Sleep(6000);
                    ganador = false;
                }

                if (njugador == 1)
                {
                    njugador = 2;
                }
                else if (njugador == 2)
                {
                    njugador = 1;
                }
            }
        }