Advertisement
LEANDRONIEVA

ajedreztp2

Sep 13th, 2023
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. public class Ajedrez {
  2.  
  3.     public static void main(String[] args) {
  4.         // TODO Auto-generated method stub
  5.         int X, Y;
  6.        
  7.         char[][] tablero = generarTablero(10,10);
  8.         System.out.println("Simularemos movimientos de un caballo de ajerdrez");
  9.         System.out.println("A continuación debe ingresar las coordenadas iniciales");
  10.  
  11.         X = Helper.getPositiveInt("Ingrese fila: ");
  12.         while(X<0|X>9){
  13.             System.out.println("Debe estar entre 0 y 9");
  14.             X = Helper.getPositiveInt("Ingrese fila: ");
  15.         }
  16.         Y = Helper.getPositiveInt("Ingrese columna: ");
  17.         while(Y<0|Y>9){
  18.             System.out.println("Debe estar entre 0 y 9");
  19.             Y = Helper.getPositiveInt("Ingrese columna: ");
  20.         }
  21.  
  22.         CaballoAjedrez horse = new CaballoAjedrez(X,Y);
  23.         for (int i = 0; i<5; i++ ) {
  24.             horse.mostrarTablero(tablero);
  25.             horse.mover(tablero);
  26.         }
  27.     }
  28.  
  29.     private static char[][] generarTablero(int filas, int columnas) {
  30.         char[][] tablero = new char[filas][columnas];
  31.         for (int i = 0; i < filas; i++) {
  32.             for (int j = 0; j < columnas; j++) {
  33.                 tablero[i][j] = '-'; // Inicializar todo el tablero con espacios en blanco
  34.             }
  35.         }
  36.         return tablero;
  37.     }
  38.    
  39.    
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement