2048游戏动作辅助Java

问题描述

我开始制作这款极其简单的2048游戏,没有图形和东西(只有阵列),然后制作了棋盘:

import java.util.*;

public class GameBoard
{
String [][] GameBoard;
void justprint(String s,int n) //(ignore,just a function that makes next steps easier)
{
    for(int i = 0; i<n;i++)
    {
        System.out.print(s);
    }
    System.out.println();
}
public GameBoard(int n)
{
    GameBoard = new String [n][n];
    Random num = new Random();
    for(int i = 0; i<n;i++)
    {
        for(int j = 0; j<n;j++)
        {
            GameBoard[i][j] = "    ";
        }
    }
    System.out.print("-");
    justprint("-----",n);
    int r1 = num.nextInt(n);
    int r2 = num.nextInt(n);
    int r3 = num.nextInt(n);
    int r4 = num.nextInt(n);
    GameBoard[r1][r2] = "   2";
    GameBoard[r3][r4] = "   2";
    for(int i = 0; i<n;i++)
    {
        System.out.print("|");
        for(int j = 0; j<n;j++)
        {
            System.out.print(GameBoard[i][j] + "|");
        }
        System.out.println();
        System.out.print("-");
        justprint("-----",n);
    }
    this.GameBoard = GameBoard;
}

}

现在,我要使函数检查相邻的地方是否为空白,或者添加是否相同的数字,等等。但我得让他们上另一堂课我可能可以使这些功能检查所有这些功能,但是有人可以告诉我如何在不同的类中实现所有功能吗?

我已经尝试过了,但是我希望用户输入游戏板的大小,而我不能像制作一个新的类那样写

GameBoard gb = new GameBoard[4][4];

我不想定义大小,但是如果不定义大小,就无法定义运动函数... 有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...