• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pong issues  RSS feed

 
Rory McFarland
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, my name is Rory and I am trying to get the grasp of Java, I am working on a pong program, that allows 2 players. And my first roadblock has been to get the both paddles to work concurrently together.  I can take out either if statements for either player 1 or player 2s paddle, and I can get them to work, but when I have both of them plugged in only the first paddle statement works. So the ball just flies through paddle1, I hope I described my issue well enough, and many thanks for the help!

 
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only the first paddle statement works

What is a "paddle statement"?  Which statements in the posted code are paddle statements?
I see 4 if statements.  Are some of those paddle statements?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are miissing a closing brace in your post. Don't use 'i' in front of a variable name to indicate integer. You have two paddles, which one is iPaddleX?
 
Rory McFarland
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You are miissing a closing brace in your post. Don't use 'i' in front of a variable name to indicate integer. You have two paddles, which one is iPaddleX?



iPaddleX is the 2nd players paddle, it would be on  the right side of the screen, and is the first if statement for the logic of when the ball hits the paddle. Maybe it would be easier to post my entire code.

Norm Radder wrote:
only the first paddle statement works

What is a "paddle statement"?  Which statements in the posted code are paddle statements?
I see 4 if statements.  Are some of those paddle statements?


Sorry, yes the 4 if statements I have posted are for when the ball hits either iPaddle(paddle to the right) or iPad(paddle to the left)
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you'd clean up your indentation it might be easier to follow.

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also better variable names would make the code easier to read:
rightPaddle and leftPaddle would read easier than
iPaddle(paddle to the right) or iPad(paddle to the left)
 
Rory McFarland
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hows this?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See how your braces on lines 113 & 114 line up? This an indication that your indentation is wrong and also a hint that your logic is wrong.
 
Rory McFarland
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:See how your braces on lines 113 & 114 line up? This an indication that your indentation is wrong and also a hint that your logic is wrong.


I see, I had no idea those had any relations to what is wrong with my program.
 
Rory McFarland
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it!! Still a little sloppy but it works!
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to be headed in the right direction.

Good programmers can't stress enough how important good formatting and style is. Doubly so if you're asking others for help.

Won't you need a leftScore and a rightScore?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!