Advertisement
Bubusuk

Untitled

Jan 13th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. package piskvorky;
  2.  
  3. import java.util.*;
  4.  
  5. public class Piskvorky {
  6.  
  7.     static int vPole = 3;
  8.     static int[][] hra = new int[vPole][vPole];
  9.     static boolean konec = true;
  10.     static int hrac = 1;
  11.  
  12.     public static void main(String[] args) {
  13.         int x;
  14.         int y;
  15.         Scanner sc = new Scanner(System.in);
  16.         while (konec) {
  17.             System.out.println("Hraje hrac " + hrac);
  18.             if (hrac == 1) {
  19.                 System.out.println("Zadejte osu x");
  20.                 x = sc.nextInt();
  21.                 System.out.println("Zadejte osu y");
  22.                 y = sc.nextInt();
  23.                 if (hra[x][y] != 1 || hra[x][y] != 2) {
  24.                     hra[x][y] = hrac;
  25.                     hrac = 2;
  26.                 }
  27.             } else {
  28.                 System.out.println("Zadejte osu x");
  29.                 x = sc.nextInt();
  30.                 System.out.println("Zadejte osu y");
  31.                 y = sc.nextInt();
  32.                 if (hra[x][y] != 1 || hra[x][y] != 2) {
  33.                     hra[x][y] = hrac;
  34.                     hrac = 2;
  35.                 }
  36.             }
  37.             zobrazPole();
  38.         }
  39.  
  40.     }
  41.  
  42.     public static void zobrazPole() {
  43.  
  44.         for (int g = 0; g < vPole * 2 + 1; g++) {
  45.             System.out.print("-");
  46.         }
  47.         System.out.println("");
  48.         for (int i = 0; i < vPole; i++) {
  49.             for (int j = 0; j < vPole; j++) {
  50.                 System.out.print("|");
  51.                 if (hra[i][j] == 1) {
  52.                     System.out.print("O");
  53.                 } else if (hra[i][j] == 2) {
  54.                     System.out.print("X");
  55.                 } else {
  56.                     System.out.print(" ");
  57.                 }
  58.  
  59.             }
  60.             System.out.println("|");
  61.             for (int g = 0; g < vPole * 2 + 1; g++) {
  62.                 System.out.print("-");
  63.             }
  64.             System.out.println("");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement