我想要做的是給用戶5個輸入(棋子),白嘴鴉,主教,國王,女王,騎士。並將它們輸出到一個網格中,我不知道如何將用戶輸入限制爲5次,並用「。」打印網格的其餘部分。如何限制二維數組用戶輸入並輸出其餘值「。」?
我的輸出結果現在在下面的網格中,但是我怎樣才能得到Qb2的用戶輸入(女王,在第2列,在第2行?)),並把它放在網格中?等等碎片 ?
Output of the result I get vs the output of the sample given
注意:列是從「A」到「H」和行從底部開始,所以從「第1行」至行「8」。
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
我的代碼:(?女王,第2欄第2行)
import java.util.Scanner;
class chessMoves
{
//MAIN CODE AT THE VERY BOTTOM OF THE CLASS
Scanner sc = new Scanner(System.in);
private String[][] grid = new String[8][8];
//target is x, so if x is at location in the grid, your program should determine if
// any of the pieces can move to that position.
private String king,queen,rook,bishop,knight,target;
public void chessPieces(){
//remember you're only using the peices in scanner for a string just for a test
//switch them to 2D Array so that i can as
System.out.println("Hello Guest00129, Welcome to Chess.");
System.out.println("In order to play this game, input pieces like below(cap;atilaized)");
System.out.println("Rook at column c and at row 5 then: Rc5");
System.out.println("Please enter a position for Rook");
rook = sc.nextLine();
System.out.println("Please enter a position for King");
king = sc.nextLine();
System.out.println("Please enter a position for Queen");
queen = sc.nextLine();
System.out.println("Please enter a position for Bishop");
bishop = sc.nextLine();
System.out.println("Please enter a position for Knight");
knight = sc.nextLine();
System.out.println("Please enter a position for Target(X) to move the peices to that position");
target = sc.nextLine();
}
public void printGrid(){
for(int row = 0; row <grid.length; row++){
for (int column = 0;column <grid[row].length; column++){
grid[row][column] = ".";
System.out.printf("%2s",grid[row][column] + " ");
}
System.out.println();
}
}
//get the userinput working first then make a file that gets the information for that userinput and outputs here
public void readChessPositions(){
}
//the file created from the method above read it print the grid here like printout here and show the possible
//positons that can attack
public void chessOutput(){
}
//method that prints the grid with the positiosn showed in the outputfile of chess moves
//print all empty spaces with dot(.) and the postiions
public static void main (String[] args){
chessMoves test1 = new chessMoves();
test1.chessPieces();
test1.printGrid();
}
}
怎麼樣:用「。」填充網格。然後將每個棋子一個接一個放入網格中(並在5之後停止)? – 2017-04-26 15:43:45
你跟蹤棋子的位置,詢問他們想要移動哪一個,然後移動它。不要問他們每個單件應該在哪裏。提示:不要使用數組。 – jiveturkey
@RC請寫一個示例代碼或者我不明白你的意思 –