Please help me asap


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Please help me asap

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Posts
    1

    Please help me asap

    guys can ypu please help me i have this code but i donr know how it works can you please put comment on lines and explsin on comment how it works. Thank you very much please help me because im just beginner in java thanks again.

    here's the code:

    import java.io.*;
    import java.util.*;


    class Puzzle
    {
    public static InputStreamReader a=new InputStreamReader(System.in);
    public static BufferedReader b=new BufferedReader(a);

    public static void main(String args[]) throws IOException
    {
    Random myRand=new Random();
    int temp=0;
    int ctrY = 1;
    int ctrX = 0;
    int i = 0;
    int n[] = new int[16];
    int m[][] = new int[6][6];
    int x=0,y=0;
    boolean win = false;
    boolean pass = false;

    i = myRand.nextInt()%16;
    i = Math.abs(i);
    n[0] = i;

    while (ctrY <= 15){
    i = myRand.nextInt()%16;
    i = Math.abs(i);

    for (ctrX=0;ctrX<ctrY;ctrX++){
    if (n[ctrX]==i){
    pass = false;
    break;
    }else
    pass = true;
    }//end for

    if (pass == true ){
    n[ctrX] = i;
    ctrY++;
    }//endif
    }//end while

    for(ctrX=0;ctrX<16;ctrX++){
    if (n[ctrX]==0){
    i = n[15];
    n[ctrX] = i;
    n[15] = 0;
    break;}
    }

    //initialize m[6][6] to -1
    for(ctrY=0; ctrY<=5; ctrY++)
    for (ctrX=0; ctrX<=5; ctrX++)
    m[ctrY][ctrX]=-1;

    i=0;

    //transfer values of n[] to m[][]
    for(y=1;y<5;y++)
    for(x=1;x<5;x++){
    m[y][x] = n[i];
    i++;
    }

    temp = 1;

    while (win!=true && temp!=0)
    {
    pass = false;
    for(y=1; y<=4; y++){
    for (x=1; x<=4; x++)
    System.out.print(m[y][x] + "\t");
    System.out.println();}

    // Dos screen should be cleared

    System.out.print("input move: ");
    temp=new Integer(b.readLine()).intValue();


    for(ctrY=0;ctrY<6;ctrY++)
    {
    if (pass == true)
    break;
    for(ctrX=0;ctrX<6;ctrX++){
    if (m[ctrY][ctrX]==0){

    if (m[ctrY][ctrX+1] == temp){
    m[ctrY][ctrX] =temp;
    m[ctrY][ctrX+1] = 0;
    break;}
    else if (m[ctrY][ctrX-1] == temp){
    m[ctrY][ctrX] = temp;
    m[ctrY][ctrX-1] = 0;
    break;}
    else if (m[ctrY+1][ctrX] == temp){
    m[ctrY][ctrX] = temp;
    m[ctrY+1][ctrX] = 0;
    pass = true;
    break;}
    else if (m[ctrY-1][ctrX] == temp){
    m[ctrY][ctrX] = temp;
    m[ctrY-1][ctrX] = 0;
    pass = true;
    break;}
    else
    System.out.println("Invalid Move..");

    }//end if
    }//end inner for
    }//end outer for

    if (m[1][1]==1 && m[1][2]==2 && m[1][3]==3
    && m[1][4]==4 && m[2][1]==5 && m[2][2]==6 && m[2][3]==7 && m[2][4]==8
    && m[3][1]==9 && m[3][2]==10 && m[3][3]==11 && m[3][4]==12
    && m[4][1]==13 && m[4][2]==14 && m[4][3]==15){
    win = true;
    System.out.println ("You win..");
    }
    }//end while
    } //end main
    }//end class



    thanks again hope you can help me guys thanks a lot

  2. #2
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Lots of uncommented code. Junk it and start over.
    I'd suggest that you contact the author and ask him.

Similar Threads

  1. Replies: 0
    Last Post: 06-18-2003, 07:55 PM
  2. Can this be done??? Need to know asap
    By Michael in forum .NET
    Replies: 1
    Last Post: 09-18-2002, 10:58 PM
  3. MORE to Prv email ----Reply back asap
    By n.r. in forum VB Classic
    Replies: 0
    Last Post: 07-30-2002, 07:20 AM
  4. Please help!!! ASAP
    By Irma in forum Database
    Replies: 1
    Last Post: 07-10-2002, 11:22 AM
  5. Urgent need response ASAP!!!!
    By bubbles in forum XML
    Replies: 0
    Last Post: 03-18-2002, 10:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center