Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Need big help wih a loop

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.






]
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I didn't say it. I'm just telling you what this tiny ad said.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic