Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- char[][] planell = new char[8][8];
- int opcio;
- Scanner entrada= new Scanner(System.in);
- boolean Final=false;
- boolean PeonB=false;
- boolean PeonN=false;
- int torn = 0;
- int blanc = 0;
- int negre = 0;
- do {
- System.out.println("\nEscacs");
- System.out.println("\n1. Col.locar els peons i jugar "
- +"\n2. Sortir "
- +"\n\nNOTA: Si cites una opció més gran de 2 també sortira del joc.");
- opcio = entrada.nextInt();
- switch(opcio) {
- case 1:
- for (int c = 0; c < 8 ; c++){
- for (int j = 0; j < 8 ; j++){
- planell[c][j] = '·';
- }
- }
- for (int c = 0; c < 8 ; c++){
- planell[1][c] = 'P';
- planell[6][c] = 'p';
- }
- char lletra = 'a';
- for (int col = 0; col < 8; col++){
- System.out.print(" "+" ");
- System.out.print(" "+(lletra)+"");
- lletra++;
- }
- for (int fila = 0; fila < 8; fila++){
- System.out.println();
- System.out.print(fila+0);
- for (int col = 0; col < 8; col++){
- System.out.print(" "+" "+planell[fila][col]+" ");
- }
- }
- System.out.println();
- blanc=1;
- while(Final==false)
- {
- if (blanc==1)
- { boolean movFet=false;
- System.out.println("\nBlanc (minuscules)!");
- System.out.println("Poscio horizontal del tu peo (lletres)");
- char poss=entrada.next().charAt(0);
- System.out.println("Poscio vertical de tu peo (numero)");
- int ver=entrada.nextInt();
- System.out.println("Poscio horizontal del desti (lletres)");
- char hordes=entrada.next().charAt(0);
- System.out.println("Poscio vertical del desti (numero)");
- int verdes=entrada.nextInt();
- int numposs=0;
- switch(poss) {
- case 'A': numposs=0;break;
- case 'B': numposs=1;break;
- case 'C': numposs=2;break;
- case 'D': numposs=3;break;
- case 'E': numposs=4;break;
- case 'F': numposs=5;break;
- case 'G': numposs=6;break;
- case 'H': numposs=7;break;
- }
- int num=0;
- switch (hordes) {
- case 'A': num=0;break;
- case 'B': num=1;break;
- case 'C': num=2;break;
- case 'D': num=3;break;
- case 'E': num=4;break;
- case 'F': num=5;break;
- case 'G': num=6;break;
- case 'H': num=7;break;
- }
- if (planell[ver][numposs]!=' ') {
- if (planell[verdes][num]==' ') {
- if (num==numposs) {
- if (verdes==ver-1) {
- planell[verdes][num]=planell[ver][numposs];
- planell[ver][numposs]=' ';
- movFet=true;
- }
- else {
- if (verdes==ver-2){
- planell[verdes][num]=planell[ver][numposs];
- planell[ver][numposs]=' ';
- movFet=true;
- }
- }
- }
- else {
- System.out.println("No puedes hacer eso");
- }
- }
- else {
- if (planell[verdes][num]=='p') {
- if (Math.abs(num-numposs)==1) {
- if (Math.abs(verdes-ver)==1) {
- planell[verdes][num]=planell[ver][numposs];
- planell[ver][numposs]=' ';
- movFet=true;
- }
- }
- }
- }
- }
- else {
- System.out.println("No puedes hacer eso");
- }
- for (int x=0;x<8;x++) {
- char letra=' ';
- switch (x) {
- case 0: letra='A';break;
- case 1: letra='B';break;
- case 2: letra='C';break;
- case 3: letra='D';break;
- case 4: letra='E';break;
- case 5: letra='F';break;
- case 6: letra='G';break;
- case 7: letra='H';break;
- }
- System.out.print((" "+" "+letra));
- }
- System.out.println(" ");
- for (int i= 0; i < 8; i++) {
- System.out.print((i+0));
- for (int j= 0; j < 8; j++) {
- System.out.print(" "+ planell[i][j]+" ");
- }
- for (int h=8; h<9;h++) {
- System.out.print((i+0));
- }
- System.out.println();
- }
- for (int g=0;g<8;g++)
- {
- char letra=' ';
- switch (g) {
- case 0: letra='A';break;
- case 1: letra='B';break;
- case 2: letra='C';break;
- case 3: letra='D';break;
- case 4: letra='E';break;
- case 5: letra='F';break;
- case 6: letra='G';break;
- case 7: letra='H';break;
- }
- System.out.print((" "+" "+letra));
- }
- if(movFet==true) {blanc=0;}
- }
- else
- {
- boolean movFet=false;
- System.out.println("\nNegres (majuscules)!");
- System.out.println("Poscio horizontal del tu peo (lletres)");
- char poss=entrada.next().charAt(0);
- System.out.println("Poscio vertical de tu peo (numero)");
- int ver=entrada.nextInt();
- System.out.println("Poscio horizontal del desti (lletres)");
- char hordes=entrada.next().charAt(0);
- System.out.println("Poscio vertical del desti (numero)");
- int verdes=entrada.nextInt();
- int numposs=0;
- switch(poss) {
- case 'A': numposs=0;break;
- case 'B': numposs=1;break;
- case 'C': numposs=2;break;
- case 'D': numposs=3;break;
- case 'E': numposs=4;break;
- case 'F': numposs=5;break;
- case 'G': numposs=6;break;
- case 'H': numposs=7;break;
- }
- int num=0;
- switch (hordes) {
- case 'A': num=0;break;
- case 'B': num=1;break;
- case 'C': num=2;break;
- case 'D': num=3;break;
- case 'E': num=4;break;
- case 'F': num=5;break;
- case 'G': num=6;break;
- case 'H': num=7;break;
- }
- if (planell[ver][numposs]!=' ') {
- if (planell[verdes][num]==' ') {
- if (num==numposs) {
- if (verdes==ver+1) {
- planell[verdes][num]=planell[ver][numposs];
- planell[ver][numposs]=' ';
- movFet=true;
- }
- else {
- if (verdes==ver+2){
- planell[verdes][num]=planell[ver][numposs];
- planell[ver][numposs]=' ';
- movFet=true;
- }
- }
- }
- else {
- System.out.println("No puedes hacer eso");
- }
- }
- else {
- if (planell[verdes][num]=='P') {
- if (Math.abs(num-numposs)==1) {
- if (Math.abs(verdes-ver)==1) {
- planell[verdes][num]=planell[ver][numposs];
- planell[ver][numposs]=' ';
- movFet=true;
- }
- }
- }
- }
- }
- else {
- System.out.println("No puedes hacer eso");
- }
- for (int x=0;x<8;x++) {
- char letra=' ';
- switch (x) {
- case 0: letra='A';break;
- case 1: letra='B';break;
- case 2: letra='C';break;
- case 3: letra='D';break;
- case 4: letra='E';break;
- case 5: letra='F';break;
- case 6: letra='G';break;
- case 7: letra='H';break;
- }
- System.out.print((" "+" "+letra));
- }
- System.out.println(" ");
- for (int i= 0; i < 8; i++) {
- System.out.print((i+0));
- for (int j= 0; j < 8; j++) {
- System.out.print(" "+ planell[i][j]+" ");
- }
- for (int h=8; h<9;h++) {
- System.out.print((i+0));
- }
- System.out.println();
- }
- for (int g=0;g<8;g++)
- {
- char letra=' ';
- switch (g) {
- case 0: letra='A';break;
- case 1: letra='B';break;
- case 2: letra='C';break;
- case 3: letra='D';break;
- case 4: letra='E';break;
- case 5: letra='F';break;
- case 6: letra='G';break;
- case 7: letra='H';break;
- }
- System.out.print((" "+" "+letra));
- }
- if(movFet==true) {blanc=1;}
- }
- }
- PeonB=false;
- PeonN=false;
- for (int i=0;i<8;i++) {
- for (int j=0 ;j<8 ;j++) {
- if (planell[i][j]=='P') {
- PeonB=true;
- }
- if (planell[i][j]=='p') {
- PeonN=true;
- }
- }
- if (PeonB==true) {
- if (PeonN==true) {
- Final=false;
- }
- else {
- System.out.println("Ha guanyat el Blanc");
- Final=true;
- }
- }
- else {
- System.out.println("Ha guanyat el negre");
- Final=true;
- }
- }
- break;
- }
- }while(opcio <= 1);
- System.out.println("Sortida");
- entrada.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement