Java Gameboard和Glider家庭作业(需要帮助缩短)

时间:2016-04-05 17:24:25

标签: java

我的作业是

  • 创建二维char数组以表示游戏板
  • 从棋盘位置[2] [2]开始,将滑翔机写入游戏板
  • 显示游戏板

我想出了以下内容,我该如何压缩它?

public class HW8 {

 public static void main(String[] args)
   {

     char [][] gameBoard = new char[20][20];   



          int x = 0;
          int y = 0;
          char[][] a = new char[x][y];


          char[][] gliderArrays = glider(a);
          for (int r = 0; r < a.length; r++)
          {
             for (int c = 0; c < a[0].length; c++)
             {
                gliderArrays[r][c] = a[r][c];

             }
          }

          for (int i = 0; i < gliderArrays.length; i++)
          {
             for (int j = 0; j < gliderArrays[0].length; j++)
             {
                gameBoard[i][j] = gliderArrays[i][j];
                gameBoard[2][2] = gliderArrays[i][j];
             }
          }

          for (int i = 0; i < gameBoard.length; i++) {
             for (int j = 0; j < gameBoard[0].length; j++) {
             System.out.print(gameBoard[i][j]);
            }
            System.out.println();

          }
       }

       //Create the glider 2D array
       public static char[][] glider(char[][] a) {
          char[][] gliderArray = {{' ','*',' '},
                                     {' ','*','*'},
                                     {'*',' ','*'}};

          for (int i = 0; i < a.length; i++) {
             for (int j = 0; j < a[0].length; j++) {
             gliderArray[i][j] = a[i][j];
          }
        }

        return gliderArray;
       }


    }

0 个答案:

没有答案