• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Type Adventure

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







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

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yup, yup, yup. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic