• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple game parser with Scanners  RSS feed

 
T Lindstrom
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! This is my first post here, so I hope I'm not doing something terribly wrong!

To practice object-oriented programming in Java, I'm creating a little tactical text game where a number of players, of which each starts with 100 health points, can take turns in attacking each other until there's only one left.
If I can manage it, I might add some more possible "moves", to make it a bit interesting, like maybe an option to "defend" or things like that.

Anyway, this means I'm trying to make a two-word input, consisting of an action and a target. I've tried implementing it, but due to my limited understanding of Scanners I've hit the wall.
Here is my code, it does not work as I intended.



What I want, is for the player to input a line of two words separated by spaces, and these words to be put into the two variables action and target.
Am I on the right track here, could some simple tweaking fix this? Or should I do this some other way, and if so, how?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never compare Strings (or really any Object type) using "==". You want to use the .equals() method of the class.

You may want to read this FAQ that explains why.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… and welcome to the Ranch
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!