Guest User

Untitled

a guest
Jan 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Checkers {
  4.  
  5. //TODO: Java ma pole adresovane jinak nez body v geometrii!
  6. //TODO: GEO- [sloupec,radek] respektive [x,y]
  7. //TODO: JAVA- [radek,sloupec] respektive [y,x]
  8.  
  9. public static int[][] pole = new int[10][10];
  10.  
  11. public static void main(String[] args) {
  12. vypis(pole);
  13. System.out.println("Who starts? enter 6 or 9");
  14. Scanner in = new Scanner(System.in);
  15. int n = in.nextInt();
  16. round(n);
  17. }
  18.  
  19.  
  20. public static void round(int n){
  21. System.out.println("Player "+n+">>");
  22. Scanner in = new Scanner(System.in);
  23. System.out.print("x= "); int x = in.nextInt();
  24. System.out.println();
  25. System.out.print("y= "); int y = in.nextInt();
  26. if (pole[y][x] != 0){
  27. round(n);
  28. } else {
  29. pole[y][x] = n;
  30. win_check(n);
  31. vypis(pole);
  32. }
  33. if (n==6){ round(9);}
  34. else { round(6); }
  35. }
  36.  
  37. public static void win_check(int n){
  38. for (int x = 0; x < pole.length; x++) {
  39. for (int y = 0; y < pole.length; y++) {
  40. if(pole[x][y] == 6 || pole[x][y] == 9){
  41.  
  42. if (x < 4) {
  43. r_check(x,y,n);
  44. if (y < 4) {
  45. down_check(x,y,n);
  46. dr_check(x,y,n);
  47. }
  48. if (y == 4 || y == 5) {
  49. down_check(x,y,n);
  50. up_check(x,y,n);
  51. }
  52. if (y > 5) {
  53. up_check(x,y,n);
  54. ur_check(x,y,n);
  55. }
  56. }
  57.  
  58. if (x == 4 || x == 5) {
  59. r_check(x,y,n);
  60. l_check(x,y,n);
  61. if (y < 4) {
  62. down_check(x,y,n);
  63. dr_check(x,y,n);
  64. dl_check(x,y,n);
  65. }
  66. if (y == 4 || y == 5) {
  67. up_check(x,y,n);
  68. down_check(x,y,n);
  69.  
  70. ul_check(x,y,n);
  71. ur_check(x,y,n);
  72.  
  73. dl_check(x,y,n);
  74. dr_check(x,y,n);
  75. }
  76. if (y > 5) {
  77. ul_check(x,y,n);
  78. up_check(x,y,n);
  79. ur_check(x,y,n);
  80. }
  81. }
  82.  
  83. if (x > 5) {
  84. l_check(x,y,n);
  85. if (y < 4) {
  86. dl_check(x,y,n);
  87. down_check(x,y,n);
  88. }
  89. if (y == 4 || y == 5) {
  90. up_check(x,y,n);
  91. down_check(x,y,n);
  92.  
  93. ul_check(x,y,n);
  94. dl_check(x,y,n);
  95. }
  96. if (y > 5) {
  97. up_check(x,y,n);
  98. ul_check(x,y,n);
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }
  105.  
  106. public static void win(int x, int y){
  107. System.out.println("Player " + pole[y][x]+ " won!");
  108. System.exit(0); // Terminates the program
  109. }
  110.  
  111. public static void r_check(int x, int y, int n){
  112. int a = x;
  113. int b = y;
  114. System.out.println("R_check");
  115. for (int i = x; i < x+5; i++) {
  116. if (pole[y][i] == 0 || pole[y][i] != n){
  117. return;
  118. }
  119. }
  120. win(a,b);
  121. }
  122.  
  123. public static void l_check(int x, int y, int n){
  124. int a = x;
  125. int b = y;
  126. System.out.println("L_check");
  127. for (int i = x; i > x-5; i--) {
  128. if (pole[y][i] == 0 || pole[y][i] != n){
  129. return;
  130. }
  131. }
  132. win(a,b);
  133. }
  134.  
  135. public static void up_check(int x, int y, int n){
  136. int a = x;
  137. int b = y;
  138. System.out.println("UP_check");
  139. for (int i = y; i > y-5; i--) {
  140. if (pole[i][x] == 0 || pole[y][i] != n){ // JAVA, projizdime jednotlive radky [radek,sloupec]
  141. return;
  142. }
  143. }
  144. win(a,b);
  145. }
  146.  
  147. public static void down_check(int x, int y, int n) {
  148. int a = x;
  149. int b = y;
  150. System.out.println("DOWN_check");
  151. for (int i = y; i < y + 5; i++) {
  152. if (pole[i][x] == 0 || pole[y][i] != n) { // JAVA, projizdime jednotlive radky [radek,sloupec]
  153. return;
  154. }
  155. }
  156. win(a,b);
  157. }
  158.  
  159. public static void dr_check(int x, int y, int n){
  160. int a = x;
  161. int b = y;
  162. System.out.println("DR_check");
  163. for (int i = x; i < x+5; i++) {
  164. if(pole[y][i]==0 || pole[y][i] != n){
  165. return;
  166. }
  167. y++;
  168. }
  169. win(a,b);
  170. }
  171.  
  172. public static void dl_check(int x, int y, int n){
  173. int a = x;
  174. int b = y;
  175. System.out.println("DL_check");
  176. for (int i = x; i < x+5; i++) { // DOWN
  177. if(pole[y][i]==0 || pole[y][i] != n){
  178. return;
  179. }
  180. y--; // LEFT
  181. }
  182. win(a,b);
  183. }
  184.  
  185. public static void ul_check(int x, int y, int n){
  186. int a = x;
  187. int b = y;
  188. System.out.println("UL_check");
  189. for (int i = x; i > x-5; i--) { // UP
  190. if (pole[y][i]==0 || pole[y][i] != n){
  191. return;
  192. }
  193. y--; // LEFT
  194. }
  195. win(a,b);
  196. }
  197.  
  198. public static void ur_check(int x, int y, int n){
  199. int a = x;
  200. int b = y;
  201. System.out.println("UR_check");
  202. for (int i = x; i > x-5; i--) { // UP
  203. if (pole[y][i]==0 || pole[y][i] != n){
  204. return;
  205. }
  206. y++; // RIGHT
  207. }
  208. win(a,b);
  209. }
  210.  
  211. public static void vypis(int[][] pole) {
  212. String a = "0123456789";
  213. for (int k = 0; k < pole.length; k++) { // smycka tiskne svrchni cislovani 0 -> 9
  214. System.out.print(k+" ");
  215. }
  216. System.out.println();
  217. for (int x = 0; x < pole.length; x++) {
  218. for (int y = 0; y < pole.length; y++) {
  219. System.out.print(pole[x][y]+ " ");
  220. }
  221. System.out.println(a.substring(x,x+1)+" ");
  222. }
  223. System.out.println();
  224. }
  225. }
Add Comment
Please, Sign In to add comment