selamlar,
javada küçük bir işim vardı. üniversiteli bir arkadaşa ödevi için yardımda bulunuyorum.
Aşağıdaki kod 2048 oyunuymuş, javadaki eksikleri gidermek ve oyunu çalışır hale getirmek için koddaki boşlukları doldurmak gerekiyormuş.
ücreti dahilinde yardımcı olacak birilerini arıyorum...?
------------------
import java.util.Random;
import java.util.Scanner;
class Game2048
{
private int[][] AA; //keeps the entries
private int[][] emptycells; //keeps the information of empty cells
private int score; //keeps the total score
public Game2048()
{
//initiliza your game here
AA=new int[4][4];
emptycells=new int[4][4];
score=0;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
emptycells[i][j]=0;
//at the begining there should be three entries in the array
for(int i=0;i

;i++)
newentry();
//display also your initial array
}
public boolean possiblemoves()
{
//if there are possible moves return true
//otherwise return false
return true;
}
public void newentry()
{
//insert randomly 2 or 4 in a random empty cell
int r,c,n;
Random rand=new Random();
int valid=0;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
if (emptycells[i][j]==0)
valid=1;
if(valid==1)
{
do{
r=rand.nextInt(4);
c=rand.nextInt(4);
n=(rand.nextInt(2)+1)*2;
}while(emptycells[r][c] !=0);
AA[r][c]=n;
emptycells[r][c]=1;
//display also your array
display();
}
}
public void moveUp()
{
//the codes for up command
//if there is a change in the array,
//then insert a new entry and display the array
}
public void moveDown()
{
//the codes for down command
//if there is a change in the array,
//then insert a new entry and display the array
}
public void moveLeft()
{
//the codes for left command
//if there is a change in the array,
//then insert a new entry and display the array
}
public void moveRight()
{
//the codes for right command
//if there is a change in the array,
//then insert a new entry and display the array
}
public void displayScore()
{
//displays the score
System.out.println("Score:"+score);
}
public void display()
{
//displays the array
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(emptycells[i][j] !=0)
System.out.printf("&4d |",AA[i][j]);
else
System.out.print(" |");
}
System.out.println("");
}
System.out.println("");
}
}
public class Game2048App
{
//There should be no change below!!
//Write you methods accordingly.
public static void main(String[] args)
{
int m;
Scanner scan = new Scanner(System.in);
Game2048 g = new Game2048();
System.out.println("Press 5 and enter for DOWN");
System.out.println("Press 6 and enter for RIGHT");
System.out.println("Press 4 and enter for LEFT");
System.out.println("Press 8 and enter for UP");
System.out.println("Press 99 and enter to exit");
do
{
m=scan.nextInt();
if(g.possiblemoves()==false)
{
g.displayScore();
break;
}
else
{
if(m==5)
g.moveDown();
else if(m==6)
g.moveLeft();
else if(m==4)
g.moveRight();
else if(m==8)
g.moveUp();
else
System.out.println("illegal command");
}
}while(m!=99);
}
}