void processaTeclado(int tecla) { switch (tecla) { case 'w': // cima case GLUT_KEY_UP: if(movimentar(posicaoJoystickX, posicaoJoystickY + 1.f)) posicaoJoystickY++; break; case 's'://baixo case GLUT_KEY_DOWN: if(movimentar(posicaoJoystickX, posicaoJoystickY -1)) posicaoJoystickY--; break; case 'a'://esquerda case GLUT_KEY_LEFT: if(movimentar(posicaoJoystickX -1, posicaoJoystickY)) posicaoJoystickX--; break; case GLUT_KEY_RIGHT: if(movimentar(posicaoJoystickX + 1, posicaoJoystickY)) posicaoJoystickX++; break; } exibicaoPrincipal(); }
int movimentar(int jogador,int i, int j, int x2, int y2) { if(x2 < 0 || x2 >= 8) return 0; if(y2 < 0 || y2 >= 8) return 0; if(tabuleiro[x2][y2] == 177 || tabuleiro[x2][y2] == 'B' || tabuleiro[x2][y2] == 'P') return 0; if(i < 0 || i >= 8) return 0; if(j < 0 || j >= 8) return 0; if(i == x2 && j == y2 && jogador == 1) { tabuleiro[x2][y2] = 'P'; tabuleiro[x][y] = ' '; return 1; } else if(i == x2 && j == y2 && jogador == 2) { tabuleiro[x2][y2] = 'B'; tabuleiro[x][y] = ' '; return 1; } int w; if(jogador == 1) { for(w = 0; w < 2; w++) { if(movimentar(1, i+dirP[0][w], j+dirP[1][w], x2, y2) && tabuleiro[i][j] == 'B') { countP++; tabuleiro[i][j] = ' '; } } } else { for(w = 0; w < 2; w++) { if(movimentar(2, i+dirB[0][w], j+dirB[1][w], x2, y2) && tabuleiro[i][j] == 'P') { countB++; tabuleiro[i][j] = ' '; } } } }
int main() { gerar_tabuleiro(); colocar_pecas(); int i, j; int n = 3; int jogador = 1; imprimir_mapa(); while(n--) { printf("Jogador %d:\n", jogador); scanf("%d%d%d%d", &x, &y, &x2, &y2); if(!movimentar(jogador, x, y, x2, y2)) printf("Posicao impossivel de ser acessada\n"); imprimir_mapa(); if(n%2 == 1) jogador = 1; else jogador = 2; } return 0; }
int main() { int estado = 1; unsigned int discos = 0; Pilha * A = criar(); Pilha * B = criar(); Pilha * C = criar(); while(estado != 1000){ switch(estado){ case 1 : system("cls"); estado = inicializar(A, &discos); break; case 2 : system("cls"); mostrarPinos(A,B,C); case 3 : mostrarPossibilidades(A,B,C); case 4 : estado = movimentar(A, B, C); break; case 5 : if(tamanho(C) == discos){ estado = 6; } else{ estado = 2; } break; case 6 : terminar(A, B, C); estado = 1000; break; } } printf("Jogo finalizado!!"); }