void loop(char jogador) { char tab[9][9]= { {' ', ' ', ' ', 'M', 'M', 'M', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', 'M', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', 'G', ' ', ' ', ' ', ' '}, {'M', ' ', ' ', ' ', 'G', ' ', ' ', ' ', 'M'}, {'M', 'M', 'G', 'G', 'R', 'G', 'G', 'M', 'M'}, {'M', ' ', ' ', ' ', 'G', ' ', ' ', ' ', 'M'}, {' ', ' ', ' ', ' ', 'G', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', 'M', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', 'M', 'M', 'M', ' ', ' ', ' '}, }; unsigned int mov[4]; unsigned int n_jog = 0; bool trono = false; char msg = 0, fim = 0; time_t t0; time(&t0); while(true) { fim = verificar_vitoria(tab); clear(); desenhar_tabuleiro(tab); if(fim) break; move(20, 0); desenhar_mensagem(msg); refresh(); remover_pecas_capturadas(tab); msg = 0; move(21, 0); ler_movimento(jogador, mov); if(is_jogada_valida(tab, jogador, mov, &msg)) { n_jog++; mover_peca(tab, mov); unsigned int captura[2]; if(testar_captura(tab, jogador, mov[3], mov[2], captura)) { capturar_peca(tab, jogador, captura); if(tab[captura[0]][captura[1]] == 'R') fim = 1; } if(!trono && mov[0] == 4 && mov[1] == 4) { tab[4][4] = 'T'; trono = true; } jogador = !jogador; } } clear(); desenhar_tabuleiro(tab); move(21, 0); desenhar_fim(t0, n_jog, fim); refresh(); getch(); }
int main(){ inicia_ncurses(); WINDOW* game = cria_tela(); enable_keypad(game); cria_borda(game); tela_inicio(game); mostra_tela(game); int i; i = pega_input(game); formata_tela(game); cria_borda(game); tela_jogo(game); tp_peca peca = nova_peca(); while(i!='q'){ if(fim_do_movimento(game, &peca)){ peca = nova_peca(); } escreve_peca(game, peca); mostra_tela(game); apaga_peca(game, peca); if(movimento_valido(game, &peca, i)){ mover_peca(&peca, i); } escreve_peca(game, peca); mostra_tela(game); i = pega_input(game); if(fim_do_movimento(game, &peca)&&limite_superior(&peca)){ break; } } formata_tela(game); cria_borda(game); tela_fim(game); mostra_tela(game); i = pega_input(game); finaliza_ncurses(); return 0; }