• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i stop my car crossing the roadsides  RSS feed

 
Muhammad Babar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every 1
My name is babar and my problem is that i want to stop my car passing the road side
i want to do it like real game where you cannot pass your through road sides
here is the code if any one could please help me........
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the recommendation in your thread in the Sun Swing forum, you need to refactor this program into its constituent classes. Otherwise as you continue to change behaviors between components of your program, the complexity of this single God-class will grow and become unmanageable. So I urge you to first refactor, then you can logically think of how a Car object should behave when held by a Track object.
 
Muhammad Babar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete stein wrote:As per the recommendation in your thread in the Sun Swing forum, you need to refactor this program into its constituent classes. Otherwise as you continue to change behaviors between components of your program, the complexity of this single God-class will grow and become unmanageable. So I urge you to first refactor, then you can logically think of how a Car object should behave when held by a Track object.

can you please help without refectoring of my class??
just tell me how can i stop my car crossing road side??if you know
thanks in advance
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muhammad Babar wrote:
can you please help without refectoring of my class??
just tell me how can i stop my car crossing road side??if you know
thanks in advance


I can only tell you what I would do, and if that helps, great, and if not, perhaps someone else will give you different advice, but I'd have a Track object hold a Car (or potentially a collection of Car) objects. Car would know its own speed and direction and would have a nextPossibleMove method that returns a Point on where the would move next based on its current position and speed if its move method is called. Track would use this information to see if the Car bumps into a wall and if so, not allow the move or change the direction of the Car and then call move() on the car.

Much luck!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!