Advertisement
Guest User

dsaddsdasda

a guest
Mar 5th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. //////////////CLASS PLOCHA////////////
  3.  
  4. import java.util.Random;
  5. import java.util.Scanner;
  6.  
  7.  
  8. public class Plocha
  9. {
  10. //fields
  11. private double row;
  12. private double col;
  13. char[][]TicToe;
  14.  
  15.  
  16. //constructor
  17. public Plocha(int row, int col)
  18. {
  19. this.row= row;
  20. this.col= col;
  21. TicToe = new char[5][5];
  22. }
  23.  
  24. //methods
  25. public void createPlayGrid()
  26. {
  27.  
  28. for(int i= 0; i< TicToe.length; i++)
  29. {
  30. for(int k= 0; k< TicToe[i].length; k++)
  31. {
  32. System.out.print(TicToe[i][k]);
  33.  
  34. }
  35. System.out.println("");
  36. }
  37.  
  38. }
  39. public void makePlayGrid(char I)
  40. {
  41.  
  42. for(int i= 0; i< TicToe.length; i++)
  43. {
  44. for(int k= 0; k< TicToe[i].length; k++)
  45. {
  46. TicToe[i][k]= I;
  47. }
  48. }
  49. }
  50.  
  51. public void playerX(char X)
  52. {
  53. int row;
  54. int col;
  55. Scanner sc = new Scanner(System.in);
  56. System.out.print("Zadajte Riadok: ");
  57. row=sc.nextInt();
  58. System.out.print("Zadajte Stlpec: ");
  59. col=sc.nextInt();
  60. if (row<5 && col<5)
  61. {
  62. TicToe[row][col]= X;
  63. }
  64.  
  65. }
  66. public void playerO(char O)
  67. {
  68. Random randomGenerator = new Random();
  69. int randomInt = randomGenerator.nextInt(4);
  70. int random = randomGenerator.nextInt(4);
  71.  
  72. for (double i = 1; i <= 1; ++i)
  73.  
  74. {
  75.  
  76. if (randomInt < 5 && random < 5)
  77. {
  78. TicToe[randomInt][random]= O;
  79.  
  80. }
  81.  
  82. }
  83.  
  84.  
  85. TicToe[randomInt][random]= O;
  86.  
  87. }
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. /////// CLASSS DEMO////////////////////////
  100. import java.util.Random;
  101. import java.util.Scanner;
  102.  
  103. public class Demo
  104. {
  105.  
  106. public static void main(String[] args)
  107. {
  108.  
  109. Random rand = new Random();
  110. int ran = rand.nextInt(4);
  111.  
  112.  
  113. Plocha hra = new Plocha(10,10);
  114.  
  115. hra.makePlayGrid('-');
  116. while(1<2)
  117. {
  118. hra.playerX('X');
  119. hra.createPlayGrid();
  120.  
  121.  
  122. Random randomGenerator = new Random();
  123. for (double i = 1; i <= 1; ++i)
  124.  
  125. {
  126. int randomInt = randomGenerator.nextInt(4);
  127. System.out.println(randomInt);
  128. }
  129.  
  130. System.out.println(" ");
  131.  
  132.  
  133. }
  134. }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement