• Post Reply Bookmark Topic Watch Topic
  • New Topic

I need help with text game  RSS feed

 
Owyn van Cleef
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Owyn van Cleef
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Rajat K Gupta
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!