• Post Reply Bookmark Topic Watch Topic
  • New Topic

Type Adventure  RSS feed

 
Cal Burger
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use a loop and if/else statements along with my Switch to create a very simple type adventure.
I want there to be a boolean to add my quit function, but am wondering if a Sentinel-controlled loop would be better. I simply need the player to be able to travel from room to room, an error message come up if they press the wrong button, allowing them to try again, and then a quit function available at all times. I know how to add a quit function to each input section but would have been trying to use a boolean and while loop to solve this, to no avail.

Here is my current code (not finished but my only trouble thus far is with the quit function)







 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Please UseCodeTags (← click) when posting code as it makes it easier for people to read your code. I've added them for you this time.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cal Burger wrote:my only trouble thus far is with the quit function)


And what specific trouble is that? You need to TellTheDetails(⇐click).

As a side note, although it's syntactically correct, and behaves just fine, it's poor style to use == and != with true and false.


 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should also not put so much code in the main method. In my opinion, a main method should contain one statement which starts the application.

You should be writing the logic down on paper, not trying to write any code until the logic is worked out, and then only writing a few lines of code before running it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!