• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scanner input not working?  RSS feed

 
Nikki Smith
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know I can use a loop to cycle through rather than having so much duplication, it's just set up that way for now while testing movement. I tried throwing in a few print statements and when I ran it the kb seemed to have E stored in the playerMove variable, so I'm not sure what the issue is. The code that just has strings typed directly in works correctly, but the code that accepts user input doesn't. Probably been staring at this too long and I'm guessing it's some silly little thing I'm just overlooking.

In Driver class


In GameManager class



In Player class which extends Participants
(This bugs me, and I'm sure there's a way to make this cleaner, but I'm just trying to get the mechanics working first).



Here's what the console displays when this is ran and I entered E and e for the kb input:

You're in an unfamiliar room.
To explore please type E to move east and W to move west.
Room 1 contains:
The room is empty

E
Room 1 contains:
The room is empty

E
Room 1 contains:
The room is empty

e
Room 1 contains:
The room is empty

Room 2 contains:
Mordac (26 health point(s) remaining)
Badger on a stick (+4 point(s) of damage)

Room 3 contains:
The room is empty

Room 4 contains:
Toaster (23 health point(s) remaining)
No weapons

Room 3 contains:
The room is empty

Room 4 contains:
Toaster (23 health point(s) remaining)
No weapons
 
Junilu Lacar
Sheriff
Posts: 11481
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use == to compare Strings.  Use String.equals():

To ignore case, you can use .equalsIgnoreCase(direction) instead.

If you use Java 7 or later, you can also use a switch-case statement:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!