Forums Register Login

I need help with text game

+Pie Number of slices to send: Send
Hi folks!

I recently started learning Java and as challenge i challenged myself to create a text game. I made a few different classes. A core one that starts the game, and a variablen class. And the game itself which is in the main class.

Here are the classes.

Core:


Variablen:


Main:


The problem is, when i typ in "go to door". It starts no() instead of go(). Why is this happening? I appreciate every help!

Thank you.
+Pie Number of slices to send: Send
Hi Owyn, welcome to JavaRanch!

Extra print lines are a time-honored method of debugging. Try a "System.out.println(text)" after line 9 of Main.java. That will tell you what is going wrong, if not exactly why.
+Pie Number of slices to send: Send
 

Greg Charles wrote:Hi Owyn, welcome to JavaRanch!

Extra print lines are a time-honored method of debugging. Try a "System.out.println(text)" after line 9 of Main.java. That will tell you what is going wrong, if not exactly why.



Hi! Thanks for your reply. This is what i ended up with..?



Output:

Welcome player, what is your name?
sd
...Hello sd!
You appear to be in a room, it's very dark but you manage to notice a door. What will you do?
go to door
Make your decision!
You stay where you are.
Bad!

 
+Pie Number of slices to send: Send
Hi Owyn,

In Variablen class you are using Scanner class methods but here you need to understand how Scanner class works.
Try to make difference between the Scanner class next() and nextLine() methods.

Refer: java.util.Scanner or http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html


This is the answer for your problem. Still if you are not comfortable, please reply back.

-Rajat
Good heavens! What have you done! Here, try to fix it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 529 times.
Similar Threads
Need help with output of a program
Input in a do while loop
Getting an array out of bounds error
hasNext and Files
How many Sentinel values can be in one Java program?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:37:31.