public class game15 {
static int t[][] = { { 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9,10,11,12 },
{ 13,14,15,0 } };
static int x=3; // initial for x axis of space position (zero number);
static int y=3; // initial for y axis of space position (zero number);
public static void doUp() {
int s;
if (y-1>=0) {s=t[y-1][x]; t[y-1][x]=t[y][x];t[y][x]=s; y=y-1;}}
public static void doDown() {
int s;
if (y+1<=3) {s=t[y+1][x]; t[y+1][x]=t[y][x];t[y][x]=s; y=y+1; }}
public static void doLeft() {
int s;
if (x-1>=0) {s=t[y][x-1]; t[y][x-1]=t[y][x];t[y][x]=s; x=x-1;}}
public static void doRight() {
int s;
if (x+1<=3) {s=t[y][x+1]; t[y][x+1]=t[y][x];t[y][x]=s;x=x+1;}}
public static void doSolve() {
//<======= add code to solve the solution here;
}
public static void main(String[] args) throws NumberFormatException, IOException {
String ch=null;
boolean again=true;
while (again){
show();
System.out.println("Which direction do you want to move (u=up,d=down,l=left,r=right,s=Solve it, or x=exit) ?");
ch=getkey();
if (ch.contentEquals("u") ) { doUp(); }
if (ch.contentEquals("d") ) { doDown(); }
if (ch.contentEquals("l") ) { doLeft(); }
if (ch.contentEquals("r") ) { doRight(); }
if (ch.contentEquals("s") ) { doSolve();}
if (ch.contentEquals("x") ) {again=false; System.out.println("Good bye");}
}}