Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.83 KB | None | 0 0
  1. public static void main(String[] args) {
  2. // TODO Auto-generated method stub
  3.  
  4. char[][] planell = new char[8][8];
  5. int opcio;
  6.  
  7. Scanner entrada= new Scanner(System.in);
  8.  
  9. boolean Final=false;
  10. boolean PeonB=false;
  11. boolean PeonN=false;
  12.  
  13. int torn = 0;
  14. int blanc = 0;
  15. int negre = 0;
  16.  
  17.  
  18.  
  19.  
  20. do {
  21. System.out.println("\nEscacs");
  22. System.out.println("\n1. Col.locar els peons i jugar "
  23. +"\n2. Sortir "
  24. +"\n\nNOTA: Si cites una opció més gran de 2 també sortira del joc.");
  25. opcio = entrada.nextInt();
  26.  
  27. switch(opcio) {
  28.  
  29. case 1:
  30.  
  31. for (int c = 0; c < 8 ; c++){
  32. for (int j = 0; j < 8 ; j++){
  33. planell[c][j] = '·';
  34. }
  35. }
  36.  
  37. for (int c = 0; c < 8 ; c++){
  38. planell[1][c] = 'P';
  39. planell[6][c] = 'p';
  40. }
  41.  
  42.  
  43. char lletra = 'a';
  44. for (int col = 0; col < 8; col++){
  45. System.out.print(" "+" ");
  46. System.out.print(" "+(lletra)+"");
  47. lletra++;
  48. }
  49. for (int fila = 0; fila < 8; fila++){
  50. System.out.println();
  51. System.out.print(fila+0);
  52. for (int col = 0; col < 8; col++){
  53. System.out.print(" "+" "+planell[fila][col]+" ");
  54. }
  55. }
  56. System.out.println();
  57.  
  58. blanc=1;
  59. while(Final==false)
  60. {
  61. if (blanc==1)
  62. { boolean movFet=false;
  63. System.out.println("\nBlanc (minuscules)!");
  64. System.out.println("Poscio horizontal del tu peo (lletres)");
  65. char poss=entrada.next().charAt(0);
  66. System.out.println("Poscio vertical de tu peo (numero)");
  67. int ver=entrada.nextInt();
  68. System.out.println("Poscio horizontal del desti (lletres)");
  69. char hordes=entrada.next().charAt(0);
  70. System.out.println("Poscio vertical del desti (numero)");
  71. int verdes=entrada.nextInt();
  72.  
  73. int numposs=0;
  74. switch(poss) {
  75. case 'A': numposs=0;break;
  76. case 'B': numposs=1;break;
  77. case 'C': numposs=2;break;
  78. case 'D': numposs=3;break;
  79. case 'E': numposs=4;break;
  80. case 'F': numposs=5;break;
  81. case 'G': numposs=6;break;
  82. case 'H': numposs=7;break;
  83. }
  84.  
  85. int num=0;
  86. switch (hordes) {
  87. case 'A': num=0;break;
  88. case 'B': num=1;break;
  89. case 'C': num=2;break;
  90. case 'D': num=3;break;
  91. case 'E': num=4;break;
  92. case 'F': num=5;break;
  93. case 'G': num=6;break;
  94. case 'H': num=7;break;
  95. }
  96.  
  97. if (planell[ver][numposs]!=' ') {
  98. if (planell[verdes][num]==' ') {
  99. if (num==numposs) {
  100. if (verdes==ver-1) {
  101. planell[verdes][num]=planell[ver][numposs];
  102. planell[ver][numposs]=' ';
  103. movFet=true;
  104. }
  105. else {
  106. if (verdes==ver-2){
  107. planell[verdes][num]=planell[ver][numposs];
  108. planell[ver][numposs]=' ';
  109. movFet=true;
  110. }
  111. }
  112. }
  113. else {
  114. System.out.println("No puedes hacer eso");
  115. }
  116. }
  117. else {
  118. if (planell[verdes][num]=='p') {
  119. if (Math.abs(num-numposs)==1) {
  120. if (Math.abs(verdes-ver)==1) {
  121. planell[verdes][num]=planell[ver][numposs];
  122. planell[ver][numposs]=' ';
  123. movFet=true;
  124. }
  125. }
  126. }
  127. }
  128. }
  129. else {
  130. System.out.println("No puedes hacer eso");
  131. }
  132.  
  133. for (int x=0;x<8;x++) {
  134. char letra=' ';
  135. switch (x) {
  136. case 0: letra='A';break;
  137. case 1: letra='B';break;
  138. case 2: letra='C';break;
  139. case 3: letra='D';break;
  140. case 4: letra='E';break;
  141. case 5: letra='F';break;
  142. case 6: letra='G';break;
  143. case 7: letra='H';break;
  144. }
  145. System.out.print((" "+" "+letra));
  146.  
  147.  
  148. }
  149. System.out.println(" ");
  150. for (int i= 0; i < 8; i++) {
  151. System.out.print((i+0));
  152. for (int j= 0; j < 8; j++) {
  153.  
  154.  
  155. System.out.print(" "+ planell[i][j]+" ");
  156. }
  157. for (int h=8; h<9;h++) {
  158. System.out.print((i+0));
  159. }
  160. System.out.println();
  161.  
  162. }
  163. for (int g=0;g<8;g++)
  164. {
  165. char letra=' ';
  166. switch (g) {
  167. case 0: letra='A';break;
  168. case 1: letra='B';break;
  169. case 2: letra='C';break;
  170. case 3: letra='D';break;
  171. case 4: letra='E';break;
  172. case 5: letra='F';break;
  173. case 6: letra='G';break;
  174. case 7: letra='H';break;
  175. }
  176. System.out.print((" "+" "+letra));
  177. }
  178. if(movFet==true) {blanc=0;}
  179.  
  180. }
  181. else
  182. {
  183. boolean movFet=false;
  184. System.out.println("\nNegres (majuscules)!");
  185. System.out.println("Poscio horizontal del tu peo (lletres)");
  186. char poss=entrada.next().charAt(0);
  187. System.out.println("Poscio vertical de tu peo (numero)");
  188. int ver=entrada.nextInt();
  189. System.out.println("Poscio horizontal del desti (lletres)");
  190. char hordes=entrada.next().charAt(0);
  191. System.out.println("Poscio vertical del desti (numero)");
  192. int verdes=entrada.nextInt();
  193.  
  194. int numposs=0;
  195. switch(poss) {
  196. case 'A': numposs=0;break;
  197. case 'B': numposs=1;break;
  198. case 'C': numposs=2;break;
  199. case 'D': numposs=3;break;
  200. case 'E': numposs=4;break;
  201. case 'F': numposs=5;break;
  202. case 'G': numposs=6;break;
  203. case 'H': numposs=7;break;
  204. }
  205.  
  206. int num=0;
  207. switch (hordes) {
  208. case 'A': num=0;break;
  209. case 'B': num=1;break;
  210. case 'C': num=2;break;
  211. case 'D': num=3;break;
  212. case 'E': num=4;break;
  213. case 'F': num=5;break;
  214. case 'G': num=6;break;
  215. case 'H': num=7;break;
  216. }
  217.  
  218. if (planell[ver][numposs]!=' ') {
  219. if (planell[verdes][num]==' ') {
  220. if (num==numposs) {
  221. if (verdes==ver+1) {
  222. planell[verdes][num]=planell[ver][numposs];
  223. planell[ver][numposs]=' ';
  224. movFet=true;
  225. }
  226. else {
  227. if (verdes==ver+2){
  228. planell[verdes][num]=planell[ver][numposs];
  229. planell[ver][numposs]=' ';
  230. movFet=true;
  231. }
  232. }
  233. }
  234. else {
  235. System.out.println("No puedes hacer eso");
  236. }
  237.  
  238. }
  239. else {
  240. if (planell[verdes][num]=='P') {
  241. if (Math.abs(num-numposs)==1) {
  242. if (Math.abs(verdes-ver)==1) {
  243. planell[verdes][num]=planell[ver][numposs];
  244. planell[ver][numposs]=' ';
  245. movFet=true;
  246. }
  247. }
  248. }
  249. }
  250. }
  251. else {
  252. System.out.println("No puedes hacer eso");
  253. }
  254.  
  255. for (int x=0;x<8;x++) {
  256. char letra=' ';
  257. switch (x) {
  258. case 0: letra='A';break;
  259. case 1: letra='B';break;
  260. case 2: letra='C';break;
  261. case 3: letra='D';break;
  262. case 4: letra='E';break;
  263. case 5: letra='F';break;
  264. case 6: letra='G';break;
  265. case 7: letra='H';break;
  266. }
  267. System.out.print((" "+" "+letra));
  268.  
  269.  
  270. }
  271. System.out.println(" ");
  272. for (int i= 0; i < 8; i++) {
  273. System.out.print((i+0));
  274. for (int j= 0; j < 8; j++) {
  275.  
  276.  
  277. System.out.print(" "+ planell[i][j]+" ");
  278. }
  279. for (int h=8; h<9;h++) {
  280. System.out.print((i+0));
  281. }
  282. System.out.println();
  283.  
  284. }
  285. for (int g=0;g<8;g++)
  286. {
  287. char letra=' ';
  288. switch (g) {
  289. case 0: letra='A';break;
  290. case 1: letra='B';break;
  291. case 2: letra='C';break;
  292. case 3: letra='D';break;
  293. case 4: letra='E';break;
  294. case 5: letra='F';break;
  295. case 6: letra='G';break;
  296. case 7: letra='H';break;
  297. }
  298. System.out.print((" "+" "+letra));
  299. }
  300. if(movFet==true) {blanc=1;}
  301.  
  302. }
  303. }
  304. PeonB=false;
  305. PeonN=false;
  306. for (int i=0;i<8;i++) {
  307. for (int j=0 ;j<8 ;j++) {
  308. if (planell[i][j]=='P') {
  309. PeonB=true;
  310. }
  311. if (planell[i][j]=='p') {
  312. PeonN=true;
  313. }
  314. }
  315. if (PeonB==true) {
  316. if (PeonN==true) {
  317. Final=false;
  318. }
  319. else {
  320. System.out.println("Ha guanyat el Blanc");
  321. Final=true;
  322. }
  323. }
  324. else {
  325. System.out.println("Ha guanyat el negre");
  326. Final=true;
  327. }
  328. }
  329.  
  330. break;
  331. }
  332. }while(opcio <= 1);
  333. System.out.println("Sortida");
  334. entrada.close();
  335. }
  336.  
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement