• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need big help wih a loop  RSS feed

 
gail belfast
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to write a snakes and ladders program but i am having serious trouble getting my loop to work. I am pretty much a beginner and any help would be great.
The loop is meant to roll the dice and let anyone who has thrown the dice enter the game but then it appears to throw them out and now included the second player at all.






]
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gail belfast wrote:I have to write a snakes and ladders program but i am having serious trouble getting my loop to work.

Gail,

Please UseCodeTags (←click) when posting code. I think you tried, but I've corrected them for you. You can see what I did with the 'Edit' key.
Unfortunately, you now have a second problem: Your code lines are much too long, and it makes your thread very hard to read. I'd help you out there too, but you have TONS of them.

I suggest you read the link and correct them yourself.

Thanks.

Winston

PS: Welcome to JavaRanch.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've not looked too closely at the code but the playGame method having a game play loop which tests for "not started" seems wrong to me. Shouldn't it be testing for "playing" or "running" or "not finished".
Also in the if statement where you test to see if a player has rolled 6 and hasn't started yet you set the game loop variable "started" to true, shouldn't that be setting the players started state to true.
Finally the "while player has started" statement should have an opening curly brace after it and a closing curly brace at the end of the code block as it's not clear what code you intend to run when the while statement is true.

On a different note all together, I suggest you move sections of the code into their own methods so your play game method just has the control logic and a few calls to other methods. It will make it much easier to understand what is happening.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!