Results 1 to 9 of 9
- 12-07-2012, 04:40 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
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.
- 12-07-2012, 04:56 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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.
Website: Learn Java by Examples
- 12-07-2012, 05:13 AM #3
Re: Help understanding how program works!
Forum Rules -- particularly the third paragraph.
Guide For New Members
BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-07-2012, 05:55 AM #4
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
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
-
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.
- 12-07-2012, 06:05 AM #6
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
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.
-
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!
- 12-07-2012, 06:17 AM #8
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
Re: Help understanding how program works!
You're obviously right. Just in a bind. Thanks again.
-
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!
Similar Threads
-
Letter counter program. having trouble understanding it.
By silverglade in forum New To JavaReplies: 17Last Post: 05-21-2011, 01:06 PM -
Program works but don't exactly understand it
By Danieldcc in forum New To JavaReplies: 4Last Post: 10-20-2010, 06:13 AM -
Help on understanding a program
By newbie225 in forum New To JavaReplies: 1Last Post: 11-10-2009, 12:53 AM -
I have trouble understanding this program!
By PureAwesomeness in forum New To JavaReplies: 1Last Post: 03-16-2009, 05:34 AM -
Can someone please help fix this code so the program works? (2D arrays)
By busdude in forum New To JavaReplies: 2Last Post: 11-18-2008, 10:44 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks