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.
gail belfast wrote:I have to write a snakes and ladders program but i am having serious trouble getting my loop to work.
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.
PS: Welcome to JavaRanch.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
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.
I didn't say it. I'm just telling you what this tiny ad said.
Free, earth friendly heat - from the CodeRanch trailboss