Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By wsaryada
  • 1 Post By Fubarable

Thread: Help understanding how program works!

  1. #1
    zzzarf is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Help understanding how program works!

    Hi I started work on a project and hit a snag so I got help, but am struggling to really decipher what the code is doing. Specifically the check() method. Any help would be great thanks. I pasted the two major methods. THANKS AGAIN!
    Java Code:
    /*
    Classic stacker arcade game
    */
    
    public void go()
        {
    	int tmp = 0;
    	Component temporaryLostComponent = null;
    	//move bar side to side while user doesnt press space bar
    	do 
    	    {
    		if (right == true)
    		    {
    			right();
    		    } 
    		else 
    		    {
    			left();
    		    }
    		if (delX[1] == 10-length[1]) //reverse direction when at right bound
    		    {
    			right = false;
    		    } 
    		else if (delX[1] == 0) //reverse direction when at left bound
    		    {
    			right = true;
    		    }
    		draw(); //draw board
    		try 
    		    {
    			Thread.sleep((long) time);
    		    }
    		catch (InterruptedException e) 
    		    {
                            e.printStackTrace();
    		    }
    		
    	    }
    	while(press == false);
    
    	if (level>12)
    	    {
    		time= 150-(iteration*iteration*2-iteration); //blocks move faster with each successful move
    	    } 
    	else 
    	    {
    		time = time - 2.2; //speed stops increasing after 
    	    }
    	iteration++;
    	level--;
    	press = false;
    	tmp = check();
    	length[0] = length[1];
    	length[1] = tmp;
    	if (level == -1)
    	    {
    		JOptionPane.showMessageDialog(temporaryLostComponent, "Congratulations! You beat the game!");
    	    }
    	if (length[1] <= 0)
    	    {	
    		JOptionPane.showMessageDialog(temporaryLostComponent, "Game over! You reached line "+(18-level)+"!");
    		System.exit(0);
    	    }
    	last = delX[1];
    	start = false;
    	go();
        }
    
        public int check()
        {
    	if (start == true)
    	    {
    		return length[1];
    	    } 
    	else if (last<delX[1])
    	    {
    		if (delX[1]+length[1]-1 <= last+length[0]-1)
    		    {
    			return length[1];
    		    } 
    		else 
    		    {
    			return length[1]-Math.abs((delX[1]+length[1])-(last+length[0]));
    		    }
    	    } 
    	else if (last>delX[1])
    	    {
    		return length[1]-Math.abs(delX[1]-last);
    	    } 
    	else 
    	    {
    		return length[1];
    	    }
        }
    Last edited by zzzarf; 12-07-2012 at 05:58 AM.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Help understanding how program works!

    Aren't you the one who write the method? You should tell us what you are trying to accomplish with the method. And what problems that you have currently. The last thing is please edit your post to use the [code][/code] block for your code to make it more readable.
    Last edited by wsaryada; 12-07-2012 at 05:10 AM.
    Fubarable likes this.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Help understanding how program works!

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    zzzarf is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Re: Help understanding how program works!

    Sorry. Truth is my friend wrote it and I can't understand a few aspects of it. In a bind. Understand if you don't want to help. Thanks again

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help understanding how program works!

    So this is in fact "borrowed" code. Then the usual fix is to go to the source. Ask your friend about his code, and work towards understanding and a solution.

  6. #6
    zzzarf is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Re: Help understanding how program works!

    That was my first try. He's MIA. Really just need a few sentence explanation of how it works.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help understanding how program works!

    My experience is that it is better in this situation to then write your own code and thus be able to understand it from the ground up.

    You can continue to try to find your friend of course, as his help would be great!

  8. #8
    zzzarf is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Re: Help understanding how program works!

    You're obviously right. Just in a bind. Thanks again.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help understanding how program works!

    That's what happens when you try to use non-professional borrow code. Do the right thing -- create your own code for your project. You'll understand it much better, and will learn much more!
    DarrylBurke likes this.

Similar Threads

  1. Letter counter program. having trouble understanding it.
    By silverglade in forum New To Java
    Replies: 17
    Last Post: 05-21-2011, 01:06 PM
  2. Program works but don't exactly understand it
    By Danieldcc in forum New To Java
    Replies: 4
    Last Post: 10-20-2010, 06:13 AM
  3. Help on understanding a program
    By newbie225 in forum New To Java
    Replies: 1
    Last Post: 11-10-2009, 12:53 AM
  4. I have trouble understanding this program!
    By PureAwesomeness in forum New To Java
    Replies: 1
    Last Post: 03-16-2009, 05:34 AM
  5. Replies: 2
    Last Post: 11-18-2008, 10:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •