Results 1 to 7 of 7
  1. #1
    Gray_Blue is offline Member
    Join Date
    Feb 2015
    Posts
    3
    Rep Power
    0

    Default How to do movement in a text based game?

    Hello everyone, sorry if this is a dumb question or if this isn't the place for it... I'm relatively new to Java, but I have a few months behind me.
    So my issue is this- I'm trying to create a text based game, like those old ones where you type "north" or "east" to move as such, and "look" to inspect the area. My only problem thus far has been trying to figure out just how I should... "structure?" the movement. As in, what's the best overall way to approach this? I've tried making a new method for every area and just passing a variable called "location," but along with passing the inventory and stat arrays, it's just become messy. Or is this a good way to do it? I have a separate method for when the player enters something, but then how will it know which description to give when the player types "look?"

    Again, apologies if this is a stupid question that is both in the wrong place and infuriates everyone who sees it, just tryin' to learn!

    Also I can paste my code if that would help... let me know.
    Thanks!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: How to do movement in a text based game?

    When you say "old" text based games, how old are you talking about? Are you talking about cursor addressing?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Gray_Blue is offline Member
    Join Date
    Feb 2015
    Posts
    3
    Rep Power
    0

    Default Re: How to do movement in a text based game?

    I mean everything is text- you will not click on anything throughout the game, only type commands.
    Last edited by Gray_Blue; 02-13-2015 at 12:51 AM.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: How to do movement in a text based game?

    Ok, I am going to presume you are talking about cursor addressing. This is a capability of some old CRT's and current CRT emulators that allow one to move a cursor or other character around the screen of a CRT. They usually consist of escape sequences which contain a row/column address. Other folks on this forum may offer better help but I would suggest you search on "cursor addressing" and see if can get more detailed information. An example of how this looks on a regular CRT screen is in the vi or vim text editors.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: How to do movement in a text based game?

    Again a poor lost adventurer who is looking for "the best" - of course you can then not do it. Why don't you settle for a way that simply works but is not necessarily the best? I'm sure if you don't lay such hefty demands on yourself, you can come up with something yourself too.

    And that is really important, that you can come up with something yourself - good or bad. Because that is the whole point of this exercise isn't it? And it gives something to talk about.


    PS: you might think this is an easy type of game to make since its all text, I made that mistake myself too. But its really hefty to do because you need a rich datastructure layer below it linking all the rooms together, being able to store a text dialogue which adapts to your progression and to be able to store the state of the world. In the end I was spending more time developing the tooling to be able to build that world and setting up its data than I was working on the actual game.
    Last edited by gimbal2; 02-13-2015 at 09:49 AM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Gray_Blue is offline Member
    Join Date
    Feb 2015
    Posts
    3
    Rep Power
    0

    Default Re: How to do movement in a text based game?

    Yeah, now I realize that it's much harder to make... i decided to keep the code but scrap the idea for now, I'll save it for when I'm more advanced. For now, I'm making a level based Tower Battle game and its much more simple- the structure was done in one day. Thanks for the help guys!

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: How to do movement in a text based game?

    Use interfaces and the instanceof operator; if a cell/location is an implementation of, say, a 'Lookable' interface then it implements the look() method that returns a String that describes why it is worth looking at that particular cell/location. You'll end up with a lot of small interfaces and a bit of natural language processing (as in: 'look north' or 'look here')

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Name entry for text based game.
    By Acar25 in forum New To Java
    Replies: 3
    Last Post: 09-20-2012, 07:19 AM
  2. Need help with my text based game
    By czarcalvinsk in forum New To Java
    Replies: 1
    Last Post: 04-07-2012, 11:57 PM
  3. creating a text based game
    By Phobos0001 in forum New To Java
    Replies: 1
    Last Post: 02-12-2008, 04:35 PM

Posting Permissions

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