这是MAIN
public class Play
{
public static void main(String[] args)
{
Grid grid = new Grid(10);
grid.fillArr('o');
grid.printArr();
Objects ships = new Object(0);
ship.getShip('X');
}
}
对象(SHIP)CLASS
public class Objects
{
//FIELDS
private int ship;
//CONSTRUCTORS
public Objects(int ship)
{
this.ship = ship;
}
//METHODS
public int getShip()
{
return ship;
}
public void getLod(char c)
{
}
}
这是Grid Class
public class Grid
{
//FIELDS
char[][] arr;
private Objects[] ship;
private int numofShips;
//CONSTRUCTORS
public Grid(int a)
{
arr = new char [a][a];
ship = new Objects[10];
}
//METHODS
public void printArr()
{
for(int q = 0; q < arr.length; q = q + 1)
{
for(int w = 0; w < arr.length; w++)
{
System.out.print(arr[q][w] + " ");
}
System.out.print("\n");
}
}
public void fillArr(char c)
{
for(int q = 0; q < arr.length; q++)
{
for(int w = 0; w < arr.length; w++)
{
arr[q][w] = c;
}
}
}
public void reloadGrid()
{
//Draw base grid
for(int r = 0; r < arr.length; r++)
for(int c = 0; c < arr[r].length; c++)
arr[r][c] = 'o';
//Draw ship <-----THIS IS A PROBLEM...//////////////////////////////
for(int i = 0; i < numofShips; i++)
{
}
}
public void addToGrid(Objects p)
{
ship[numofShips] = p;
numofShips++;
}
}
很抱歉代码中的所有错误。