tac-toe java打印优胜者

ybzsozfc  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(151)

我做了一个Tictatcoe游戏,但和大多数游戏有点不同。用户必须输入3个坐标,例如10 x。这将是他们在第1行第2列打印x。我正在努力寻找一种方法来打印一个获奖者,因为我用了一种奇怪的方式。任何帮助或修复都将不胜感激!!

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package tictactoe;
  7. import java.util.Scanner;
  8. /**
  9. *
  10. * @author Win10
  11. */
  12. public class TicTacToe {
  13. String board [][] =
  14. { {"-","-","-",},
  15. {"-","-","-",},
  16. {"-","-","-",}};
  17. final int numRows = 3;
  18. final int numCols = 3;
  19. public void pick(int row, int col, String letter){
  20. board[row][col] = letter;
  21. }
  22. public void printBoard() {
  23. for(int i = 0; i < numRows; i++){
  24. for(int j = 0; j < numCols; j++) { // one row
  25. System.out.print("|" + board[i][j]);
  26. }
  27. System.out.println("|");
  28. }
  29. }
  30. /**
  31. * @param args the command line arguments
  32. */
  33. public static void main(String[] args) {
  34. TicTacToe ttt= new TicTacToe();
  35. Scanner scnr = new Scanner(System.in);
  36. for(int i = 0; i < 9; i++) {
  37. System.out.println("Type row, column and player");
  38. int row = scnr.nextInt();
  39. int col = scnr.nextInt();
  40. String player = scnr.next();
  41. ttt.pick(row, col, player);
  42. ttt.printBoard();
  43. }
  44. }
  45. }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题