I started making this extremely simple 2048 game, without graphics and stuff (only array), and made the board :
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;
}
}
Now, I want to make the functions to check if the neighbouring places are blank, or to add if they are the same number, etc.; but I have to make them in another class. I can probably make the functions to check all of that, but can someone tell me just how I could implement all of it in different classes?
I already tried doing it, but I want the user to input the size of the game board, and I can't do that as if I make a new class I have to write like
GameBoard gb = new GameBoard[4][4];
I don't want to define the size, but if I don't then I can't define my movement functions... Any ideas?