嘿,我正在嘗試繪製柵格。我創建了一個二維數組,我試圖用Rectangle2D填充它。我希望網格是一個角色可以在其上等角的等寬方格。這裏是我的代碼:Java以柵格形式繪製遊戲板
public class GameWindow
{
public static int[][] map = {
{0, 0, 1, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 1, 0, 0},
{0, 2, 1, 0, 0}
};
public static double[][] board;
public static Rectangle2D setBoard()
{
Rectangle2D.Double tile = new Rectangle2D.Double(10, 10, 10, 10);
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
board[i][j] = tile;
}
}
}
public static int rows = 6;
public static int columns = 5;
public static int[][] next = new int[rows][columns];
public static void main(String[] args)
{
for(int i = 0; i < map.length; i++)
{
for(int j = 0; j < map[i].length; j++)
{
System.out.print(map[i][j] + " ");
}
System.out.println();
}
}
}
有一個編譯錯誤,它不讓我在這個數組中存儲矩形。另外我懷疑它甚至會形成網格。
告訴我們什麼是編譯錯誤將是首選>:| – 2012-03-31 21:08:30