Results 1 to 3 of 3
  1. #1
    LordHamshire is offline Member
    Join Date
    Jul 2014
    Posts
    9
    Rep Power
    0

    Default User Input for Text-Based Adventure Game: "throw [item] at [something]"

    In a text-based adventure game running on the command prompt, If I wanted the player to input a string like "throw [item] at [something]" and I wanted to record what they wrote for [item] and for [something] as two separate variables, is there an easier way to do that than doing something silly like looping through an array of characters or something?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: User Input for Text-Based Adventure Game: "throw [item] at [something]"

    Regular expressions with capture groups would work. Check out the Pattern and Matcher classes. There's a lot to learn there so
    you need to read the pattern syntax and try some examples. If you don't understand something, the forum will still be here.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    LordHamshire is offline Member
    Join Date
    Jul 2014
    Posts
    9
    Rep Power
    0

    Default Re: User Input for Text-Based Adventure Game: "throw [item] at [something]"

    Thanks, I'll check it out.

Similar Threads

  1. Replies: 4
    Last Post: 01-21-2014, 12:49 PM
  2. Replies: 1
    Last Post: 12-04-2013, 09:32 PM
  3. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  4. Replies: 1
    Last Post: 01-23-2009, 04:13 PM
  5. Can't get my "if" statement to read user input
    By daletron3030 in forum New To Java
    Replies: 7
    Last Post: 01-16-2009, 05:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •