我做了一个Tictatcoe游戏,但和大多数游戏有点不同。用户必须输入3个坐标,例如10 x。这将是他们在第1行第2列打印x。我正在努力寻找一种方法来打印一个获奖者,因为我用了一种奇怪的方式。任何帮助或修复都将不胜感激!!
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tictactoe;
import java.util.Scanner;
/**
*
* @author Win10
*/
public class TicTacToe {
String board [][] =
{ {"-","-","-",},
{"-","-","-",},
{"-","-","-",}};
final int numRows = 3;
final int numCols = 3;
public void pick(int row, int col, String letter){
board[row][col] = letter;
}
public void printBoard() {
for(int i = 0; i < numRows; i++){
for(int j = 0; j < numCols; j++) { // one row
System.out.print("|" + board[i][j]);
}
System.out.println("|");
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
TicTacToe ttt= new TicTacToe();
Scanner scnr = new Scanner(System.in);
for(int i = 0; i < 9; i++) {
System.out.println("Type row, column and player");
int row = scnr.nextInt();
int col = scnr.nextInt();
String player = scnr.next();
ttt.pick(row, col, player);
ttt.printBoard();
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!