Guest User

Untitled

a guest
Dec 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public class Tablero{
  2.  
  3. String tablero[][]=new String[3][3];
  4.  
  5. public void inicializar(){
  6. for(int x=0;x<tablero.length;x++){
  7. for(int y=0;y<tablero.length;y++){
  8. tablero[x][y]=null;
  9. }
  10. }
  11.  
  12.  
  13. }
  14.  
  15. public boolean marcarCruz(int a, int b){
  16. boolean resultado=false;
  17. if(tablero[a][b]!=null){
  18. resultado=false;
  19. }else{
  20. tablero[a][b]="X";
  21. resultado=true;
  22. }
  23. return resultado;
  24.  
  25. }
  26.  
  27. public boolean marcarCero(int a, int b){
  28. boolean resultado=false;
  29. if(tablero[a][b]!=null){
  30. resultado=false;
  31. }else{
  32. tablero[a][b]="0";
  33. resultado=true;
  34. }
  35. return resultado;
  36.  
  37. }
  38.  
  39. public boolean completo(){
  40. boolean completo=false;
  41. for(int x=0;x<tablero.length;x++){
  42. for(int y=0;y<tablero.length;y++){
  43. if(tablero[x][y]!=null){
  44. completo=true;
  45. }else{
  46. completo=false;
  47. }
  48. }
  49. }
  50. return completo;
  51. }
  52.  
  53. public String indicarSiGanoAlgunJugador(){
  54. String ganador=null;
  55. for(int x=0;x<tablero.length;x++){
  56. if(tablero[0][x].equals("X")){
  57. ganador="X";
  58. }
  59. if(tablero[1][x].equals("X")){
  60. ganador="X";
  61. }
  62. if(tablero[2][x].equals("X")){
  63. ganador="X";
  64. }
  65. if(tablero[1][x].equals("X")){
  66. ganador="0";
  67. }
  68. if(tablero[2][x].equals("X")){
  69. ganador="0";
  70. }
  71. if(tablero[0][x].equals("X")){
  72. ganador="0";
  73. }
  74. for(int y=0;y<tablero.length;y++){
  75. if(tablero[y][1].equals("X")){
  76. ganador="X";
  77. }
  78. if(tablero[y][2].equals("X")){
  79. ganador="X";
  80. }
  81. if(tablero[y][0].equals("X")){
  82. ganador="X";
  83. }
  84. if(tablero[y][1].equals("X")){
  85. ganador="0";
  86. }
  87. if(tablero[y][2].equals("X")){
  88. ganador="0";
  89. }
  90. if(tablero[y][0].equals("X")){
  91. ganador="0";
  92. }
  93. }
  94. }
  95. return ganador;
  96.  
  97. }
Add Comment
Please, Sign In to add comment