Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. public String entenderJugada(String jugada) {
  2.         String retorno = "ok";
  3.         if (validarJugada(jugada)) {
  4.             int posFila = 0;
  5.             char[] filaLetras = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
  6.             jugada = jugada.toUpperCase();
  7.             char primerComando = jugada.charAt(0);
  8.             char segundoComando = jugada.charAt(1);
  9.             int tercerComando = ((int) (jugada.charAt(2))) - 1 ;
  10.  
  11.             if (jugada.equals("X")) {
  12.                 jugadorRendido = jugadorDeTurno;
  13.                 if (jugadorDeTurno.equals(jugadorUno)) {
  14.                     jugadorUno.setCantPartidasGanadas(jugadorUno.getCantPartidasGanadas() + 1);
  15.                 } else {
  16.                     jugadorDos.setCantPartidasGanadas(jugadorDos.getCantPartidasGanadas() + 1);
  17.                 }
  18.             }
  19.             if (primerComando == 'J') {
  20.                 for (int i = 0; i < filaLetras.length; i++) {
  21.                     if (filaLetras[i] == segundoComando) {
  22.                         posFila = i;
  23.                     }
  24.                 }
  25.                 tablero.ponerFicha(posFila, tercerComando);
  26.             } else if (primerComando == 'P') {
  27.                 for (int i = 0; i < filaLetras.length; i++) {
  28.                     if (filaLetras[i] == segundoComando) {
  29.                         posFila = i;
  30.                     }
  31.                 }
  32.                 tablero.ponerPanel(posFila, tercerComando);
  33.             } else if (primerComando == 'M') {
  34.  
  35.                 tablero.moverPanel(segundoComando, tercerComando);
  36.             }
  37.         } else {
  38.             //la jugada no es valida
  39.             retorno = "Ingreso una jugada inválida ";
  40.         }
  41.         return retorno;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement