Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Checkers {
- //TODO: Java ma pole adresovane jinak nez body v geometrii!
- //TODO: GEO- [sloupec,radek] respektive [x,y]
- //TODO: JAVA- [radek,sloupec] respektive [y,x]
- public static int[][] pole = new int[10][10];
- public static void main(String[] args) {
- vypis(pole);
- System.out.println("Who starts? enter 6 or 9");
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- round(n);
- }
- public static void round(int n){
- System.out.println("Player "+n+">>");
- Scanner in = new Scanner(System.in);
- System.out.print("x= "); int x = in.nextInt();
- System.out.println();
- System.out.print("y= "); int y = in.nextInt();
- if (pole[y][x] != 0){
- round(n);
- } else {
- pole[y][x] = n;
- win_check(n);
- vypis(pole);
- }
- if (n==6){ round(9);}
- else { round(6); }
- }
- public static void win_check(int n){
- for (int x = 0; x < pole.length; x++) {
- for (int y = 0; y < pole.length; y++) {
- if(pole[x][y] == 6 || pole[x][y] == 9){
- if (x < 4) {
- r_check(x,y,n);
- if (y < 4) {
- down_check(x,y,n);
- dr_check(x,y,n);
- }
- if (y == 4 || y == 5) {
- down_check(x,y,n);
- up_check(x,y,n);
- }
- if (y > 5) {
- up_check(x,y,n);
- ur_check(x,y,n);
- }
- }
- if (x == 4 || x == 5) {
- r_check(x,y,n);
- l_check(x,y,n);
- if (y < 4) {
- down_check(x,y,n);
- dr_check(x,y,n);
- dl_check(x,y,n);
- }
- if (y == 4 || y == 5) {
- up_check(x,y,n);
- down_check(x,y,n);
- ul_check(x,y,n);
- ur_check(x,y,n);
- dl_check(x,y,n);
- dr_check(x,y,n);
- }
- if (y > 5) {
- ul_check(x,y,n);
- up_check(x,y,n);
- ur_check(x,y,n);
- }
- }
- if (x > 5) {
- l_check(x,y,n);
- if (y < 4) {
- dl_check(x,y,n);
- down_check(x,y,n);
- }
- if (y == 4 || y == 5) {
- up_check(x,y,n);
- down_check(x,y,n);
- ul_check(x,y,n);
- dl_check(x,y,n);
- }
- if (y > 5) {
- up_check(x,y,n);
- ul_check(x,y,n);
- }
- }
- }
- }
- }
- }
- public static void win(int x, int y){
- System.out.println("Player " + pole[y][x]+ " won!");
- System.exit(0); // Terminates the program
- }
- public static void r_check(int x, int y, int n){
- int a = x;
- int b = y;
- System.out.println("R_check");
- for (int i = x; i < x+5; i++) {
- if (pole[y][i] == 0 || pole[y][i] != n){
- return;
- }
- }
- win(a,b);
- }
- public static void l_check(int x, int y, int n){
- int a = x;
- int b = y;
- System.out.println("L_check");
- for (int i = x; i > x-5; i--) {
- if (pole[y][i] == 0 || pole[y][i] != n){
- return;
- }
- }
- win(a,b);
- }
- public static void up_check(int x, int y, int n){
- int a = x;
- int b = y;
- System.out.println("UP_check");
- for (int i = y; i > y-5; i--) {
- if (pole[i][x] == 0 || pole[y][i] != n){ // JAVA, projizdime jednotlive radky [radek,sloupec]
- return;
- }
- }
- win(a,b);
- }
- public static void down_check(int x, int y, int n) {
- int a = x;
- int b = y;
- System.out.println("DOWN_check");
- for (int i = y; i < y + 5; i++) {
- if (pole[i][x] == 0 || pole[y][i] != n) { // JAVA, projizdime jednotlive radky [radek,sloupec]
- return;
- }
- }
- win(a,b);
- }
- public static void dr_check(int x, int y, int n){
- int a = x;
- int b = y;
- System.out.println("DR_check");
- for (int i = x; i < x+5; i++) {
- if(pole[y][i]==0 || pole[y][i] != n){
- return;
- }
- y++;
- }
- win(a,b);
- }
- public static void dl_check(int x, int y, int n){
- int a = x;
- int b = y;
- System.out.println("DL_check");
- for (int i = x; i < x+5; i++) { // DOWN
- if(pole[y][i]==0 || pole[y][i] != n){
- return;
- }
- y--; // LEFT
- }
- win(a,b);
- }
- public static void ul_check(int x, int y, int n){
- int a = x;
- int b = y;
- System.out.println("UL_check");
- for (int i = x; i > x-5; i--) { // UP
- if (pole[y][i]==0 || pole[y][i] != n){
- return;
- }
- y--; // LEFT
- }
- win(a,b);
- }
- public static void ur_check(int x, int y, int n){
- int a = x;
- int b = y;
- System.out.println("UR_check");
- for (int i = x; i > x-5; i--) { // UP
- if (pole[y][i]==0 || pole[y][i] != n){
- return;
- }
- y++; // RIGHT
- }
- win(a,b);
- }
- public static void vypis(int[][] pole) {
- String a = "0123456789";
- for (int k = 0; k < pole.length; k++) { // smycka tiskne svrchni cislovani 0 -> 9
- System.out.print(k+" ");
- }
- System.out.println();
- for (int x = 0; x < pole.length; x++) {
- for (int y = 0; y < pole.length; y++) {
- System.out.print(pole[x][y]+ " ");
- }
- System.out.println(a.substring(x,x+1)+" ");
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment