Results 1 to 10 of 10
- 09-29-2010, 02:07 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 5
- Rep Power
- 0
- 09-29-2010, 02:13 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Well, first you put the code in CODE tags so it's formatted and readable, then you point out to us where the recursion is.
- 09-29-2010, 02:40 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 5
- Rep Power
- 0
he said the method is recursive
- 09-29-2010, 02:43 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
What method?
And you appear to have removed the code making it even harder to see...
- 09-29-2010, 02:44 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 5
- Rep Power
- 0
wrong codes
Last edited by XS-IV; 09-29-2010 at 02:56 PM. Reason: wrong codes
- 09-29-2010, 02:46 PM #6
Member
- Join Date
- Sep 2010
- Posts
- 5
- Rep Power
- 0
i'm new to java and programming in general, so i'm not sure what he meant by "enemyShip method is recursive"
- 09-29-2010, 02:47 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Java Code:public class EnemyShip { int gameWidth; int position; int velocity; boolean destroyed; char icon; EnemyShip() { position = 0; velocity = 0; gameWidth = 0; destroyed = false; icon = 'e'; } EnemyShip(int pPosition, int pVelocity, int pGameWidth, char pIcon) { position = pPosition; velocity = pVelocity; gameWidth = pGameWidth; icon = pIcon; destroyed = false; } public void moveShip() { //Don't move ship if game width is 0 if (gameWidth < 0) { return; } //Don't move ship if it is dead if (destroyed) { return; } int tempVelocity = velocity; while ((tempVelocity != 0)) { //Check if boundary is reached if ((position + tempVelocity) < -gameWidth ) { tempVelocity += (position - gameWidth); position = -gameWidth; tempVelocity = -tempVelocity; velocity = -velocity; } else if ((position + tempVelocity) > gameWidth ) { tempVelocity += (position - gameWidth); position = gameWidth; tempVelocity = -tempVelocity; velocity = -velocity; } else { position += tempVelocity; tempVelocity = 0; } } } public char getIcon() { return icon; } public void setIcon(char icon) { this.icon = icon; } public boolean getDestroyed() { return destroyed; } public void setDestroyed(boolean pDestroyed) { destroyed = pDestroyed; } public int getPosition() { return position; } public int getVelocity() { return velocity; } public boolean inRangeOfFire(int pPosition) { //Check if enemy is within fire position if (!destroyed) { if (position == pPosition) { destroyed = true; icon = 'X'; return true; } } return false; } public int getAbsolutePosition() { return position + gameWidth; } }
Now, which method is recursive?
- 09-29-2010, 02:49 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
There isn't an enemyShip() method.
There's a couple of constructors, but they're not recursive.
A recursive method is one which calls itself...
- 09-29-2010, 02:50 PM #9
Member
- Join Date
- Sep 2010
- Posts
- 5
- Rep Power
- 0
he didnt say a particular 1. he just said that my "enemy Ship is recursive"
- 09-29-2010, 04:47 PM #10
Similar Threads
-
two short codes
By Libertyman in forum New To JavaReplies: 7Last Post: 06-21-2010, 04:22 PM -
java codes
By Balajee in forum AWT / SwingReplies: 1Last Post: 09-30-2008, 06:04 PM -
Assistant on my codes. SOS!!
By sya1912 in forum Java AppletsReplies: 16Last Post: 09-01-2008, 03:23 PM -
Make Java codes more simplier (Multidimensional Arrays)
By javanewbie in forum JCreatorReplies: 9Last Post: 06-25-2008, 05:48 AM -
Posting codes and help
By Java_Man in forum New To JavaReplies: 2Last Post: 02-16-2008, 04:15 AM
Bookmarks