Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////CLASS PLOCHA////////////
- import java.util.Random;
- import java.util.Scanner;
- public class Plocha
- {
- //fields
- private double row;
- private double col;
- char[][]TicToe;
- //constructor
- public Plocha(int row, int col)
- {
- this.row= row;
- this.col= col;
- TicToe = new char[5][5];
- }
- //methods
- public void createPlayGrid()
- {
- for(int i= 0; i< TicToe.length; i++)
- {
- for(int k= 0; k< TicToe[i].length; k++)
- {
- System.out.print(TicToe[i][k]);
- }
- System.out.println("");
- }
- }
- public void makePlayGrid(char I)
- {
- for(int i= 0; i< TicToe.length; i++)
- {
- for(int k= 0; k< TicToe[i].length; k++)
- {
- TicToe[i][k]= I;
- }
- }
- }
- public void playerX(char X)
- {
- int row;
- int col;
- Scanner sc = new Scanner(System.in);
- System.out.print("Zadajte Riadok: ");
- row=sc.nextInt();
- System.out.print("Zadajte Stlpec: ");
- col=sc.nextInt();
- if (row<5 && col<5)
- {
- TicToe[row][col]= X;
- }
- }
- public void playerO(char O)
- {
- Random randomGenerator = new Random();
- int randomInt = randomGenerator.nextInt(4);
- int random = randomGenerator.nextInt(4);
- for (double i = 1; i <= 1; ++i)
- {
- if (randomInt < 5 && random < 5)
- {
- TicToe[randomInt][random]= O;
- }
- }
- TicToe[randomInt][random]= O;
- }
- }
- /////// CLASSS DEMO////////////////////////
- import java.util.Random;
- import java.util.Scanner;
- public class Demo
- {
- public static void main(String[] args)
- {
- Random rand = new Random();
- int ran = rand.nextInt(4);
- Plocha hra = new Plocha(10,10);
- hra.makePlayGrid('-');
- while(1<2)
- {
- hra.playerX('X');
- hra.createPlayGrid();
- Random randomGenerator = new Random();
- for (double i = 1; i <= 1; ++i)
- {
- int randomInt = randomGenerator.nextInt(4);
- System.out.println(randomInt);
- }
- System.out.println(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement