尝试用Java制作基本的滑动益智游戏,但在尝试测试时遇到问题

时间:2020-06-12 21:03:37

标签: java

我目前正在尝试制作基本的滑动益智游戏。但是,对于解决问题我需要做些什么,我不太确定。

下面是我的代码,当尝试测试到目前为止的内容时,CreateTheGame方法不起作用? 我在测试仪中遇到以下错误,“类Slide Puzzle中的CreateTheGame方法无法应用于给定类型:必需:int [] []”

我搞砸了吗,还是一个简单的错误?谢谢!

import java.util.Arrays;
import java.util.Random;

public class SlidingPuzzle
{
public static int rows = 4;
public static int cols = 4;
private int EmptyBox;
public static int[][] TheGame;

public SlidingPuzzle(int row, int col)
{  
    rows = row;
    cols = col;
    int[][] TheGame = new int[row][col];

}

**public static void main (String[] args) {

    CreateTheGame();

}**


public static int[][] CreateTheGame(int[][] TheGame)
{
   //Created an array to use to generate random numbers
   //that'll be filled into the 2D array
   Random random = new Random();
   int[] TheNumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
   int count = 0;


   for (int x = 0; x < TheNumbers.length; x++) {
           int ranIndex = random.nextInt(TheNumbers.length);
           int Temp = TheNumbers[ranIndex];
           TheNumbers[ranIndex] = TheNumbers[x];
           TheNumbers[x] = Temp;   
   }

   for (int row = 0; row < TheGame.length; row++)
    for (int col = 0; col < TheGame[row].length; col++)
   { 
       TheGame[row][col] = TheNumbers[count];
       count++;   
   }
   return TheGame;
}

public void printGame () 
{ 
   for (int row = 0; row < TheGame.length; row++)
   for (int col = 0; col < TheGame[row].length; col++)
   {
       System.out.print(TheGame[row][col] + " ");
   }
    System.out.println();

}   

//public int SelectBoxToMove();      

2 个答案:

答案 0 :(得分:1)

看起来CreateTheGame()需要一个int [] []类型的参数。

但是当您在此处调用该函数时,您不会传递任何参数:

{ 
Arabidopsis: [file1, file2, file3, file4],
Bean_reference_genome: [file1, file2]
}

也许您的意思是类似**public static void main (String[] args) { CreateTheGame(); }**

答案 1 :(得分:0)

我认为最好是在构造函数中调用CreateTheGame()方法,并且需要添加一个int [] []参数TheGame来使它像这样{{1} }。 int main方法之后,您可以像下面这样创建CreateTheGame(TheGame)的实例:

SlidingPuzzle

}