I hope i find someone to help finish the game ( 2048 )., since I'm in a computing programmer for only 2 month it's been difficult for me to do it.
The basis of this game that the user can choose what ever dimension he wants, and i kind of figured it out but now I'm struggling in a question saying:
In the beginning of the game two ‘1’ tiles are added to two random cells in the grid. Every subsequent turn a ‘1’ tile is added to an unoccupied cell in the grid, at the end of every turn you should make a list of all free cells and randomly select a free cell using that list".
I tried my best best still didn't work.
Another question was challenging says:
After the user makes a move all number tiles should attempt to move in the selected direction. A tile should continue to move in the given direction until it either hits another tile with a different number and stops or hits a tile with the same name and merges with it. Make sure that the only reason a tile stopped moving is if there are no empty cells in the direction it is supposed to move, or that all tiles that were supposed to merge do merge.
My current code:
import java.util.*;
public class The1024Game {
public static void main(String[] args) {
// TODO Auto-generated method stub
// QEUSTION 1: Asking the user to choose the desired dimensions of the grid
Scanner in = new Scanner(System.in);
System.out.print("Enter board size (IT MUST BE BETWEEN 4 AND 10): ");
int Dimension = 0;
do {
Dimension = in.nextInt();
if ( Dimension>10 | Dimension<4) {
System.out.print("THE DIMENSION MUST BE BETWEEN 4 AND 10!! PLEASE TRY AGAIN: ");
}
}while (Dimension>10 | Dimension<4);
System.out.println("The dimension has been set correctly");
// QEUSTION 2 : The frame of the game
int [][] GameFrame = new int[Dimension][Dimension];
//System.out.println(GameFrame[0][0]);
//GameFrame[0][0]=1000;
for(int i = 0; i<Dimension; i++) {
System.out.print("|");
for (int j=0; j<Dimension; j++) {
System.out.print(GameFrame[i][j]);
if(GameFrame[i][j]>=100 & GameFrame[i][j]<1000) {
System.out.print(" ");
}
if(GameFrame[i][j]>=10 & GameFrame[i][j]<100) {
System.out.print(" ");
}if(GameFrame[i][j]>=0 & GameFrame[i][j]<10 ){
System.out.print(" ");
}if(GameFrame[i][j]>=1000) {
}
System.out.print("|");
}
System.out.println();
for(int k=0; k<Dimension; k++) {
System.out.print("| ");}
System.out.print("|");
System.out.println();
System.out.print(" ");
for(int k=0; k<Dimension; k++) {
System.out.print("-----");
}
//testing another methode:
//StringBuilder rowLine = new StringBuilder();
//for (int c = 0; c<Dimension; c++) {
// rowLine.append("+-----");
//}
//rowLine.append("+");
System.out.print("\n");
}
// question 3:
int [] Free_coordinates;
for (int i=0; i<Dimension; i++) {
int [] Coordinates={0,0};
for (int j=0; j<Dimension; j++) {
if (GameFrame[i][j]==0) {
Coordinates[0]=i;
Coordinates[1]=j;
}
}
}