static void Main(string[] args)
        {
            try
            {
                PartidaDeXadrez partidaDeXadrez = new PartidaDeXadrez();
                while (!partidaDeXadrez.Terminada)
                {
                    try
                    {
                        Tela.ImprimirTabuleiro(partidaDeXadrez.Tabuleiro);

                        //ORIGEM
                        Tela.ImprimirJogadaParte1(partidaDeXadrez);
                        PosicaoXadrez posicaoXadrez = Tela.LerPosicaoXadrez();
                        Posicao       origem        = posicaoXadrez.ToPosicao();
                        partidaDeXadrez.ValidarOrigem(origem);
                        bool[,] movimentos = partidaDeXadrez.Tabuleiro.ObterPeca(origem).MovimentosPossiveis();
                        Tela.ImprimirTabuleiro(partidaDeXadrez.Tabuleiro, movimentos, origem);

                        //DESTINO
                        Tela.ImprimirJogadaParte1(partidaDeXadrez);
                        Tela.ImprimirJogadaParte2(posicaoXadrez);
                        Posicao destino = Tela.LerPosicaoXadrez().ToPosicao();
                        partidaDeXadrez.ValidarDestino(origem, destino);
                        partidaDeXadrez.NovaJogada(origem, destino);
                    }
                    catch (TabuleiroException erro)
                    {
                        Console.Write("\n  " + erro.Message);
                        Console.ReadKey();
                    }
                }
                Tela.ImprimirTabuleiro(partidaDeXadrez.Tabuleiro);
                Tela.ImprimirJogadaParte1(partidaDeXadrez);
            }
            catch (TabuleiroException erro)
            {
                Console.WriteLine(erro.Message);
            }
            Console.ReadKey();
        }
Ejemplo n.º 2
0
 private void DgvXadrez_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         int     linha   = dgvXadrez.SelectedCells[0].RowIndex;
         int     coluna  = dgvXadrez.SelectedCells[0].ColumnIndex;
         Posicao posicao = new Posicao(dgvXadrez.SelectedCells[0].RowIndex, dgvXadrez.SelectedCells[0].ColumnIndex);
         if (Origem == null)
         {
             PartidaDeXadrez.ValidarOrigem(posicao);
             Origem = posicao;
             AjustarOrigem(linha, coluna);
         }
         else
         {
             Posicao origem = Origem;
             Origem = null;
             PartidaDeXadrez.ValidarDestino(origem, posicao);
             PartidaDeXadrez.NovaJogada(origem, posicao);
             TestarPromocao(PartidaDeXadrez.Tabuleiro.ObterPeca(posicao));
             AtualizarDataGrid();
             TesteXeque();
         }
     }
     catch (TabuleiroException erro)
     {
         MessageBox.Show(erro.Message);
         AtualizarDataGrid();
     }
     catch (ArgumentOutOfRangeException)
     {
         MessageBox.Show("A POSIÇÃO INFORMADA É INVÁLIDA!");
         AtualizarDataGrid();
     }
     catch (XequeMateException)
     {
         MessageBox.Show("É XEQUE-MATE!\nVENCEDOR: " + PartidaDeXadrez.JogadorAdversario());
         Close();
     }
 }