コード例 #1
0
        // Determina si un jugador está ahogado (tablas)
        public bool ahogado(bool color)
        {
            ArrayList jugador;
            Rey       rey;
            Tablero   tablero = new Tablero();

            tablero.setEstado(this.getEstado());

            if (color)
            {
                jugador = tablero.fichasBlancas;
                rey     = reyBlanco;
            }
            else
            {
                jugador = tablero.fichasNegras;
                rey     = reyNegro;
            }

            if (tablero.esJaque(color, true))
            {
                return(false);
            }

            Ficha f;

            for (int i = 0; i < jugador.Count; i++)
            {
                f = (Ficha)jugador[i];
                if (f.movimientosPermitidos.Count > 0)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        // Determina si el rey "color" está en jaque (mate)
        public bool esJaque(bool color, bool mate)
        {
            Rey       rey;
            ArrayList jugadorRival;
            Tablero   tablero = new Tablero();

            tablero.setEstado(this.getEstado());

            // Copia del jugador (se modifica en los calculos)
            ArrayList jugador = new ArrayList();

            if (color)
            {
                jugadorRival = tablero.fichasNegras;
                for (int i = 0; i < tablero.fichasBlancas.Count; i++)
                {
                    jugador.Add(tablero.fichasBlancas[i]);
                }
                rey = tablero.reyBlanco;
            }
            else
            {
                jugadorRival = tablero.fichasBlancas;
                for (int i = 0; i < tablero.fichasNegras.Count; i++)
                {
                    jugador.Add(tablero.fichasNegras[i]);
                }
                rey = tablero.reyNegro;
            }

            Ficha ficha;

            // Copia de los movimientos (se modifica en los calculos)
            ArrayList movimientos = new ArrayList();

            bool noJaque = false;

            for (int i = 0; i < jugadorRival.Count; i++)
            {
                ficha = (Ficha)jugadorRival[i];

                if (ficha.celdasAmenazadas.Contains(rey.miCasilla))
                {
                    if (!mate)
                    {
                        return(true);
                    }

                    if (rey.movimientosPermitidos.Count == 0)
                    {
                        Casilla aux;
                        Ficha   f, r;

                        for (int j = 0; j < jugador.Count; j++)
                        {
                            f   = (Ficha)jugador[j];
                            aux = f.miCasilla;
                            movimientos.Clear();

                            for (int k = 0; k < f.movimientosPermitidos.Count; k++)
                            {
                                movimientos.Add(f.movimientosPermitidos[k]);
                            }

                            foreach (Casilla c in movimientos)
                            {
                                r = c.ficha;

                                if (tablero.moverFicha(f, aux, c))
                                {
                                    if (!tablero.esJaque(color, false))
                                    {
                                        noJaque = true;
                                    }
                                }

                                c.ficha = r;
                                if (r != null)
                                {
                                    r.capturada = false;
                                }
                                aux.ficha = f;
                                tablero.actualizarMovimientos();

                                if (noJaque)
                                {
                                    return(false);
                                }
                            }
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: LuisGP/ChessLG
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back
                == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            if (!finJuego && mueven)
            {
                Window.Title = "ChessLG";

                if (tablero.ahogado(tablero.turno))
                {
                    //Console.Beep();
                    //this.Exit();
                    MessageBox.Show("TABLAS!!");
                    finJuego            = true;
                    tablero.movimiento += NotAlg.TABLAS;
                }

                if (tablero.esJaque(tablero.turno, false))
                {
                    Window.Title       += " - Jaque!";
                    tablero.movimiento += NotAlg.JAQUE;
                }

                if (tablero.esJaque(tablero.turno, true))
                {
                    //Console.Beep();
                    //Console.Beep();
                    MessageBox.Show("JAQUE MATE!!");
                    //this.Exit();
                    finJuego            = true;
                    tablero.movimiento += NotAlg.JAQUE;
                }

                Window.Title += " - " + tablero.movimiento;

                // Añadimos el movimiento
                if (tablero.turno == Ficha.BLANCA || finJuego)
                {
                    tablero.historial.Add(tablero.movimiento);
                    tablero.movimiento = "";
                }

                mueven = false;
            }

            if (turnoAnterior == tablero.turno)
            {
                turnoAnterior = !tablero.turno;
                mueven        = true;
            }

            // Prueba heavy de estado
            //Estado status = tablero.getEstado();
            //tablero.setEstado(status);

            // TODO Opciones de fin de juego - Menu, repetir, salir

            // Actualiza la posicion del raton
            mouseFunction();

            base.Update(gameTime);
        }