尝试用java制作一个基本的滑动拼图游戏,但在尝试测试时遇到了问题

尝试用java制作一个基本的滑动拼图游戏,但在尝试测试时遇到了问题,java,Java,我目前正在尝试做一个基本的滑动益智游戏。然而,我有点卡住了,不太确定我需要做什么来解决我的问题 下面是我的代码,当尝试测试到目前为止我所拥有的东西时,CreateTheGame方法不起作用? 我在测试仪中遇到以下错误,“滑动拼图类中的CreateTheGame方法无法应用于给定类型:必需:int[]” 我是把事情搞得一团糟还是一个简单的错误?谢谢 import java.util.Arrays; import java.util.Random; public class SlidingPuzz

我目前正在尝试做一个基本的滑动益智游戏。然而,我有点卡住了,不太确定我需要做什么来解决我的问题

下面是我的代码,当尝试测试到目前为止我所拥有的东西时,CreateTheGame方法不起作用? 我在测试仪中遇到以下错误,“滑动拼图类中的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();      
导入java.util.array;
导入java.util.Random;
公共类幻灯片拼图
{
公共静态int行=4;
公共静态int cols=4;
私有int-EmptyBox;
公共静态int[][]游戏;
公共幻灯片拼图(整数行,整数列)
{  
行=行;
cols=col;
int[][]游戏=新int[行][col];
}
**公共静态void main(字符串[]args){
创建游戏();
}**
公共静态int[][]创建游戏(int[][]游戏)
{
//创建了用于生成随机数的数组
//将填充到2D数组中
随机=新随机();
int[]数字={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
整数计数=0;
对于(int x=0;x
看起来CreateTheGame()需要int[]类型的参数

但在此处调用函数时,不传递任何参数:

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

    CreateTheGame();

}**

也许你的意思是
CreateTheGame(TheGame);

我认为如果你在构造函数中调用
CreateTheGame()
方法,你需要在你的例子中添加一个int[][]参数
TheGame
,那么它就会像这样
CreateTheGame(TheGame)
。 在int main方法之后,您将创建一个
SlidingPuzzle
的实例,如下所示:

public static void main (String[] args) {

SlidingPuzzle game= new SlidingPuzzle(4,4);

}

CreateTheGame()
没有传入所需的参数。非常感谢!我还在学习Java,所以我决定做一个滑动拼图的基本版本,哈哈。现在我可以回到正轨了!祝你好运,继续前进,你做得很好!我按照你的建议做了,这对我来说更有意义,哈哈。最后,我也按照Mehdi的建议将其移动到了构造函数中。现在一切似乎都回到了正轨,谢谢!