java简单的控制台游戏“船只”不能添加一个“船”到一个数组,我完全卡住了

时间:2015-11-20 12:52:38

标签: java arrays eclipse console

我做了一个叫做船只的简单游戏,我制作了一个2D阵列(10x10),我有一个问题,在阵列中添加“船”(游戏的目的是在阵列中找到一艘船),我完全是因为我正在寻求帮助,对不起错误等等,但这是我的第一篇文章,我只是打招呼。谢谢!

这是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++;
      }
}

很抱歉代码中的所有错误。

0 个答案:

没有答案